Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds parsing of IntVarEvents #624

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions replication/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ const (
TABLE_MAP_OPT_META_ENUM_AND_SET_DEFAULT_CHARSET
TABLE_MAP_OPT_META_ENUM_AND_SET_COLUMN_CHARSET
)

type IntVarEventType byte

const (
INVALID IntVarEventType = iota
LAST_INSERT_ID
INSERT_ID
)
16 changes: 16 additions & 0 deletions replication/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,19 @@ func (e *MariadbGTIDListEvent) Dump(w io.Writer) {
fmt.Fprintf(w, "Lists: %v\n", e.GTIDs)
fmt.Fprintln(w)
}

type IntVarEvent struct {
Type IntVarEventType
Value uint64
}

func (i *IntVarEvent) Decode(data []byte) error {
i.Type = IntVarEventType(data[0])
i.Value = binary.LittleEndian.Uint64(data[1:])
return nil
}

func (i *IntVarEvent) Dump(w io.Writer) {
fmt.Fprintf(w, "Type: %d\n", i.Type)
fmt.Fprintf(w, "Value: %d\n", i.Value)
}
18 changes: 18 additions & 0 deletions replication/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,21 @@ func (_ *testDecodeSuite) TestGTIDEventMysql8NewFields(c *C) {
c.Assert(ev.OriginalServerVersion, Equals, tc.expectOriginalServerVersion)
}
}

func (_ *testDecodeSuite) TestIntVarEvent(c *C) {
// IntVarEvent Type LastInsertID, Value 13
data := []byte{1, 13, 0, 0, 0, 0, 0, 0, 0}
ev := IntVarEvent{}
err := ev.Decode(data)
c.Assert(err, IsNil)
c.Assert(ev.Type, Equals, LAST_INSERT_ID)
c.Assert(ev.Value, Equals, uint64(13))

// IntVarEvent Type InsertID, Value 23
data = []byte{2, 23, 0, 0, 0, 0, 0, 0, 0}
ev = IntVarEvent{}
err = ev.Decode(data)
c.Assert(err, IsNil)
c.Assert(ev.Type, Equals, INSERT_ID)
c.Assert(ev.Value, Equals, uint64(23))
}
5 changes: 0 additions & 5 deletions replication/generic_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ func (e *GenericEvent) Decode(data []byte) error {
// Seed2 uint64
// }

// type IntVarEvent struct {
// Type uint8
// Value uint64
// }

// type UserVarEvent struct {
// NameLength uint32
// Name []byte
Expand Down
2 changes: 2 additions & 0 deletions replication/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ func (p *BinlogParser) parseEvent(h *EventHeader, data []byte, rawData []byte) (
e = ee
case PREVIOUS_GTIDS_EVENT:
e = &PreviousGTIDsEvent{}
case INTVAR_EVENT:
e = &IntVarEvent{}
default:
e = &GenericEvent{}
}
Expand Down