More code documented

This commit is contained in:
2018-11-19 22:44:17 +01:00
parent be37d25444
commit db67e68078
5 changed files with 115 additions and 120 deletions
+2 -5
View File
@@ -54,7 +54,7 @@ const (
func (e *FormatDescriptionEvent) Decode(data []byte) error {
buf := tools.NewBuffer(data)
e.Version = buf.ReadUint16()
e.ServerVersion = trimString(buf.ReadStringVarLen(50))
e.ServerVersion = trimStringEOF(buf.ReadStringVarLen(50))
e.CreateTimestamp = buf.ReadUint32()
e.EventHeaderLength = buf.ReadUint8()
e.EventTypeHeaderLengths = buf.ReadStringEOF()
@@ -64,9 +64,6 @@ func (e *FormatDescriptionEvent) Decode(data []byte) error {
ChecksumAlgorithm: ChecksumAlgorithmUndefined,
}
if e.ServerDetails.Version > 50601 {
// Last 5 bytes are:
// [1] Checksum algorithm
// [4] Checksum
e.ServerDetails.ChecksumAlgorithm = ChecksumAlgorithm(data[len(data)-5])
e.EventTypeHeaderLengths = e.EventTypeHeaderLengths[:len(e.EventTypeHeaderLengths)-5]
}
@@ -127,7 +124,7 @@ func parseVersionNumber(v string) int {
return major*10000 + minor*100 + patch
}
func trimString(str []byte) string {
func trimStringEOF(str []byte) string {
for i, c := range str {
if c == 0x00 {
return string(str[:i])
+2 -1
View File
@@ -2,7 +2,8 @@ package binlog
import "github.com/localhots/bocadillo/tools"
// Position ...
// Position is a pair of log file name and a binary offset in it that is used to
// represent the beginning of the event description.
type Position struct {
File string
Offset uint64
+2 -9
View File
@@ -28,12 +28,7 @@ type RowsFlag uint16
const (
// RowsFlagEndOfStatement is used to clear old table mappings.
RowsFlagEndOfStatement RowsFlag = 0x0001
rowsFlagNoForeignKeyChecks RowsFlag = 0x0002
rowsFlagNoUniqueKeyChecks RowsFlag = 0x0004
rowsFlagRowHasColumns RowsFlag = 0x0008
freeTableMapID = 0x00FFFFFF
RowsFlagEndOfStatement RowsFlag = 0x0001
)
// PeekTableIDAndFlags returns table ID and flags without decoding whole event.
@@ -229,7 +224,7 @@ func (e *RowsEvent) decodeValue(buf *tools.Buffer, ct mysql.ColumnType, meta uin
case mysql.ColumnTypeLongblob:
return buf.ReadStringVarEnc(4)
// Bits
// Other
case mysql.ColumnTypeBit:
nbits := int(((meta >> 8) * 8) + (meta & 0xFF))
length = int(nbits+7) / 8
@@ -241,8 +236,6 @@ func (e *RowsEvent) decodeValue(buf *tools.Buffer, ct mysql.ColumnType, meta uin
v, n := mysql.DecodeBit(buf.Cur(), nbits, length)
buf.Skip(n)
return v
// Stuff
case mysql.ColumnTypeEnum:
return buf.ReadVarLen64(length)