Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.actiontech.dble.net.connection.AbstractConnection;
import com.actiontech.dble.net.service.AbstractService;
import com.actiontech.dble.net.service.WriteFlags;
import com.actiontech.dble.plan.common.field.FieldUtil;
import com.actiontech.dble.statistic.sql.StatisticListener;
import com.actiontech.dble.util.ByteUtil;
import com.actiontech.dble.util.DateUtil;
Expand Down Expand Up @@ -91,6 +92,7 @@ private void storeNullBitMap(int i) {
private void convert(byte[] fv, FieldPacket fieldPk) {

int fieldType = fieldPk.getType();
boolean unsigned = (fieldPk.getFlags() & FieldUtil.UNSIGNED_FLAG) != 0;
switch (fieldType) {
case Fields.FIELD_TYPE_STRING:
case Fields.FIELD_TYPE_VARCHAR:
Expand Down Expand Up @@ -118,8 +120,14 @@ private void convert(byte[] fv, FieldPacket fieldPk) {

// Example
// 01 00 00 00 00 00 00 00 -- int64 = 1
long longVar = ByteUtil.getLong(fv);
this.fieldValues.add(ByteUtil.getBytes(longVar));
if (unsigned) {
long longVar = ByteUtil.getUnsignedLong(fv);
this.fieldValues.add(ByteUtil.getBytes(longVar));
} else {
long longVar = ByteUtil.getLong(fv);
this.fieldValues.add(ByteUtil.getBytes(longVar));
}

break;
case Fields.FIELD_TYPE_LONG:
case Fields.FIELD_TYPE_INT24:
Expand All @@ -128,8 +136,14 @@ private void convert(byte[] fv, FieldPacket fieldPk) {

// Example
// 01 00 00 00 -- int32 = 1
int intVar = ByteUtil.getInt(fv);
this.fieldValues.add(ByteUtil.getBytes(intVar));
if (unsigned) {
int intVar = ByteUtil.getUnsignedInt(fv);
this.fieldValues.add(ByteUtil.getBytes(intVar));
} else {
int intVar = ByteUtil.getInt(fv);
this.fieldValues.add(ByteUtil.getBytes(intVar));
}

break;
case Fields.FIELD_TYPE_SHORT:
case Fields.FIELD_TYPE_YEAR:
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/actiontech/dble/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public static int getInt(byte[] bytes) {
// (bytes[2] << 16)) | (0xff000000 & (bytes[3] << 24));
}

public static int getUnsignedInt(byte[] bytes) {
return Integer.parseUnsignedInt(new String(bytes));
// return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 &
// (bytes[2] << 16)) | (0xff000000 & (bytes[3] << 24));
}

public static long getLong(byte[] bytes) {
return Long.parseLong(new String(bytes));
// return(0xffL & (long)bytes[0]) | (0xff00L & ((long)bytes[1] << 8)) |
Expand All @@ -169,6 +175,16 @@ public static long getLong(byte[] bytes) {
// 48)) | (0xff00000000000000L & ((long)bytes[7] << 56));
}

public static long getUnsignedLong(byte[] bytes) {
return Long.parseUnsignedLong(new String(bytes));
// return(0xffL & (long)bytes[0]) | (0xff00L & ((long)bytes[1] << 8)) |
// (0xff0000L & ((long)bytes[2] << 16)) | (0xff000000L & ((long)bytes[3]
// << 24))
// | (0xff00000000L & ((long)bytes[4] << 32)) | (0xff0000000000L &
// ((long)bytes[5] << 40)) | (0xff000000000000L & ((long)bytes[6] <<
// 48)) | (0xff00000000000000L & ((long)bytes[7] << 56));
}

public static double getDouble(byte[] bytes) {
return Double.parseDouble(new String(bytes));
}
Expand Down
Loading