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