For sets and enums length is already precalculated
This commit is contained in:
parent
8cbca43cf7
commit
b1e0b061f0
|
@ -9,7 +9,6 @@ import (
|
||||||
|
|
||||||
"github.com/localhots/bocadillo/mysql"
|
"github.com/localhots/bocadillo/mysql"
|
||||||
"github.com/localhots/bocadillo/tools"
|
"github.com/localhots/bocadillo/tools"
|
||||||
"github.com/localhots/pretty"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RowsEvent contains a Rows Event.
|
// RowsEvent contains a Rows Event.
|
||||||
|
@ -253,16 +252,14 @@ func (e *RowsEvent) decodeValue(buf *tools.Buffer, ct mysql.ColumnType, meta uin
|
||||||
buf.Skip(n)
|
buf.Skip(n)
|
||||||
return v
|
return v
|
||||||
case mysql.ColumnTypeSet:
|
case mysql.ColumnTypeSet:
|
||||||
length = int(meta & 0xFF)
|
|
||||||
nbits := length * 8
|
nbits := length * 8
|
||||||
v, n := mysql.DecodeBit(buf.Cur(), nbits, length)
|
v, n := mysql.DecodeBit(buf.Cur(), nbits, length)
|
||||||
pretty.Println("Decoding set", buf.Cur(), nbits, length, "-->", v)
|
|
||||||
buf.Skip(n)
|
buf.Skip(n)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
// Stuff
|
// Stuff
|
||||||
case mysql.ColumnTypeEnum:
|
case mysql.ColumnTypeEnum:
|
||||||
return buf.ReadVarLen64(int(meta & 0xFF))
|
return buf.ReadVarLen64(length)
|
||||||
|
|
||||||
// Unsupported
|
// Unsupported
|
||||||
case mysql.ColumnTypeDecimal:
|
case mysql.ColumnTypeDecimal:
|
||||||
|
|
|
@ -56,7 +56,6 @@ func (r *Reader) ReadEvent() (*Event, error) {
|
||||||
if err := evt.Header.Decode(connBuff, r.format); err != nil {
|
if err := evt.Header.Decode(connBuff, r.format); err != nil {
|
||||||
return nil, errors.Annotate(err, "decode event header")
|
return nil, errors.Annotate(err, "decode event header")
|
||||||
}
|
}
|
||||||
|
|
||||||
if evt.Header.NextOffset > 0 {
|
if evt.Header.NextOffset > 0 {
|
||||||
r.state.Offset = uint64(evt.Header.NextOffset)
|
r.state.Offset = uint64(evt.Header.NextOffset)
|
||||||
}
|
}
|
||||||
|
@ -71,26 +70,29 @@ func (r *Reader) ReadEvent() (*Event, error) {
|
||||||
switch evt.Header.Type {
|
switch evt.Header.Type {
|
||||||
case binlog.EventTypeFormatDescription:
|
case binlog.EventTypeFormatDescription:
|
||||||
var fde binlog.FormatDescriptionEvent
|
var fde binlog.FormatDescriptionEvent
|
||||||
err = fde.Decode(evt.Buffer)
|
err := fde.Decode(evt.Buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotate(err, "decode format description event")
|
return nil, errors.Annotate(err, "decode format description event")
|
||||||
}
|
}
|
||||||
r.format = fde.FormatDescription
|
r.format = fde.FormatDescription
|
||||||
evt.Format = fde.FormatDescription
|
evt.Format = fde.FormatDescription
|
||||||
|
|
||||||
case binlog.EventTypeRotate:
|
case binlog.EventTypeRotate:
|
||||||
var re binlog.RotateEvent
|
var re binlog.RotateEvent
|
||||||
err = re.Decode(evt.Buffer, r.format)
|
err := re.Decode(evt.Buffer, r.format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotate(err, "decode rotate event")
|
return nil, errors.Annotate(err, "decode rotate event")
|
||||||
}
|
}
|
||||||
r.state = re.NextFile
|
r.state = re.NextFile
|
||||||
|
|
||||||
case binlog.EventTypeTableMap:
|
case binlog.EventTypeTableMap:
|
||||||
var tme binlog.TableMapEvent
|
var tme binlog.TableMapEvent
|
||||||
err = tme.Decode(evt.Buffer, r.format)
|
err := tme.Decode(evt.Buffer, r.format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Annotate(err, "decode table map event")
|
return nil, errors.Annotate(err, "decode table map event")
|
||||||
}
|
}
|
||||||
r.tableMap[tme.TableID] = tme.TableDescription
|
r.tableMap[tme.TableID] = tme.TableDescription
|
||||||
|
|
||||||
case binlog.EventTypeWriteRowsV0,
|
case binlog.EventTypeWriteRowsV0,
|
||||||
binlog.EventTypeWriteRowsV1,
|
binlog.EventTypeWriteRowsV1,
|
||||||
binlog.EventTypeWriteRowsV2,
|
binlog.EventTypeWriteRowsV2,
|
||||||
|
@ -108,6 +110,7 @@ func (r *Reader) ReadEvent() (*Event, error) {
|
||||||
return nil, errors.New("Unknown table ID")
|
return nil, errors.New("Unknown table ID")
|
||||||
}
|
}
|
||||||
evt.Table = &td
|
evt.Table = &td
|
||||||
|
|
||||||
case binlog.EventTypeQuery:
|
case binlog.EventTypeQuery:
|
||||||
// Can be decoded by the receiver
|
// Can be decoded by the receiver
|
||||||
case binlog.EventTypeXID:
|
case binlog.EventTypeXID:
|
||||||
|
|
Loading…
Reference in New Issue