@@ -2,6 +2,7 @@ package replication
2
2
3
3
import (
4
4
"encoding/binary"
5
+ "encoding/hex"
5
6
"fmt"
6
7
"io"
7
8
"strconv"
@@ -217,6 +218,55 @@ func (e *RotateEvent) Dump(w io.Writer) {
217
218
fmt .Fprintln (w )
218
219
}
219
220
221
+ type PreviousGTIDsEvent struct {
222
+ GTIDSets string
223
+ }
224
+
225
+ func (e * PreviousGTIDsEvent ) Decode (data []byte ) error {
226
+ var previousGTIDSets []string
227
+ pos := 0
228
+ uuidCount := binary .LittleEndian .Uint16 (data [pos :pos + 8 ])
229
+ pos += 8
230
+
231
+ for i := uint16 (0 );i < uuidCount ; i ++ {
232
+ uuid := e .decodeUuid (data [pos :pos + 16 ])
233
+ pos += 16
234
+ sliceCount := binary .LittleEndian .Uint16 (data [pos :pos + 8 ])
235
+ pos += 8
236
+ var intervals []string
237
+ for i := uint16 (0 );i < sliceCount ; i ++ {
238
+ start := e .decodeInterval (data [pos :pos + 8 ])
239
+ pos += 8
240
+ stop := e .decodeInterval (data [pos :pos + 8 ])
241
+ pos += 8
242
+ interval := ""
243
+ if stop == start + 1 {
244
+ interval = fmt .Sprintf ("%d" ,start )
245
+ }else {
246
+ interval = fmt .Sprintf ("%d-%d" ,start ,stop - 1 )
247
+ }
248
+ intervals = append (intervals ,interval )
249
+ }
250
+ previousGTIDSets = append (previousGTIDSets ,fmt .Sprintf ("%s:%s" ,uuid ,strings .Join (intervals ,":" )))
251
+ }
252
+ e .GTIDSets = fmt .Sprintf ("%s" ,strings .Join (previousGTIDSets ,"," ))
253
+ return nil
254
+ }
255
+
256
+ func (e * PreviousGTIDsEvent ) Dump (w io.Writer ) {
257
+ fmt .Fprintf (w , "Previous GTID Event: %s\n " , e .GTIDSets )
258
+ fmt .Fprintln (w )
259
+ }
260
+
261
+ func (e * PreviousGTIDsEvent ) decodeUuid (data []byte ) string {
262
+ return fmt .Sprintf ("%s-%s-%s-%s-%s" ,hex .EncodeToString (data [0 :4 ]),hex .EncodeToString (data [4 :6 ]),
263
+ hex .EncodeToString (data [6 :8 ]),hex .EncodeToString (data [8 :10 ]),hex .EncodeToString (data [10 :]))
264
+ }
265
+
266
+ func (e * PreviousGTIDsEvent ) decodeInterval (data []byte ) uint64 {
267
+ return binary .LittleEndian .Uint64 (data )
268
+ }
269
+
220
270
type XIDEvent struct {
221
271
XID uint64
222
272
0 commit comments