1
0
Fork 0

Simplify rows event decoding

This commit is contained in:
Gregory Eremin 2018-11-11 14:33:26 +01:00
parent 69353f61bc
commit 8cbca43cf7
2 changed files with 10 additions and 3 deletions

View File

@ -118,3 +118,12 @@ func (r *Reader) ReadEvent() (*Event, error) {
return &evt, err
}
// DecodeRows decodes buffer into a rows event.
func (e Event) DecodeRows() (binlog.RowsEvent, error) {
re := binlog.RowsEvent{Type: e.Header.Type}
if binlog.RowsEventVersion(e.Header.Type) < 0 {
return re, errors.New("invalid rows event")
}
return re, re.Decode(e.Buffer, e.Format, *e.Table)
}

View File

@ -12,7 +12,6 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/localhots/bocadillo/binlog"
"github.com/localhots/bocadillo/mysql"
"github.com/localhots/bocadillo/reader"
)
@ -200,8 +199,7 @@ func (s *testSuite) expectValue(t *testing.T, tbl *table, exp interface{}) {
return
}
if evt.Table != nil && evt.Table.TableName == tbl.name {
re := binlog.RowsEvent{Type: evt.Header.Type}
err := re.Decode(evt.Buffer, evt.Format, *evt.Table)
re, err := evt.DecodeRows()
if err != nil {
t.Fatalf("Failed to decode rows event: %v", err)
}