packet

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OKPacketHeader                = 0x00
	EOFPacketHeader               = 0xfe
	ErrPacketHeader               = 0xff
	AuthSwitchRequestPacketHeader = 0xfe
	AuthMoreDataPacketHeader      = 0x01
	LocalInfileRequest            = 0xfb
)
View Source
const (
	SESSION_TRACK_SYSTEM_VARIABLES = 0x00
	SESSION_TRACK_SCHEMA           = 0x01
	SESSION_TRACK_STATE_CHANGE     = 0x02
	SESSION_TRACK_GTIDS            = 0x03
)

Variables

View Source
var (
	ErrPacketData = errors.New("packet: data error")
)
View Source
var FixedLengthInteger fixedLengthInteger
View Source
var LengthEncodedInteger lengthEncodedInteger
View Source
var LengthEncodedString lengthEncodedString
View Source
var NulTerminatedString nulTerminatedString

Functions

func IsAuthMoreData

func IsAuthMoreData(data []byte) bool

func IsAuthSwitchRequest

func IsAuthSwitchRequest(data []byte) bool

func IsEOF

func IsEOF(data []byte) bool

func IsErr

func IsErr(data []byte) bool

func IsLocalInfileRequest

func IsLocalInfileRequest(data []byte) bool

func IsOK

func IsOK(data []byte) bool

func IsPing

func IsPing(data []byte) bool

func IsQuery

func IsQuery(data []byte) bool

func IsQuit

func IsQuit(data []byte) bool

func ParseAuthMoreData

func ParseAuthMoreData(data []byte) ([]byte, error)

func ParseColumnCount

func ParseColumnCount(data []byte) (uint64, error)

Types

type Attribute

type Attribute struct {
	Key string
	Val string
}

type AuthSwitchRequest

type AuthSwitchRequest struct {
	Header

	PayloadHeader uint8
	AuthPlugin    core.AuthenticationPlugin
	AuthData      []byte
}

func ParseAuthSwitchRequest

func ParseAuthSwitchRequest(data []byte) (*AuthSwitchRequest, error)

type BinaryResultSetRow

type BinaryResultSetRow struct {
	Header

	PktHeader  byte
	NullBitMap []byte
	Row        Row
}

func (*BinaryResultSetRow) NullBitMapGet

func (p *BinaryResultSetRow) NullBitMapGet(index int) bool

type Column

type Column interface {
	Packet
	GetDatabase() string
	GetTable() string
	GetName() string
	GetCharSet() *core.Collation
	GetLength() uint32
	GetType() core.TableColumnType
	GetFlags() core.ColumnDefinitionFlag
	GetDecimals() byte
	String() string
}

func ParseColumnDefinition

func ParseColumnDefinition(bs []byte) (Column, error)

type ColumnDefinition

type ColumnDefinition struct {
	Header

	Catalog      string // def
	Schema       string
	Table        string
	OrgTable     string
	Name         string
	OrgName      string
	NextLength   uint64 // 0x0c
	CharacterSet *core.Collation
	ColumnLength uint32
	ColumnType   core.TableColumnType
	Flags        core.ColumnDefinitionFlag
	Decimals     uint8
}

ColumnDefinition https://dev.mysql.com/doc/internals/en/com-query-response.html#column-definition

func (*ColumnDefinition) Dump

func (p *ColumnDefinition) Dump(capabilities core.CapabilityFlag) ([]byte, error)

func (*ColumnDefinition) GetCharSet

func (p *ColumnDefinition) GetCharSet() *core.Collation

func (*ColumnDefinition) GetDatabase

func (p *ColumnDefinition) GetDatabase() string

func (*ColumnDefinition) GetDecimals

func (p *ColumnDefinition) GetDecimals() byte

func (*ColumnDefinition) GetFlags

func (*ColumnDefinition) GetLength

func (p *ColumnDefinition) GetLength() uint32

func (*ColumnDefinition) GetName

func (p *ColumnDefinition) GetName() string

func (*ColumnDefinition) GetTable

func (p *ColumnDefinition) GetTable() string

func (*ColumnDefinition) GetType

func (p *ColumnDefinition) GetType() core.TableColumnType

func (*ColumnDefinition) String

func (p *ColumnDefinition) String() string

type ColumnValue

type ColumnValue interface {
	IsNull() bool
	Value() Value
	DumpText() ([]byte, error)
	DumpBinary() ([]byte, error)
	String() string
}

func NewColumnValue

func NewColumnValue(isNull bool, val interface{}, mysqlType core.TableColumnType) ColumnValue

type EOF

type EOF struct {
	Header

	EOFHeader    uint8
	WarningCount uint16
	StatusFlags  core.StatusFlag
}

EOF https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html

func NewEOF

func NewEOF(warningCount int, statusFlag core.StatusFlag) *EOF

func ParseEOF

func ParseEOF(bs []byte, capabilities core.CapabilityFlag) (*EOF, error)

func (*EOF) Dump

func (eof *EOF) Dump(capabilities core.CapabilityFlag) ([]byte, error)

type ERR

type ERR struct {
	Header

	ERRHeader      uint8
	ErrorCode      core.Code
	SqlStateMarker byte
	SqlState       string
	ErrorMessage   string
}

ERR https://dev.mysql.com/doc/internals/en/packet-ERR_Packet.html

func NewERR

func NewERR(code core.Code, sqlState, message string) *ERR

func ParseERR

func ParseERR(bs []byte, capabilities core.CapabilityFlag) (*ERR, error)

func (*ERR) Dump

func (e *ERR) Dump(capabilities core.CapabilityFlag) ([]byte, error)

func (*ERR) Error

func (e *ERR) Error() string

type Handshake

type Handshake struct {
	Header

	ProtocolVersion         uint8
	ServerVersion           string
	ConnectionId            uint32
	Salt1                   []byte
	CapabilityFlags         core.CapabilityFlag
	CharacterSet            *core.Collation
	StatusFlags             core.StatusFlag
	ExtendedCapabilityFlags core.CapabilityFlag
	AuthPluginDataLen       uint8
	Salt2                   []byte
	AuthPlugin              core.AuthenticationPlugin
}

Handshake https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake

func ParseHandshake

func ParseHandshake(bs []byte) (*Handshake, error)

func (*Handshake) Dump

func (p *Handshake) Dump(capabilities core.CapabilityFlag) ([]byte, error)

func (*Handshake) GetAuthData

func (p *Handshake) GetAuthData() []byte

func (*Handshake) GetCapabilities

func (p *Handshake) GetCapabilities() core.CapabilityFlag

func (*Handshake) SetCapabilities

func (p *Handshake) SetCapabilities(capabilities core.CapabilityFlag)

type HandshakeResponse

type HandshakeResponse struct {
	Header

	ClientCapabilityFlags core.CapabilityFlag
	MaxPacketSize         uint32
	CharacterSet          *core.Collation
	Username              []byte // interpreted by CharacterSet
	AuthRes               []byte
	Database              []byte // interpreted by CharacterSet
	AuthPlugin            core.AuthenticationPlugin

	AttributeLen uint64
	Attributes   []Attribute
}

HandshakeResponse https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::HandshakeResponse

func ParseHandshakeResponse

func ParseHandshakeResponse(bs []byte) (*HandshakeResponse, error)

func (*HandshakeResponse) AddAttribute

func (p *HandshakeResponse) AddAttribute(key string, val string)

func (*HandshakeResponse) Dump

func (p *HandshakeResponse) Dump(capabilities core.CapabilityFlag) ([]byte, error)

func (*HandshakeResponse) GetUsername

func (p *HandshakeResponse) GetUsername() string
type Header struct {
	Length uint32
	Seq    uint8
}

func (*Header) Dump

func (h *Header) Dump(core.CapabilityFlag) ([]byte, error)

func (*Header) Parse

func (h *Header) Parse(buf *bytes.Buffer) error

func (*Header) SetSequence

func (h *Header) SetSequence(seq int)

type OK

type OK struct {
	Header

	OKHeader            uint8
	AffectedRows        uint64
	LastInsertId        uint64
	StatusFlags         core.StatusFlag
	WarningCount        uint16
	Info                []byte
	SessionStateChanges []byte // todo
}

OK https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html

func ParseOk

func ParseOk(bs []byte, capabilities core.CapabilityFlag) (*OK, error)

func (*OK) Dump

func (p *OK) Dump(capabilities core.CapabilityFlag) ([]byte, error)

type Packet

type Packet interface {
	SetSequence(int)
	Dump(core.CapabilityFlag) ([]byte, error)
}

func NewColumnCount

func NewColumnCount(count int) (Packet, error)

type Row

type Row []ColumnValue

func ParseBinaryResultSetRow

func ParseBinaryResultSetRow(data []byte, columns []Column, loc *time.Location) (Row, error)

func ParseTextResultSetRow

func ParseTextResultSetRow(data []byte, columns []Column, loc *time.Location) (Row, error)

func (Row) String

func (r Row) String() string

type SSLRequest

type SSLRequest struct {
	Header

	ClientCapabilityFlags core.CapabilityFlag
	MaxPacketSize         uint32
	CharacterSet          *core.Collation
}

func ParseSSLRequest

func ParseSSLRequest(data []byte) (*SSLRequest, error)

func (*SSLRequest) Dump

func (p *SSLRequest) Dump(capabilities core.CapabilityFlag) ([]byte, error)

type Simple

type Simple struct {
	Header
	Payload []byte
}

func New

func New(cmd core.Command, data []byte) *Simple

func NewAuthSwitchResponse

func NewAuthSwitchResponse(authRes []byte) *Simple

func NewSimple

func NewSimple(payload []byte) *Simple

func (*Simple) Dump

func (p *Simple) Dump(capabilities core.CapabilityFlag) ([]byte, error)

type StmtExecute

type StmtExecute struct {
	Header

	ComStmtExecute     uint8
	StmtId             uint32
	Flags              uint8
	IterationCount     uint32
	NullBitMap         []byte
	NewParamsBoundFlag uint8
	ParamType          []byte
	ParamValue         []byte
}

StmtExecute https://dev.mysql.com/doc/internals/en/com-stmt-execute.html

func NewStmtExecute

func NewStmtExecute() *StmtExecute

func (*StmtExecute) CreateNullBitMap

func (p *StmtExecute) CreateNullBitMap(paramCount int)

func (*StmtExecute) Dump

func (p *StmtExecute) Dump(capabilities core.CapabilityFlag) ([]byte, error)

func (*StmtExecute) NullBitMapSet

func (p *StmtExecute) NullBitMapSet(paramCount, index int)

type StmtPrepareOKFirst

type StmtPrepareOKFirst struct {
	Header

	Status       uint8
	StmtId       uint32
	ColumnCount  uint16
	ParamCount   uint16
	WarningCount uint16
}

StmtPrepareOKFirst https://dev.mysql.com/doc/internals/en/com-stmt-prepare-response.html#packet-COM_STMT_PREPARE_OK

func ParseStmtPrepareOKFirst

func ParseStmtPrepareOKFirst(data []byte) (*StmtPrepareOKFirst, error)

type TextResultSetRow

type TextResultSetRow struct {
	Header
	Row Row
}

TextResultSetRow https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-ProtocolText::ResultsetRow

func NewTextResultSetRow

func NewTextResultSetRow(row Row) *TextResultSetRow

func (*TextResultSetRow) Dump

func (p *TextResultSetRow) Dump(capabilities core.CapabilityFlag) ([]byte, error)

type Value

type Value interface{}

Jump to

Keyboard shortcuts

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