Skip to content

Commit 7d6d123

Browse files
committed
add EventDeserializer.CompatibilityMode.INTEGER_AS_BYTE_ARRAY impl.
1 parent 8204086 commit 7d6d123

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public abstract class AbstractRowsEventDataDeserializer<T extends EventData> imp
7575
private Long invalidDateAndTimeRepresentation;
7676
private boolean microsecondsPrecision;
7777
private boolean deserializeCharAndBinaryAsByteArray;
78+
private boolean deserializeIntegerAsByteArray;
7879

7980
public AbstractRowsEventDataDeserializer(Map<Long, TableMapEventData> tableMapEventByTableId) {
8081
this.tableMapEventByTableId = tableMapEventByTableId;
@@ -97,6 +98,10 @@ void setDeserializeCharAndBinaryAsByteArray(boolean value) {
9798
this.deserializeCharAndBinaryAsByteArray = value;
9899
}
99100

101+
void setDeserializeIntegerAsByteArray(boolean deserializeIntegerAsByteArray) {
102+
this.deserializeIntegerAsByteArray = deserializeIntegerAsByteArray;
103+
}
104+
100105
protected Serializable[] deserializeRow(long tableId, BitSet includedColumns, ByteArrayInputStream inputStream)
101106
throws IOException {
102107
TableMapEventData tableMapEvent = tableMapEventByTableId.get(tableId);
@@ -203,22 +208,37 @@ protected Serializable deserializeBit(int meta, ByteArrayInputStream inputStream
203208
}
204209

205210
protected Serializable deserializeTiny(ByteArrayInputStream inputStream) throws IOException {
211+
if (deserializeIntegerAsByteArray) {
212+
return inputStream.read(1);
213+
}
206214
return (int) ((byte) inputStream.readInteger(1));
207215
}
208216

209217
protected Serializable deserializeShort(ByteArrayInputStream inputStream) throws IOException {
218+
if (deserializeIntegerAsByteArray) {
219+
return inputStream.read(2);
220+
}
210221
return (int) ((short) inputStream.readInteger(2));
211222
}
212223

213224
protected Serializable deserializeInt24(ByteArrayInputStream inputStream) throws IOException {
225+
if (deserializeIntegerAsByteArray) {
226+
return inputStream.read(3);
227+
}
214228
return (inputStream.readInteger(3) << 8) >> 8;
215229
}
216230

217231
protected Serializable deserializeLong(ByteArrayInputStream inputStream) throws IOException {
232+
if (deserializeIntegerAsByteArray) {
233+
return inputStream.read(4);
234+
}
218235
return inputStream.readInteger(4);
219236
}
220237

221238
protected Serializable deserializeLongLong(ByteArrayInputStream inputStream) throws IOException {
239+
if (deserializeIntegerAsByteArray) {
240+
return inputStream.read(8);
241+
}
222242
return inputStream.readLong(8);
223243
}
224244

src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventDeserializer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ private void ensureCompatibility(EventDataDeserializer eventDataDeserializer) {
200200
deserializer.setDeserializeCharAndBinaryAsByteArray(
201201
compatibilitySet.contains(CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY)
202202
);
203+
deserializer.setDeserializeIntegerAsByteArray(
204+
compatibilitySet.contains(CompatibilityMode.INTEGER_AS_BYTE_ARRAY)
205+
);
203206
}
204207
}
205208

@@ -350,7 +353,11 @@ public enum CompatibilityMode {
350353
*
351354
* <p>This option is going to be enabled by default starting from mysql-binlog-connector-java@1.0.0.
352355
*/
353-
CHAR_AND_BINARY_AS_BYTE_ARRAY
356+
CHAR_AND_BINARY_AS_BYTE_ARRAY,
357+
/**
358+
* Return TINY/SHORT/INT24/LONG/LONGLONG values as byte[]|s (instead of int|s).
359+
*/
360+
INTEGER_AS_BYTE_ARRAY
354361
}
355362

356363
/**

0 commit comments

Comments
 (0)