add FarPointer.set and WirePointer.setOffsetAndKind. unit tests pass
This commit is contained in:
parent
58417744ff
commit
bf7bcaa56f
5 changed files with 18 additions and 3 deletions
|
@ -18,7 +18,13 @@ class EncodingSuite extends FunSuite {
|
||||||
val message = new MessageBuilder(5, BuilderArena.AllocationStrategy.FIXED_SIZE);
|
val message = new MessageBuilder(5, BuilderArena.AllocationStrategy.FIXED_SIZE);
|
||||||
val allTypes = message.initRoot(TestAllTypes.Builder.factory);
|
val allTypes = message.initRoot(TestAllTypes.Builder.factory);
|
||||||
TestUtil.initTestMessage(allTypes);
|
TestUtil.initTestMessage(allTypes);
|
||||||
//TestUtil.checkTestMessage(allTypes);
|
|
||||||
|
TestUtil.checkTestMessage(allTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to debug, do this:
|
||||||
|
//Serialize.writeMessage((new java.io.FileOutputStream("/Users/dwrensha/Desktop/test.dat")).getChannel(),
|
||||||
|
// message);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ object TestUtil {
|
||||||
builder.setTextField(new Text.Reader("foo"));
|
builder.setTextField(new Text.Reader("foo"));
|
||||||
// builder.setDataField(data("bar"));
|
// builder.setDataField(data("bar"));
|
||||||
{
|
{
|
||||||
|
|
||||||
val subBuilder = builder.initStructField();
|
val subBuilder = builder.initStructField();
|
||||||
subBuilder.setVoidField(org.capnproto.Void.VOID);
|
subBuilder.setVoidField(org.capnproto.Void.VOID);
|
||||||
subBuilder.setBoolField(true);
|
subBuilder.setBoolField(true);
|
||||||
|
@ -44,7 +45,6 @@ object TestUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setEnumField(TestEnum.CORGE);
|
builder.setEnumField(TestEnum.CORGE);
|
||||||
|
|
||||||
builder.initVoidList(6);
|
builder.initVoidList(6);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,9 @@ final class FarPointer {
|
||||||
public static void setSegmentId(ByteBuffer buffer, int offset, int segmentId) {
|
public static void setSegmentId(ByteBuffer buffer, int offset, int segmentId) {
|
||||||
buffer.putInt(8 * offset + 4, segmentId);
|
buffer.putInt(8 * offset + 4, segmentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void set(ByteBuffer buffer, int offset, boolean isDoubleFar, int pos) {
|
||||||
|
int idf = isDoubleFar ? 1 : 0;
|
||||||
|
WirePointer.setOffsetAndKind(buffer, offset, (pos << 3) | (idf << 2) | WirePointer.FAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ final class WireHelpers {
|
||||||
|
|
||||||
//# Set up the original pointer to be a far pointer to
|
//# Set up the original pointer to be a far pointer to
|
||||||
//# the new segment.
|
//# the new segment.
|
||||||
WirePointer.setKindAndTarget(segment.buffer, refOffset, WirePointer.FAR, allocation.offset);
|
FarPointer.set(segment.buffer, refOffset, false, allocation.offset);
|
||||||
FarPointer.setSegmentId(segment.buffer, refOffset, allocation.segment.id);
|
FarPointer.setSegmentId(segment.buffer, refOffset, allocation.segment.id);
|
||||||
|
|
||||||
//# Initialize the landing pad to indicate that the
|
//# Initialize the landing pad to indicate that the
|
||||||
|
|
|
@ -29,6 +29,10 @@ final class WirePointer {
|
||||||
(((targetOffset - offset) - 1) << 2) | kind);
|
(((targetOffset - offset) - 1) << 2) | kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setOffsetAndKind(ByteBuffer buffer, int offset, int offsetAndKind) {
|
||||||
|
buffer.putInt(offset * 8, offsetAndKind);
|
||||||
|
}
|
||||||
|
|
||||||
public static int inlineCompositeListElementCount(long wirePointer) {
|
public static int inlineCompositeListElementCount(long wirePointer) {
|
||||||
return offsetAndKind(wirePointer) >>> 2;
|
return offsetAndKind(wirePointer) >>> 2;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue