|
18 | 18 | import com.github.shyiko.mysql.binlog.event.Event;
|
19 | 19 | import com.github.shyiko.mysql.binlog.event.EventData;
|
20 | 20 | import com.github.shyiko.mysql.binlog.event.EventHeader;
|
| 21 | +import com.github.shyiko.mysql.binlog.event.EventHeaderV4; |
21 | 22 | import com.github.shyiko.mysql.binlog.event.EventType;
|
| 23 | +import com.github.shyiko.mysql.binlog.event.FormatDescriptionEventData; |
22 | 24 | import com.github.shyiko.mysql.binlog.event.TableMapEventData;
|
23 | 25 | import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream;
|
24 | 26 |
|
@@ -240,6 +242,27 @@ public EventDataDeserializer getEventDataDeserializer(EventType eventType) {
|
240 | 242 | return eventDataDeserializer != null ? eventDataDeserializer : defaultEventDataDeserializer;
|
241 | 243 | }
|
242 | 244 |
|
| 245 | + public EventDeserializer detectChecksumType(ByteArrayInputStream inputStream) |
| 246 | + throws IOException { |
| 247 | + inputStream.mark(EventHeaderV4.HEADER_LEN); |
| 248 | + EventHeader eventHeader = eventHeaderDeserializer.deserialize(inputStream); |
| 249 | + inputStream.reset(); |
| 250 | + |
| 251 | + inputStream.mark((int) (EventHeaderV4.HEADER_LEN + eventHeader.getDataLength())); |
| 252 | + inputStream.skip(EventHeaderV4.HEADER_LEN); // skip header, not interpret it twice |
| 253 | + FormatDescriptionEventDataDeserializer deserializer = new FormatDescriptionEventDataDeserializer(); |
| 254 | + FormatDescriptionEventData formatDescriptionEventData = deserializer.deserialize(inputStream); |
| 255 | + int eventLength = formatDescriptionEventData.getEventLength(); |
| 256 | + // 1 byte means checksum algo, 4 byte is crc checksum content |
| 257 | + if (eventLength + 1 + 4 == eventHeader.getDataLength()) { |
| 258 | + setChecksumType(ChecksumType.CRC32); |
| 259 | + } else { |
| 260 | + setChecksumType(ChecksumType.NONE); |
| 261 | + } |
| 262 | + inputStream.reset(); |
| 263 | + return this; |
| 264 | + } |
| 265 | + |
243 | 266 | /**
|
244 | 267 | * @see CompatibilityMode#DATE_AND_TIME_AS_LONG
|
245 | 268 | * @see CompatibilityMode#DATE_AND_TIME_AS_LONG_MICRO
|
|
0 commit comments