1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shardingsphere.db.protocol.mysql.packet.binlog.management;
19
20 import com.google.common.base.Preconditions;
21 import lombok.Getter;
22 import lombok.ToString;
23 import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLBinlogEventType;
24 import org.apache.shardingsphere.db.protocol.mysql.packet.binlog.AbstractMySQLBinlogEventPacket;
25 import org.apache.shardingsphere.db.protocol.mysql.packet.binlog.MySQLBinlogEventHeader;
26 import org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
27
28
29
30
31
32
33
34 @Getter
35 @ToString
36 public final class MySQLBinlogFormatDescriptionEventPacket extends AbstractMySQLBinlogEventPacket {
37
38 private final int binlogVersion = 4;
39
40 private final byte[] mysqlServerVersion;
41
42 private final int createTimestamp;
43
44 private final int eventHeaderLength = 19;
45
46 public MySQLBinlogFormatDescriptionEventPacket(final MySQLBinlogEventHeader binlogEventHeader, final MySQLPacketPayload payload) {
47 super(binlogEventHeader);
48 Preconditions.checkArgument(binlogVersion == payload.readInt2(), "Binlog version of FORMAT_DESCRIPTION_EVENT should always 4");
49 mysqlServerVersion = payload.readStringFixByBytes(50);
50 createTimestamp = payload.readInt4();
51 Preconditions.checkArgument(eventHeaderLength == payload.readInt1(), "Length of the Binlog Event Header should always be 19.");
52 skipTypeHeaderLength(payload);
53 skipCheckSums(payload);
54 }
55
56
57
58
59
60
61
62
63 private void skipTypeHeaderLength(final MySQLPacketPayload payload) {
64 payload.skipReserved(MySQLBinlogEventType.FORMAT_DESCRIPTION_EVENT.getValue() - 1);
65 int eventLength = payload.readInt1();
66 int remainLength = eventLength - 2 - 50 - 4 - 1 - (MySQLBinlogEventType.FORMAT_DESCRIPTION_EVENT.getValue() - 1) - 1;
67 payload.skipReserved(remainLength);
68 }
69
70 private void skipCheckSums(final MySQLPacketPayload payload) {
71 int checksumAlgorithmFlag = payload.readInt1();
72 if (1 == checksumAlgorithmFlag) {
73 payload.skipReserved(4);
74 }
75 }
76
77 @Override
78 protected void writeEvent(final MySQLPacketPayload payload) {
79
80 }
81 }