1
0
Fork 0
bocadillo/binlog/event_query.go

40 lines
1000 B
Go
Raw Normal View History

2018-11-11 13:24:45 +00:00
package binlog
import (
2018-11-20 20:28:43 +00:00
"github.com/localhots/bocadillo/buffer"
2018-11-11 13:24:45 +00:00
)
// QueryEvent contains query details.
type QueryEvent struct {
SlaveProxyID uint32
ExecutionTime uint32
ErrorCode uint16
StatusVars []byte
Schema []byte
Query []byte
}
// Decode given buffer into a qeury event.
// Spec: https://dev.mysql.com/doc/internals/en/query-event.html
func (e *QueryEvent) Decode(connBuff []byte) {
2018-11-20 20:28:43 +00:00
buf := buffer.New(connBuff)
2018-11-11 13:24:45 +00:00
e.SlaveProxyID = buf.ReadUint32()
e.ExecutionTime = buf.ReadUint32()
schemaLen := int(buf.ReadUint8())
e.ErrorCode = buf.ReadUint16()
statusVarLen := int(buf.ReadUint8())
2018-11-12 12:33:10 +00:00
e.StatusVars = make([]byte, statusVarLen)
2018-11-11 13:24:45 +00:00
copy(e.StatusVars, buf.Read(statusVarLen))
2018-11-12 12:33:10 +00:00
// FIXME: This is not by the spec but seem to work
// It could be there's an error somewhere and this byte skipping corrects it
buf.Skip(1) // Always 0x00
e.Schema = make([]byte, schemaLen)
2018-11-11 13:24:45 +00:00
copy(e.Schema, buf.Read(schemaLen))
2018-11-12 12:33:10 +00:00
2018-11-11 13:24:45 +00:00
buf.Skip(1) // Always 0x00
2018-11-12 12:33:10 +00:00
e.Query = buf.Cur()
2018-11-11 13:24:45 +00:00
}