wsky / top-link

embedded duplex multi-channel endpoint and connection management for c#/java/...
6 stars 1 forks source link

wrong ByteOrder in java MessageIO #68

Closed wsky closed 11 years ago

wsky commented 11 years ago
public static void writeMessage(ByteBuffer buffer, Message message) {
        buffer.order(ByteOrder.LITTLE_ENDIAN);
//...
buffer.order(ByteOrder.BIG_ENDIAN);
        buffer.flip();
}

but in writeCustomValue, order was changed...

private static void writeCustomValue(ByteBuffer buffer, Object value) {
        if (value == null) {
            buffer.put(ValueFormat.Void);
            return;
        }
        Class<?> type = value.getClass();
        if (byte.class.equals(type) || Byte.class.equals(type)) {
            buffer.put(ValueFormat.Byte);
            buffer.put((Byte) value);
        } else if (short.class.equals(type) || Short.class.equals(type)) {
            buffer.put(ValueFormat.Int16);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
            buffer.putShort((Short) value);
            buffer.order(ByteOrder.BIG_ENDIAN);
        } else if (int.class.equals(type) || Integer.class.equals(type)) {
            buffer.put(ValueFormat.Int32);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
            buffer.putInt((Integer) value);
            buffer.order(ByteOrder.BIG_ENDIAN);
        } else if (long.class.equals(type) || Long.class.equals(type)) {
            buffer.put(ValueFormat.Int64);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
            buffer.putLong((Long) value);
            buffer.order(ByteOrder.BIG_ENDIAN);
        } else if (Date.class.equals(type)) {
            buffer.put(ValueFormat.Date);
            buffer.order(ByteOrder.LITTLE_ENDIAN);
            buffer.putLong(((Date) value).getTime());
            buffer.order(ByteOrder.BIG_ENDIAN);
        } else {
            buffer.put(ValueFormat.CountedString);
            writeCountedString(buffer, (String) value);
        }
    }
wsky commented 11 years ago

must fix at next releas

wsky commented 11 years ago

must support version for compatible

wsky commented 11 years ago

61