protocol

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COM_SLEEP               = 0x00
	COM_QUIT                = 0x01
	COM_INIT_DB             = 0x02
	COM_QUERY               = 0x03
	COM_FIELD_LIST          = 0x04
	COM_CREATE_DB           = 0x05
	COM_DROP_DB             = 0x06
	COM_REFRESH             = 0x07
	COM_SHUTDOWN            = 0x08
	COM_STATISTICS          = 0x09
	COM_PROCESS_INFO        = 0x0a
	COM_CONNECT             = 0x0b
	COM_PROCESS_KILL        = 0x0c
	COM_DEBUG               = 0x0d
	COM_PING                = 0x0e
	COM_TIME                = 0x0f
	COM_DELAYED_INSERT      = 0x10
	COM_CHANGE_USER         = 0x11
	COM_BINLOG_DUMP         = 0x12
	COM_TABLE_DUMP          = 0x13
	COM_CONNECT_OUT         = 0x14
	COM_REGISTER_SLAVE      = 0x15
	COM_STMT_PREPARE        = 0x16
	COM_STMT_EXECUTE        = 0x17
	COM_STMT_SEND_LONG_DATA = 0x18
	COM_STMT_CLOSE          = 0x19
	COM_STMT_RESET          = 0x1a
	COM_SET_OPTION          = 0x1b
	COM_STMT_FETCH          = 0x1c
	COM_DAEMON              = 0x1d
	COM_BINLOG_DUMP_GTID    = 0x1e
	COM_RESET_CONNECTION    = 0x1f
)

MySQL Command Types

View Source
const (
	OK_PACKET  = 0x00
	EOF_PACKET = 0xFE
	ERR_PACKET = 0xFF
)

Packet Type Indicators

Variables

This section is empty.

Functions

func GetCommandName

func GetCommandName(cmd byte) string

GetCommandName returns the string name of a command type

func IsEOFPacket

func IsEOFPacket(payload []byte) bool

IsEOFPacket checks if a payload is an EOF packet

func IsERRPacket

func IsERRPacket(payload []byte) bool

IsERRPacket checks if a payload is an ERR packet

func IsOKPacket

func IsOKPacket(payload []byte) bool

IsOKPacket checks if a payload is an OK packet

func IsQueryCommand

func IsQueryCommand(cmd byte) bool

IsQueryCommand returns true if the command modifies data or requires special handling

func IsTransactionCommand

func IsTransactionCommand(query string) bool

IsTransactionCommand checks if a query string is a transaction command

func WriteLengthEncodedInt

func WriteLengthEncodedInt(buf []byte, n uint64) []byte

WriteLengthEncodedInt writes a length-encoded integer

func WriteLengthEncodedString

func WriteLengthEncodedString(buf []byte, s string) []byte

WriteLengthEncodedString writes a length-encoded string

func WritePacket

func WritePacket(w io.Writer, sequenceID uint8, payload []byte) error

WritePacket writes a packet to the connection

func WriteString

func WriteString(buf []byte, s string) []byte

WriteString writes a length-encoded string

func WriteUint16

func WriteUint16(buf []byte, n uint16) []byte

WriteUint16 writes a uint16

func WriteUint32

func WriteUint32(buf []byte, n uint32) []byte

WriteUint32 writes a uint32

Types

type EOFPacket

type EOFPacket struct {
	Warnings    uint16
	StatusFlags uint16
}

EOFPacket represents a MySQL EOF packet

func ParseEOFPacket

func ParseEOFPacket(payload []byte) (*EOFPacket, error)

ParseEOFPacket parses an EOF packet payload

type ERRPacket

type ERRPacket struct {
	ErrorCode    uint16
	SQLState     string
	ErrorMessage string
}

ERRPacket represents a MySQL error packet

func ParseERRPacket

func ParseERRPacket(payload []byte) (*ERRPacket, error)

ParseERRPacket parses an error packet payload

type HandshakeResponse41

type HandshakeResponse41 struct {
	CapabilityFlags uint32
	MaxPacketSize   uint32
	CharacterSet    uint8
	Username        string
	AuthResponse    []byte
	Database        string
	AuthPluginName  string
}

HandshakeResponse41 represents the client's response to handshake

func DecodeHandshakeResponse41

func DecodeHandshakeResponse41(payload []byte) (*HandshakeResponse41, error)

DecodeHandshakeResponse41 parses the client handshake response

type HandshakeV10

type HandshakeV10 struct {
	ProtocolVersion uint8
	ServerVersion   string
	ConnectionID    uint32
	AuthPluginData  []byte
	CapabilityFlags uint32
	CharacterSet    uint8
	StatusFlags     uint16
	AuthPluginName  string
}

HandshakeV10 represents the initial handshake packet from server to client

func NewHandshakeV10

func NewHandshakeV10(connectionID uint32) *HandshakeV10

NewHandshakeV10 creates a new default handshake packet

func (*HandshakeV10) Encode

func (h *HandshakeV10) Encode() []byte

Encode serializes the handshake packet

type OKPacket

type OKPacket struct {
	AffectedRows uint64
	LastInsertID uint64
	StatusFlags  uint16
	Warnings     uint16
	Info         string
}

OKPacket represents a MySQL OK packet

func ParseOKPacket

func ParseOKPacket(payload []byte) (*OKPacket, error)

ParseOKPacket parses an OK packet payload

type Packet

type Packet struct {
	Length     uint32
	SequenceID uint8
	Payload    []byte
}

Packet represents a MySQL wire protocol packet

func ReadPacket

func ReadPacket(r io.Reader) (*Packet, error)

ReadPacket reads a packet from the connection

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL