common

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package common contains MySQL binlog constants and binary helpers shared by the MySQL decoder packages.

Index

Constants

View Source
const (
	MySQLTypeDecimal   = 0x00
	MySQLTypeTiny      = 0x01
	MySQLTypeShort     = 0x02
	MySQLTypeLong      = 0x03
	MySQLTypeFloat     = 0x04
	MySQLTypeDouble    = 0x05
	MySQLTypeNull      = 0x06
	MySQLTypeTimestamp = 0x07
	MySQLTypeLonglong  = 0x08
	MySQLTypeInt24     = 0x09
	MySQLTypeDate      = 0x0a
	MySQLTypeTime      = 0x0b
	MySQLTypeDatetime  = 0x0c
	MySQLTypeYear      = 0x0d
	MySQLTypeNewDate   = 0x0e
	MySQLTypeVarchar   = 0x0f
	MySQLTypeBit       = 0x10

	// mysql 5.6
	MySQLTypeTimestamp2 = 0x11
	MySQLTypeDatetime2  = 0x12
	MySQLTypeTime2      = 0x13

	// start with 0xf5
	MySQLTypeJSON       = 0xf5
	MySQLTypeNewDecimal = 0xf6
	MySQLTypeEnum       = 0xf7
	MySQLTypeSet        = 0xf8
	MySQLTypeTinyBlob   = 0xf9
	MySQLTypeMediumBlob = 0xfa
	MySQLTypeLongBlob   = 0xfb
	MySQLTypeBlob       = 0xfc
	MySQLTypeVarString  = 0xfd
	MySQLTypeString     = 0xfe
	MySQLTypeGeometry   = 0xff
)

https://dev.mysql.com/doc/internals/en/com-query-response.html#packet-Protocol::MYSQL_TYPE_STRING

View Source
const (
	UnknownEvent            = 0x00
	StartEventV3            = 0x01
	QueryEvent              = 0x02
	StopEvent               = 0x03
	RotateEvent             = 0x04
	IntvarEvent             = 0x05
	LoadEvent               = 0x06
	SlaveEvent              = 0x07
	CreateFileEvent         = 0x08
	AppendBlockEvent        = 0x09
	ExecLoadEvent           = 0x0a
	DeleteFileEvent         = 0x0b
	NewLoadEvent            = 0x0c
	RandEvent               = 0x0d
	UserVarEvent            = 0x0e
	FormatDescriptionEvent  = 0x0f
	XIDEvent                = 0x10
	BeginLoadQueryEvent     = 0x11
	ExecuteLoadQueryEvent   = 0x12
	TableMapEvent           = 0x13
	WriteRowsEventV0        = 0x14
	UpdateRowsEventV0       = 0x15
	DeleteRowsEventV0       = 0x16
	WriteRowsEventV1        = 0x17
	UpdateRowsEventV1       = 0x18
	DeleteRowsEventV1       = 0x19
	IncidentEvent           = 0x1a
	HeartbeatEvent          = 0x1b
	IgnorableEvent          = 0x1c
	RowsQueryEvent          = 0x1d
	WriteRowsEventV2        = 0x1e
	UpdateRowsEventV2       = 0x1f
	DeleteRowsEventV2       = 0x20
	GTIDEvent               = 0x21
	AnonymousGTIDEvent      = 0x22
	PreviousGTIDEvent       = 0x23
	TransactionContextEvent = 0x24
	ViewChangeEvent         = 0x25
	XAPrepareLogEvent       = 0x26
	PartialUpdateRowsEvent  = 0x27
	TransactionPayloadEvent = 0x28
	HeartbeatEventV2        = 0x29
	GTIDTaggedLogEvent      = 0x2a
)

https://dev.mysql.com/doc/internals/en/binlog-event-type.html

View Source
const (
	BinlogChecksumAlgOff   byte = 0
	BinlogChecksumAlgCRC32 byte = 1
	BinlogChecksumAlgUndef byte = 255
)

BINGLOG_CHECKSUM_ALG

View Source
const (
	QFlags2Code            = 0x00
	QSQLModeCode           = 0x01
	QCatalog               = 0x02
	QAutoIncrement         = 0x03
	QCharsetCode           = 0x04
	QTimeZoneCode          = 0x05
	QCatalogNZCode         = 0x06
	QLCTimeNamesCode       = 0x07
	QCharsetDatabaseCode   = 0x08
	QTableMapForUpdateCode = 0x09
	QMasterDataWrittenCode = 0x0a
	QInvokers              = 0x0b
	QUpdatedDBNames        = 0x0c
	QMicroseconds          = 0x0d
)

QUERY_EVENT status_vars

View Source
const BinlogChecksumLength = 4

BinlogChecksumLength https://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_binlog-checksum Beginning with MySQL 5.6.2, MySQL supports reading and writing of binary log checksums. ------------------------------------ | Default Value (>= 5.6.6) | CRC32 | | Default Value (<= 5.6.5) | NONE | ------------------------------------ Enabling this option causes the master to write checksums for events written to the binary log. Set to NONE to disable, or the name of the algorithm to be used for generating checksums; currently, only CRC32 checksums are supported. As of MySQL 5.6.6, CRC32 is the default. This option was added in MySQL 5.6.2.

View Source
const DefaultEventHeaderSize int64 = 19

DefaultEventHeaderSize mysql binlog version > 1 (version > mysql 4.0.0), size = 19

Variables

View Source
var EventType2Str = map[uint8]string{
	UnknownEvent:            "UNKNOWN_EVENT",
	StartEventV3:            "START_EVENT_V3",
	QueryEvent:              "QUERY_EVENT",
	StopEvent:               "STOP_EVENT",
	RotateEvent:             "ROTATE_EVENT",
	IntvarEvent:             "INTVAR_EVENT",
	LoadEvent:               "LOAD_EVENT",
	SlaveEvent:              "SLAVE_EVENT",
	CreateFileEvent:         "CREATE_FILE_EVENT",
	AppendBlockEvent:        "APPEND_BLOCK_EVENT",
	ExecLoadEvent:           "EXEC_LOAD_EVENT",
	DeleteFileEvent:         "DELETE_FILE_EVENT",
	NewLoadEvent:            "NEW_LOAD_EVENT",
	RandEvent:               "RAND_EVENT",
	UserVarEvent:            "USER_VAR_EVENT",
	FormatDescriptionEvent:  "FORMAT_DESCRIPTION_EVENT",
	XIDEvent:                "XID_EVENT",
	BeginLoadQueryEvent:     "BEGIN_LOAD_QUERY_EVENT",
	ExecuteLoadQueryEvent:   "EXECUTE_LOAD_QUERY_EVENT",
	TableMapEvent:           "TABLE_MAP_EVENT",
	WriteRowsEventV0:        "WRITE_ROWS_EVENTv0",
	UpdateRowsEventV0:       "UPDATE_ROWS_EVENTv0",
	DeleteRowsEventV0:       "DELETE_ROWS_EVENTv0",
	WriteRowsEventV1:        "WRITE_ROWS_EVENTv1",
	UpdateRowsEventV1:       "UPDATE_ROWS_EVENTv1",
	DeleteRowsEventV1:       "DELETE_ROWS_EVENTv1",
	IncidentEvent:           "INCIDENT_EVENT",
	HeartbeatEvent:          "HEARTBEAT_EVENT",
	IgnorableEvent:          "IGNORABLE_EVENT",
	RowsQueryEvent:          "ROWS_QUERY_EVENT",
	WriteRowsEventV2:        "WRITE_ROWS_EVENTv2",
	UpdateRowsEventV2:       "UPDATE_ROWS_EVENTv2",
	DeleteRowsEventV2:       "DELETE_ROWS_EVENTv2",
	GTIDEvent:               "GTID_EVENT",
	AnonymousGTIDEvent:      "ANONYMOUS_GTID_EVENT",
	PreviousGTIDEvent:       "PREVIOUS_GTIDS_EVENT",
	TransactionContextEvent: "TRANSACTION_CONTEXT_EVENT",
	ViewChangeEvent:         "VIEW_CHANGE_EVENT",
	XAPrepareLogEvent:       "XA_PREPARE_LOG_EVENT",
	PartialUpdateRowsEvent:  "PARTIAL_UPDATE_ROWS_EVENT",
	TransactionPayloadEvent: "TRANSACTION_PAYLOAD_EVENT",
	HeartbeatEventV2:        "HEARTBEAT_EVENT_V2",
	GTIDTaggedLogEvent:      "GTID_TAGGED_LOG_EVENT",
}

EventType2Str mapping the name of binary log event type

View Source
var QStatusKey2Str = map[uint8]string{
	QFlags2Code:            "Q_FLAGS2_CODE",
	QSQLModeCode:           "Q_SQL_MODE_CODE",
	QCatalog:               "Q_CATALOG",
	QAutoIncrement:         "Q_AUTO_INCREMENT",
	QCharsetCode:           "Q_CHARSET_CODE",
	QTimeZoneCode:          "Q_TIME_ZONE_CODE",
	QCatalogNZCode:         "Q_CATALOG_NZ_CODE",
	QLCTimeNamesCode:       "Q_LC_TIME_NAMES_CODE",
	QCharsetDatabaseCode:   "Q_CHARSET_DATABASE_CODE",
	QTableMapForUpdateCode: "Q_TABLE_MAP_FOR_UPDATE_CODE",
	QMasterDataWrittenCode: "Q_MASTER_DATA_WRITTEN_CODE",
	QInvokers:              "Q_INVOKERS",
	QUpdatedDBNames:        "Q_UPDATED_DB_NAMES",
	QMicroseconds:          "Q_MICROSECONDS",
}

QStatusKey2Str is the name of status_vars

Functions

func BitmapByteSize

func BitmapByteSize(columnCount int) int

func ChecksumValidate

func ChecksumValidate(checksumType byte, expectedChecksum []byte, data []byte) bool

ChecksumValidate will validate binary log event checksum This information is from 'github.com/siddontang/go-mysql/replication/parser.go' mysql use zlib's CRC32 implementation, which uses polynomial 0xedb88320UL. reference: https://github.com/madler/zlib/blob/master/crc32.c https://github.com/madler/zlib/blob/master/doc/rfc1952.txt#L419

func EventTypeName

func EventTypeName(eventType uint8) string

EventTypeName returns a stable display name for known and future event types.

func FixedLengthInt

func FixedLengthInt(buf []byte) uint64

FixedLengthInt will turn byte to uint64 this function is from 'github.com/siddontang/go-mysql/replication/util.go'

func HasChecksum

func HasChecksum(versionStr string) bool

func LengthEncodedInt

func LengthEncodedInt(b []byte) (num uint64, isNull bool, n int)

LengthEncodedInt will decode byte to uint64 this function is from 'github.com/siddontang/go-mysql/replication/util.go'

func LengthEnodedString

func LengthEnodedString(b []byte) ([]byte, bool, int, error)

LengthEnodedString will decode bytes

func MysqlVersion

func MysqlVersion(versionStr string) int

func ReadNBytes

func ReadNBytes(rd io.Reader, size int64) ([]byte, error)

ReadNBytes read n bytes from io.Reader

Types

This section is empty.

Jump to

Keyboard shortcuts

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