File tree 4 files changed +28
-6
lines changed
main/java/com/github/shyiko/mysql/binlog/event
test/java/com/github/shyiko/mysql/binlog
4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package com .github .shyiko .mysql .binlog .event ;
17
17
18
+ import com .github .shyiko .mysql .binlog .event .deserialization .ChecksumType ;
19
+
18
20
/**
19
21
* @author <a href="mailto:stanley.shyiko@gmail.com">Stanley Shyiko</a>
20
22
*/
@@ -24,6 +26,7 @@ public class FormatDescriptionEventData implements EventData {
24
26
private String serverVersion ;
25
27
private int headerLength ;
26
28
private int dataLength ;
29
+ private ChecksumType checksumType = ChecksumType .NONE ;
27
30
28
31
public int getBinlogVersion () {
29
32
return binlogVersion ;
@@ -57,6 +60,14 @@ public int getDataLength() {
57
60
return dataLength ;
58
61
}
59
62
63
+ public ChecksumType getChecksumType () {
64
+ return checksumType ;
65
+ }
66
+
67
+ public void setChecksumType (ChecksumType checksumType ) {
68
+ this .checksumType = checksumType ;
69
+ }
70
+
60
71
@ Override
61
72
public String toString () {
62
73
final StringBuilder sb = new StringBuilder ();
@@ -65,6 +76,7 @@ public String toString() {
65
76
sb .append (", serverVersion='" ).append (serverVersion ).append ('\'' );
66
77
sb .append (", headerLength=" ).append (headerLength );
67
78
sb .append (", dataLength=" ).append (dataLength );
79
+ sb .append (", checksumType=" ).append (checksumType );
68
80
sb .append ('}' );
69
81
return sb .toString ();
70
82
}
Original file line number Diff line number Diff line change @@ -253,12 +253,7 @@ private EventData deserializeFormatDescriptionEventData(ByteArrayInputStream inp
253
253
} else {
254
254
formatDescriptionEvent = (FormatDescriptionEventData ) eventData ;
255
255
}
256
- int checksumBlockLength = eventBodyLength - formatDescriptionEvent .getDataLength ();
257
- if (checksumBlockLength > 0 ) {
258
- inputStream .skip (inputStream .available () - checksumBlockLength );
259
- int checksumType = inputStream .read ();
260
- checksumLength = ChecksumType .byOrdinal (checksumType ).getLength ();
261
- }
256
+ checksumLength = formatDescriptionEvent .getChecksumType ().getLength ();
262
257
} finally {
263
258
inputStream .skipToTheEndOfTheBlock ();
264
259
}
Original file line number Diff line number Diff line change @@ -29,13 +29,19 @@ public class FormatDescriptionEventDataDeserializer implements EventDataDeserial
29
29
30
30
@ Override
31
31
public FormatDescriptionEventData deserialize (ByteArrayInputStream inputStream ) throws IOException {
32
+ int eventBodyLength = inputStream .available ();
32
33
FormatDescriptionEventData eventData = new FormatDescriptionEventData ();
33
34
eventData .setBinlogVersion (inputStream .readInteger (2 ));
34
35
eventData .setServerVersion (inputStream .readString (50 ).trim ());
35
36
inputStream .skip (4 ); // redundant, present in a header
36
37
eventData .setHeaderLength (inputStream .readInteger (1 ));
37
38
inputStream .skip (EventType .FORMAT_DESCRIPTION .ordinal () - 1 );
38
39
eventData .setDataLength (inputStream .readInteger (1 ));
40
+ int checksumBlockLength = eventBodyLength - eventData .getDataLength ();
41
+ if (checksumBlockLength > 0 ) {
42
+ inputStream .skip (inputStream .available () - checksumBlockLength );
43
+ eventData .setChecksumType (ChecksumType .byOrdinal (inputStream .read ()));
44
+ }
39
45
return eventData ;
40
46
}
41
47
}
Original file line number Diff line number Diff line change @@ -61,6 +61,15 @@ public void testChecksumCRC32() throws Exception {
61
61
readAll (reader , 303 );
62
62
}
63
63
64
+ @ Test
65
+ public void testChecksumCRC32WithCustomEventDataDeserializer () throws Exception {
66
+ EventDeserializer eventDeserializer = new EventDeserializer ();
67
+ eventDeserializer .setEventDataDeserializer (EventType .FORMAT_DESCRIPTION , new NullEventDataDeserializer ());
68
+ BinaryLogFileReader reader = new BinaryLogFileReader (
69
+ new FileInputStream ("src/test/resources/mysql-bin.checksum-crc32" ), eventDeserializer );
70
+ readAll (reader , 303 );
71
+ }
72
+
64
73
private void readAll (BinaryLogFileReader reader , int expect ) throws IOException {
65
74
try {
66
75
int numberOfEvents = 0 ;
You can’t perform that action at this time.
0 commit comments