oh right, endianness

This commit is contained in:
David Renshaw 2014-10-06 10:17:39 -04:00
parent 95d0898c3f
commit 710c03f7f9
4 changed files with 18 additions and 5 deletions

View file

@ -5,7 +5,6 @@ import org.scalatest.FunSuite
import org.scalatest.Matchers._;
class EncodingSuite extends FunSuite {
test("AllTypes") {
val message = new MessageBuilder();
val allTypes = message.initRoot(TestAllTypes.factory);
@ -142,8 +141,19 @@ class EncodingSuite extends FunSuite {
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
{
val subReader = TestConstants.STRUCT_CONST;
//subReader.getBoolField() should equal (true);
//subReader.getInt8Field() should equal (-12);
subReader.getBoolField() should equal (true);
subReader.getInt8Field() should equal (-12);
subReader.getInt16Field() should equal(3456);
subReader.getInt32Field() should equal (-78901234);
subReader.getInt64Field() should equal (56789012345678L);
subReader.getUInt8Field() should equal (90);
subReader.getUInt16Field should equal (1234);
subReader.getUInt32Field() should equal (56789012);
subReader.getUInt64Field() should equal (345678901234567890L);
subReader.getFloat32Field() should equal (-1.25e-10f);
subReader.getFloat64Field() should equal (345);
subReader.getTextField().toString() should equal ("baz");
// ...
}
}

View file

@ -311,6 +311,7 @@ struct TestConstants {
(textField = "x structlist 3")],
enumList = [qux, bar, grault]
# interfaceList can't have a default
);
# ...
const enumConst :TestEnum = corge;

View file

@ -3,7 +3,9 @@ package org.capnproto;
public final class GeneratedClassSupport {
public static SegmentReader decodeRawBytes(String s) {
try {
return new SegmentReader(java.nio.ByteBuffer.wrap(s.getBytes("ISO_8859-1")).asReadOnlyBuffer(), null);
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(s.getBytes("ISO_8859-1")).asReadOnlyBuffer();
buffer.order(java.nio.ByteOrder.LITTLE_ENDIAN);
return new SegmentReader(buffer, null);
} catch (Exception e) {
throw new Error("could not decode raw bytes from String");
}

View file

@ -414,13 +414,13 @@ final class WireHelpers {
static StructReader readStructPointer(SegmentReader segment,
int refOffset,
int nestingLimit) {
// TODO error handling. is_null
if (nestingLimit <= 0) {
throw new DecodeException("Message is too deeply nested or contains cycles.");
}
long ref = WirePointer.get(segment.buffer, refOffset);
int refTarget = WirePointer.target(refOffset, ref);
FollowFarsResult resolved = followFars(ref, refTarget, segment);