parser

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sleep       CommandType = 0x00
	Quit                    = 0x01
	InitDB                  = 0x02
	Query                   = 0x03
	FieldList               = 0x04
	CreateDB                = 0x05
	DropDB                  = 0x06
	Refresh                 = 0x07
	Shutdown                = 0x08
	Statistics              = 0x09
	ProcessInfo             = 0x0a

	Prepare      = 0x16
	Execute      = 0x17
	SendLongData = 0x18
	Close        = 0x19
	Reset        = 0x1a
	SetOption    = 0x1b
	Fetch        = 0x1c
)

Variables

View Source
var ErrNotEnoughBuffer = errors.New("not enough buffer")
View Source
var ReuseBufferMaxSize = 1024 * 1024

ReuseBufferMaxSize represent maximum size of buffer to reuse. When size of buffer is bigger than this, buffer will be destroy and create agein to free a big bunch of memory.

Functions

func NewCOMPacket

func NewCOMPacket(b []byte, ctx *Context) (interface{}, error)

Types

type AwaitingReplyPacket

type AwaitingReplyPacket struct {
}

func NewAwaitingReplyPacket

func NewAwaitingReplyPacket(b []byte) (*AwaitingReplyPacket, error)

type COMPacket

type COMPacket struct {
	Type CommandType
	Raw  []byte
}

func (*COMPacket) CommandType

func (p *COMPacket) CommandType() CommandType

type ClientAuthResendPacket

type ClientAuthResendPacket struct {
}

func NewClientAuthResendPacket

func NewClientAuthResendPacket(b []byte) (*ClientAuthResendPacket, error)

type ClientFlags

type ClientFlags uint32
const (
	ClientLongPassword               ClientFlags = 1 << iota // 0000_0001
	ClientFoundRows                                          // 0000_0002
	ClientLongFlag                                           // 0000_0004
	ClientConnectWithDB                                      // 0000_0008
	ClientNoSchema                                           // 0000_0010 (16)
	ClientCompress                                           // 0000_0020 (32)
	ClientODBC                                               // 0000_0040 (64)
	ClientLocalFiles                                         // 0000_0080 (128)
	ClientIgnoreSpace                                        // 0000_0100 (256)
	ClientProtocol41                                         // 0000_0200 (512)
	ClientInteractive                                        // 0000_0400 (1024)
	ClientSSL                                                // 0000_0800 (2048)
	ClientIgnoreSIGPIPE                                      // 0000_1000 (4096)
	ClientTransactions                                       // 0000_2000 (8192)
	ClientReserved                                           // 0000_4000 (16384)
	ClientSecureConn                                         // 0000_8000 (32768)
	ClientMultiStatements                                    // 0001_0000 (1UL << 16)
	ClientMultiResults                                       // 0002_0000 (1UL << 17)
	ClientPSMultiResults                                     // 0004_0000 (1UL << 18)
	ClientPluginAuth                                         // 0008_0000 (1UL << 19)
	ClientConnectAttrs                                       // 0010_0000 (1UL << 20)
	ClientPluginAuthLenEncClientData                         // 0020_0000 (1UL << 21)
	ClientCanHandleExpiredPasswords                          // 0040_0000 (1UL << 22)
	ClientSessionTrack                                       // 0080_0000 (1UL << 23)
	ClientDeprecateEOF                                       // 0100_0000 (1UL << 24)
	ClientOptionalResultsetMetadata                          // 0200_0000 (1UL << 25)
	ClientZstdCompressionAlgorithm                           // 0400_0000 (1UL << 26)
	ClientQueryAttributes                                    // 0800_0000 (1UL << 27)
	MultiFactorAuthorization                                 // 1000_0000 (1UL << 28)
	ClientCapabilityExtension                                // 2000_0000 (1UL << 29)
	ClientSSLVerifyServerCert                                // 4000_0000 (1UL << 30)
	ClientRememberOptions                                    // 8000_0000 (1UL << 31)
)

type ClientHandshakePacket

type ClientHandshakePacket struct {
	ClientFlags    ClientFlags
	MaxPacketSize  uint32
	Charset        uint8
	Username       string
	HashedPassword *StringV
	Database       string
}

func NewClientHandshakePacket

func NewClientHandshakePacket(b []byte) (*ClientHandshakePacket, error)

type CloseQueryPacket

type CloseQueryPacket struct {
	StatementID uint32
}

func NewCloseQueryPacket

func NewCloseQueryPacket(b []byte) (*CloseQueryPacket, error)

type Command

type Command interface {
	CommandType() CommandType
}

type CommandType

type CommandType int

type Context

type Context struct {
	ClientFlags ClientFlags

	// Compression support
	WillCompress bool
	Compressing  bool

	// (client) Query attributes enabled
	QueryAttributes bool

	State State

	// Server status
	ResultState ResultState
	FieldNCurr  uint64
	FieldNMax   uint64

	// Prepare statements
	PreparedStmts map[uint32]Stmt

	// Client status
	LastCommand CommandType

	Data interface{}
}

Context represents the context for a connection.

func (*Context) IsClientDeprecateEOF

func (ctx *Context) IsClientDeprecateEOF() bool

type CountReader

type CountReader struct {
	R io.Reader
	N uint64
}

func (*CountReader) Read

func (cr *CountReader) Read(p []byte) (int, error)

type EOFPacket

type EOFPacket struct {
	WarningCount uint16
	ServerStatus uint16
}

func NewEOFPacket

func NewEOFPacket(b []byte) (*EOFPacket, error)

type ErrorPacket

type ErrorPacket struct {
	Number  uint16
	State   string
	Message string
}

func NewErrorPacket

func NewErrorPacket(b []byte) (*ErrorPacket, error)

type ExecuteQueryPacket

type ExecuteQueryPacket struct {
	StatementID uint32
	CursorType  uint8
	Types       []FieldType
	Parameters  []interface{}
}

func NewExecuteQueryPacket

func NewExecuteQueryPacket(b []byte, ctx *Context) (*ExecuteQueryPacket, error)

func (*ExecuteQueryPacket) CommandType

func (p *ExecuteQueryPacket) CommandType() CommandType

type FieldListPacket

type FieldListPacket struct {
	Table    string
	Wildcard string
}

func NewFieldListPacket

func NewFieldListPacket(b []byte) (*FieldListPacket, error)

func (*FieldListPacket) CommandType

func (pkt *FieldListPacket) CommandType() CommandType

type FieldType

type FieldType uint16
const (
	FieldTypeDecimal FieldType = iota
	FieldTypeTiny
	FieldTypeShort
	FieldTypeLong
	FieldTypeFloat
	FieldTypeDouble
	FieldTypeNULL
	FieldTypeTimestamp
	FieldTypeLongLong
	FieldTypeInt24
	FieldTypeDate
	FieldTypeTime
	FieldTypeDateTime
	FieldTypeYear
	FieldTypeNewDate
	FieldTypeVarChar
	FieldTypeBit
)
const (
	FieldTypeJSON FieldType = iota + 0xf5
	FieldTypeNewDecimal
	FieldTypeEnum
	FieldTypeSet
	FieldTypeTinyBLOB
	FieldTypeMediumBLOB
	FieldTypeLongBLOB
	FieldTypeBLOB
	FieldTypeVarString
	FieldTypeString
	FieldTypeGeometry
)

type OKPacket

type OKPacket struct {
	AffectedRows *UintV
	InsertID     *UintV
	Status       uint16
	WarningCount uint16
	Message      string
}

func NewOKPacket

func NewOKPacket(b []byte) (*OKPacket, error)

type Parser

type Parser struct {
	PktLens []int
	SeqNums []uint8
	Body    []byte

	Detail interface{}
	// contains filtered or unexported fields
}

func NewFromClient

func NewFromClient(r io.Reader) *Parser

NewFromServer creates a parser to parse packet from client.

func NewFromServer

func NewFromServer(r io.Reader) *Parser

NewFromServer creates a parser to parse packet from server.

func (*Parser) Context

func (pa *Parser) Context() Context

func (*Parser) ContextData

func (pa *Parser) ContextData() interface{}

func (*Parser) PacketRawLen

func (pa *Parser) PacketRawLen() uint64

func (*Parser) Parse

func (pa *Parser) Parse() error

func (*Parser) SetContextData

func (pa *Parser) SetContextData(d interface{})

func (*Parser) ShareContext

func (pa *Parser) ShareContext(other *Parser)

func (*Parser) String

func (pa *Parser) String() string

type PrepareQueryPacket

type PrepareQueryPacket struct {
	Query string
}

func NewPrepareQueryPacket

func NewPrepareQueryPacket(b []byte) (*PrepareQueryPacket, error)

func (*PrepareQueryPacket) CommandType

func (p *PrepareQueryPacket) CommandType() CommandType

type PrepareResultPacket

type PrepareResultPacket struct {
	StatementID    uint32
	FieldCount     uint16
	ParameterCount uint16
	WarningCount   uint16
}

func NewPrepareResultPacket

func NewPrepareResultPacket(b []byte) (*PrepareResultPacket, error)

type QueryPacket

type QueryPacket struct {
	ParamCount    *UintV
	ParamSetCount *UintV
	Query         string
}

func NewQueryPacket

func NewQueryPacket(b []byte, ctx *Context) (*QueryPacket, error)

NewQueryPacket parses a COM_QUERY packet. See https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_query.html also

func (*QueryPacket) CommandType

func (p *QueryPacket) CommandType() CommandType

type QuitPacket

type QuitPacket struct{}

func (*QuitPacket) CommandType

func (pkt *QuitPacket) CommandType() CommandType

type ResultFieldNumPacket

type ResultFieldNumPacket struct {
	Num uint64
}

type ResultFieldPacket

type ResultFieldPacket struct {
	ResultPacket
	Database     *StringV
	Table        *StringV
	TableOrigin  *StringV
	Column       *StringV
	ColumnOrigin *StringV
	Charset      uint16
	Length       uint32
	Type         uint8
	Flag         uint16
	DotN         uint8
	Default      *StringV
}

func NewResultFieldPacket

func NewResultFieldPacket(b []byte) (*ResultFieldPacket, error)

type ResultNonePacket

type ResultNonePacket struct {
	ResultPacket
	AffectedRows *UintV
	InsertID     *UintV
	ServerStatus uint16
	WarningCount uint16
	Message      *StringV
}

func NewResultNonePacket

func NewResultNonePacket(b []byte) (*ResultNonePacket, error)

type ResultPacket

type ResultPacket struct {
}

type ResultRecordPacket

type ResultRecordPacket struct {
	ResultPacket
	Columns []*StringV
}

func NewResultRecordPacket

func NewResultRecordPacket(b []byte, nfields int) (*ResultRecordPacket, error)

type ResultState

type ResultState int
const (
	Fields ResultState = iota + 1
	Records
	PrepareParamsAndColumns
	PrepareParams
	PrepareColumns
)

type ServerHandshakePacket

type ServerHandshakePacket struct {
	ProtocolVersion  uint8
	ServerVersion    string
	ThreadID         uint32
	ScrambleBuffer   uint64
	Filter           uint8
	ServerCapability uint16
	Charset          uint8
	ServerStatus     uint16
}

func NewServerHandshakePacket

func NewServerHandshakePacket(b []byte) (*ServerHandshakePacket, error)

type State

type State int

State represents state of the connection

const (
	None State = iota
	Handshake
	Auth
	AuthResend
	AwaitingReply
	Connected
)

type Stmt

type Stmt struct {
	ID         uint32
	NumParams  uint16
	NumColumns uint16
}

type StringV

type StringV string

func (*StringV) GoString

func (v *StringV) GoString() string

func (*StringV) String

func (v *StringV) String() string

type UintV

type UintV uint64

func (*UintV) GoString

func (v *UintV) GoString() string

func (*UintV) String

func (v *UintV) String() string

func (*UintV) Uint64 added in v0.2.0

func (v *UintV) Uint64() uint64

Uint64 converts the value to uint64. Returns 0 if v (pointer) is nil.

Jump to

Keyboard shortcuts

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