From 425a2f257294bd320adbb61758cc1f2eac7e719f Mon Sep 17 00:00:00 2001 From: winteen Date: Thu, 2 Apr 2015 08:56:06 +0800 Subject: [PATCH 1/3] refact AbstractRowsEventDataDeserializer: make logic flow more reasonable. --- .../AbstractRowsEventDataDeserializer.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java index 1f2b1d03..3a834d3b 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java @@ -71,28 +71,28 @@ protected Serializable[] deserializeRow(long tableId, BitSet includedColumns, By Serializable[] result = new Serializable[numberOfBitsSet(includedColumns)]; BitSet nullColumns = inputStream.readBitSet(result.length, true); for (int i = 0, numberOfSkippedColumns = 0; i < types.length; i++) { - int typeCode = types[i] & 0xFF, meta = metadata[i], length = 0; - if (typeCode == ColumnType.STRING.getCode() && meta > 256) { - int meta0 = meta >> 8, meta1 = meta & 0xFF; - if ((meta0 & 0x30) != 0x30) { // long CHAR field - typeCode = meta0 | 0x30; - length = meta1 | (((meta0 & 0x30) ^ 0x30) << 4); - } else { - if (meta0 == ColumnType.SET.getCode() || meta0 == ColumnType.ENUM.getCode() || - meta0 == ColumnType.STRING.getCode()) { - typeCode = meta0; - length = meta1; - } else { - throw new IOException("Unexpected meta " + meta + " for column of type " + typeCode); - } - } - } if (!includedColumns.get(i)) { numberOfSkippedColumns++; continue; } int index = i - numberOfSkippedColumns; if (!nullColumns.get(index)) { + int typeCode = types[i] & 0xFF, meta = metadata[i], length = 0; + if (typeCode == ColumnType.STRING.getCode() && meta > 256) { + int meta0 = meta >> 8, meta1 = meta & 0xFF; + if ((meta0 & 0x30) != 0x30) { // long CHAR field + typeCode = meta0 | 0x30; + length = meta1 | (((meta0 & 0x30) ^ 0x30) << 4); + } else { + if (meta0 == ColumnType.SET.getCode() || meta0 == ColumnType.ENUM.getCode() || + meta0 == ColumnType.STRING.getCode()) { + typeCode = meta0; + length = meta1; + } else { + throw new IOException("Unexpected meta " + meta + " for column of type " + typeCode); + } + } + } result[index] = deserializeCell(ColumnType.byCode(typeCode), meta, length, inputStream); } } @@ -374,4 +374,4 @@ private static long bigEndianLong(byte[] bytes, int offset, int length) { return result; } -} \ No newline at end of file +} From ad05644bff17c26f6e838ef0008f5a04f789311d Mon Sep 17 00:00:00 2001 From: winteen Date: Thu, 2 Apr 2015 09:00:02 +0800 Subject: [PATCH 2/3] Beautify code --- .../deserialization/AbstractRowsEventDataDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java index 3a834d3b..415b1e06 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java @@ -77,7 +77,7 @@ protected Serializable[] deserializeRow(long tableId, BitSet includedColumns, By } int index = i - numberOfSkippedColumns; if (!nullColumns.get(index)) { - int typeCode = types[i] & 0xFF, meta = metadata[i], length = 0; + int typeCode = types[i] & 0xFF, meta = metadata[i], length = 0; if (typeCode == ColumnType.STRING.getCode() && meta > 256) { int meta0 = meta >> 8, meta1 = meta & 0xFF; if ((meta0 & 0x30) != 0x30) { // long CHAR field From b9f4214ddb0aee4b7b07adc237bbad0bd9c3e04e Mon Sep 17 00:00:00 2001 From: chenyun Date: Fri, 3 Apr 2015 09:48:37 +0800 Subject: [PATCH 3/3] delete trailing spaces --- .../deserialization/AbstractRowsEventDataDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java index 415b1e06..5881a220 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/AbstractRowsEventDataDeserializer.java @@ -92,7 +92,7 @@ protected Serializable[] deserializeRow(long tableId, BitSet includedColumns, By throw new IOException("Unexpected meta " + meta + " for column of type " + typeCode); } } - } + } result[index] = deserializeCell(ColumnType.byCode(typeCode), meta, length, inputStream); } }