|
15 | 15 | */
|
16 | 16 | package com.github.shyiko.mysql.binlog.event.deserialization;
|
17 | 17 |
|
18 |
| -import com.github.shyiko.mysql.binlog.event.EventData; |
19 |
| -import com.github.shyiko.mysql.binlog.event.TableMapEventData; |
20 |
| -import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream; |
21 |
| - |
22 | 18 | import java.io.IOException;
|
23 | 19 | import java.io.Serializable;
|
24 | 20 | import java.math.BigDecimal;
|
|
27 | 23 | import java.util.Map;
|
28 | 24 | import java.util.TimeZone;
|
29 | 25 |
|
| 26 | +import com.github.shyiko.mysql.binlog.event.EventData; |
| 27 | +import com.github.shyiko.mysql.binlog.event.TableMapEventData; |
| 28 | +import com.github.shyiko.mysql.binlog.io.ByteArrayInputStream; |
| 29 | + |
30 | 30 | /**
|
31 | 31 | * Whole class is basically a mix of <a href="https://code.google.com/p/open-replicator">open-replicator</a>'s
|
32 | 32 | * AbstractRowEventParser and MySQLUtils. Main purpose here is to ease rows deserialization.<p>
|
@@ -170,6 +170,8 @@ protected Serializable deserializeCell(ColumnType type, int meta, int length, By
|
170 | 170 | return deserializeSet(length, inputStream);
|
171 | 171 | case GEOMETRY:
|
172 | 172 | return deserializeGeometry(meta, inputStream);
|
| 173 | + case JSON: |
| 174 | + return deserializeJson(meta, inputStream); |
173 | 175 | default:
|
174 | 176 | throw new IOException("Unsupported type " + type);
|
175 | 177 | }
|
@@ -329,6 +331,21 @@ protected byte[] deserializeGeometry(int meta, ByteArrayInputStream inputStream)
|
329 | 331 | return inputStream.read(dataLength);
|
330 | 332 | }
|
331 | 333 |
|
| 334 | + /** |
| 335 | + * Deserialize the {@code JSON} value on the input stream, and return MySQL's internal binary representation |
| 336 | + * of the JSON value. See {@link com.github.shyiko.mysql.binlog.json.JsonBinary} for a utility to parse this |
| 337 | + * binary representation into something more useful, including a string representation. |
| 338 | + * |
| 339 | + * @param meta the number of bytes in which the length of the JSON value is found first on the input stream |
| 340 | + * @param inputStream the stream containing the JSON value |
| 341 | + * @return the MySQL internal binary representation of the JSON value; may be null |
| 342 | + * @throws IOException if there is a problem reading the input stream |
| 343 | + */ |
| 344 | + protected byte[] deserializeJson(int meta, ByteArrayInputStream inputStream) throws IOException { |
| 345 | + int blobLength = inputStream.readInteger(4); |
| 346 | + return inputStream.read(blobLength); |
| 347 | + } |
| 348 | + |
332 | 349 | // checkstyle, please ignore ParameterNumber for the next line
|
333 | 350 | private static Long asUnixTime(int year, int month, int day, int hour, int minute, int second, int millis) {
|
334 | 351 | // https://dev.mysql.com/doc/refman/5.0/en/datetime.html
|
@@ -376,7 +393,7 @@ private static int[] split(long value, int divider, int length) {
|
376 | 393 | /**
|
377 | 394 | * see mysql/strings/decimal.c
|
378 | 395 | */
|
379 |
| - private static BigDecimal asBigDecimal(int precision, int scale, byte[] value) { |
| 396 | + public static BigDecimal asBigDecimal(int precision, int scale, byte[] value) { |
380 | 397 | boolean positive = (value[0] & 0x80) == 0x80;
|
381 | 398 | value[0] ^= 0x80;
|
382 | 399 | if (!positive) {
|
|
0 commit comments