oh right, endianness
This commit is contained in:
parent
95d0898c3f
commit
710c03f7f9
4 changed files with 18 additions and 5 deletions
|
@ -5,7 +5,6 @@ import org.scalatest.FunSuite
|
||||||
import org.scalatest.Matchers._;
|
import org.scalatest.Matchers._;
|
||||||
|
|
||||||
class EncodingSuite extends FunSuite {
|
class EncodingSuite extends FunSuite {
|
||||||
|
|
||||||
test("AllTypes") {
|
test("AllTypes") {
|
||||||
val message = new MessageBuilder();
|
val message = new MessageBuilder();
|
||||||
val allTypes = message.initRoot(TestAllTypes.factory);
|
val allTypes = message.initRoot(TestAllTypes.factory);
|
||||||
|
@ -142,8 +141,19 @@ class EncodingSuite extends FunSuite {
|
||||||
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
|
(TestConstants.ENUM_CONST) should equal (TestEnum.CORGE);
|
||||||
{
|
{
|
||||||
val subReader = TestConstants.STRUCT_CONST;
|
val subReader = TestConstants.STRUCT_CONST;
|
||||||
//subReader.getBoolField() should equal (true);
|
subReader.getBoolField() should equal (true);
|
||||||
//subReader.getInt8Field() should equal (-12);
|
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");
|
||||||
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,6 +311,7 @@ struct TestConstants {
|
||||||
(textField = "x structlist 3")],
|
(textField = "x structlist 3")],
|
||||||
enumList = [qux, bar, grault]
|
enumList = [qux, bar, grault]
|
||||||
# interfaceList can't have a default
|
# interfaceList can't have a default
|
||||||
|
|
||||||
);
|
);
|
||||||
# ...
|
# ...
|
||||||
const enumConst :TestEnum = corge;
|
const enumConst :TestEnum = corge;
|
||||||
|
|
|
@ -3,7 +3,9 @@ package org.capnproto;
|
||||||
public final class GeneratedClassSupport {
|
public final class GeneratedClassSupport {
|
||||||
public static SegmentReader decodeRawBytes(String s) {
|
public static SegmentReader decodeRawBytes(String s) {
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
throw new Error("could not decode raw bytes from String");
|
throw new Error("could not decode raw bytes from String");
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,13 +414,13 @@ final class WireHelpers {
|
||||||
static StructReader readStructPointer(SegmentReader segment,
|
static StructReader readStructPointer(SegmentReader segment,
|
||||||
int refOffset,
|
int refOffset,
|
||||||
int nestingLimit) {
|
int nestingLimit) {
|
||||||
|
|
||||||
// TODO error handling. is_null
|
// TODO error handling. is_null
|
||||||
if (nestingLimit <= 0) {
|
if (nestingLimit <= 0) {
|
||||||
throw new DecodeException("Message is too deeply nested or contains cycles.");
|
throw new DecodeException("Message is too deeply nested or contains cycles.");
|
||||||
}
|
}
|
||||||
|
|
||||||
long ref = WirePointer.get(segment.buffer, refOffset);
|
long ref = WirePointer.get(segment.buffer, refOffset);
|
||||||
|
|
||||||
int refTarget = WirePointer.target(refOffset, ref);
|
int refTarget = WirePointer.target(refOffset, ref);
|
||||||
FollowFarsResult resolved = followFars(ref, refTarget, segment);
|
FollowFarsResult resolved = followFars(ref, refTarget, segment);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue