Skip to content

Commit dee95a7

Browse files
committed
Adds parsing of IntVarEvents
1 parent 313a953 commit dee95a7

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

replication/const.go

+8
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,11 @@ const (
217217
TABLE_MAP_OPT_META_ENUM_AND_SET_DEFAULT_CHARSET
218218
TABLE_MAP_OPT_META_ENUM_AND_SET_COLUMN_CHARSET
219219
)
220+
221+
type IntVarEventType byte
222+
223+
const (
224+
INVALID IntVarEventType = iota
225+
LAST_INSERT_ID
226+
INSERT_ID
227+
)

replication/event.go

+16
Original file line numberDiff line numberDiff line change
@@ -643,3 +643,19 @@ func (e *MariadbGTIDListEvent) Dump(w io.Writer) {
643643
fmt.Fprintf(w, "Lists: %v\n", e.GTIDs)
644644
fmt.Fprintln(w)
645645
}
646+
647+
type IntVarEvent struct {
648+
Type IntVarEventType
649+
Value uint64
650+
}
651+
652+
func (i *IntVarEvent) Decode(data []byte) error {
653+
i.Type = IntVarEventType(data[0])
654+
i.Value = binary.LittleEndian.Uint64(data[1:])
655+
return nil
656+
}
657+
658+
func (i *IntVarEvent) Dump(w io.Writer) {
659+
fmt.Fprintf(w, "Type: %d\n", i.Type)
660+
fmt.Fprintf(w, "Value: %d\n", i.Value)
661+
}

replication/event_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,21 @@ func (_ *testDecodeSuite) TestGTIDEventMysql8NewFields(c *C) {
9797
c.Assert(ev.OriginalServerVersion, Equals, tc.expectOriginalServerVersion)
9898
}
9999
}
100+
101+
func (_ *testDecodeSuite) TestIntVarEvent(c *C) {
102+
// IntVarEvent Type LastInsertID, Value 13
103+
data := []byte{1, 13, 0, 0, 0, 0, 0, 0, 0}
104+
ev := IntVarEvent{}
105+
err := ev.Decode(data)
106+
c.Assert(err, IsNil)
107+
c.Assert(ev.Type, Equals, LAST_INSERT_ID)
108+
c.Assert(ev.Value, Equals, uint64(13))
109+
110+
// IntVarEvent Type InsertID, Value 23
111+
data = []byte{2, 23, 0, 0, 0, 0, 0, 0, 0}
112+
ev = IntVarEvent{}
113+
err = ev.Decode(data)
114+
c.Assert(err, IsNil)
115+
c.Assert(ev.Type, Equals, INSERT_ID)
116+
c.Assert(ev.Value, Equals, uint64(23))
117+
}

replication/generic_event.go

-5
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ func (e *GenericEvent) Decode(data []byte) error {
141141
// Seed2 uint64
142142
// }
143143

144-
// type IntVarEvent struct {
145-
// Type uint8
146-
// Value uint64
147-
// }
148-
149144
// type UserVarEvent struct {
150145
// NameLength uint32
151146
// Name []byte

replication/parser.go

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ func (p *BinlogParser) parseEvent(h *EventHeader, data []byte, rawData []byte) (
281281
e = ee
282282
case PREVIOUS_GTIDS_EVENT:
283283
e = &PreviousGTIDsEvent{}
284+
case INTVAR_EVENT:
285+
e = &IntVarEvent{}
284286
default:
285287
e = &GenericEvent{}
286288
}

0 commit comments

Comments
 (0)