Skip to content

Commit 4ba28f9

Browse files
committed
refactor: easy to read
1 parent 765f7fb commit 4ba28f9

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public TableMapEventData deserialize(ByteArrayInputStream inputStream) throws IO
5757
return eventData;
5858
}
5959

60-
private List<Integer> numericColumnIndex(byte[] types){
60+
private List<Integer> numericColumnIndex(byte[] types) {
6161
ArrayList<Integer> numericColumnIndexList = new ArrayList<>();
6262
for (int i = 0; i < types.length; i++) {
6363
switch (ColumnType.byCode(types[i] & 0xff)) {
@@ -78,6 +78,7 @@ private List<Integer> numericColumnIndex(byte[] types){
7878
}
7979
return numericColumnIndexList;
8080
}
81+
8182
private int numericColumnCount(byte[] types) {
8283
int count = 0;
8384
for (int i = 0; i < types.length; i++) {
@@ -103,7 +104,7 @@ private int numericColumnCount(byte[] types) {
103104
private int[] readMetadata(ByteArrayInputStream inputStream, byte[] columnTypes) throws IOException {
104105
int[] metadata = new int[columnTypes.length];
105106
for (int i = 0; i < columnTypes.length; i++) {
106-
switch(ColumnType.byCode(columnTypes[i] & 0xFF)) {
107+
switch (ColumnType.byCode(columnTypes[i] & 0xFF)) {
107108
case FLOAT:
108109
case DOUBLE:
109110
case BLOB:

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int n
6969
switch (fieldType) {
7070
case SIGNEDNESS:
7171
result.setSignedness(
72-
convertColumnOrder(readBooleanList(inputStream, nNumericColumns), numericColumIdxList));
72+
convertColumnOrder(readBooleanList(inputStream, nNumericColumns), nColumns,
73+
numericColumIdxList));
7374
break;
7475
case DEFAULT_CHARSET:
7576
result.setDefaultCharset(readDefaultCharset(inputStream));
@@ -112,22 +113,21 @@ public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int n
112113
return result;
113114
}
114115

115-
private static BitSet convertColumnOrder(BitSet numericOrderBitSet, List<Integer> numericColumIdxList) {
116+
private static BitSet convertColumnOrder(BitSet numericOrderBitSet, int nColumns,
117+
List<Integer> numericColumIdxList) {
116118
// Case SIGNEDNESS The order of indices in the Inputstream corresponds to the order of numeric columns
117-
// So we need to map the index to all columns index (include non numeric type columns)
118-
Map<Integer, Integer> mappingColumnOrderMap = new HashMap<>();
119-
120-
for (int numericColumnOrder = 0; numericColumnOrder < numericColumIdxList.size();
121-
numericColumnOrder++) {
122-
int allColumnIndex = numericColumIdxList.get(numericColumnOrder);
123-
mappingColumnOrderMap.put(numericColumnOrder, allColumnIndex);
124-
}
119+
// So we need to change the index to all columns index (include non numeric type columns)
125120

126121
BitSet columnOrderBitSet = new BitSet();
127-
for (int i = 0; i < numericOrderBitSet.length(); i++) {
128-
int numericColumnOrder = numericOrderBitSet.nextSetBit(i);
129-
int allColumnIndex = mappingColumnOrderMap.get(numericColumnOrder);
130-
columnOrderBitSet.set(allColumnIndex);
122+
int position = 0;
123+
for (int columnIndex = 0; columnIndex < nColumns; columnIndex++) {
124+
if (numericColumIdxList.contains(columnIndex)) {
125+
if (numericOrderBitSet.get(position++)) {
126+
columnOrderBitSet.set(columnIndex);
127+
}
128+
129+
}
130+
131131
}
132132
return columnOrderBitSet;
133133
}
@@ -206,15 +206,16 @@ private enum MetadataFieldType {
206206
ENUM_AND_SET_DEFAULT_CHARSET(10), // Charsets of ENUM and SET columns
207207
ENUM_AND_SET_COLUMN_CHARSET(11), // Charsets of ENUM and SET columns
208208
VISIBILITY(12), // Column visibility (8.0.23 and newer)
209-
UNKNOWN_METADATA_FIELD_TYPE(128); // Returned with binlog-row-metadata=FULL from MySQL 8.0 in some cases
209+
UNKNOWN_METADATA_FIELD_TYPE(
210+
128); // Returned with binlog-row-metadata=FULL from MySQL 8.0 in some cases
210211

211212
private final int code;
212213

213214
private MetadataFieldType(int code) {
214215
this.code = code;
215216
}
216217

217-
public int getCode() { return code; }
218+
public int getCode() {return code;}
218219

219220
private static final Map<Integer, MetadataFieldType> INDEX_BY_CODE;
220221

0 commit comments

Comments
 (0)