setStructPointer, setListPointer. still buggy
This commit is contained in:
parent
1d69d9a7ab
commit
1db37b741d
3 changed files with 81 additions and 3 deletions
|
@ -43,6 +43,22 @@ class EncodingSuite extends FunSuite {
|
|||
TestUtil.checkTestMessage(allTypes.asReader());
|
||||
}
|
||||
|
||||
test("Setters") {
|
||||
val message = new MessageBuilder();
|
||||
val allTypes = message.initRoot(TestAllTypes.factory);
|
||||
TestUtil.initTestMessage(allTypes);
|
||||
|
||||
val message2 = new MessageBuilder();
|
||||
val allTypes2 = message.initRoot(TestAllTypes.factory);
|
||||
|
||||
//allTypes2.setStructField(allTypes.asReader());
|
||||
|
||||
// ...
|
||||
//TestUtil.checkTestMessage(allTypes);
|
||||
//TestUtil.checkTestMessage(allTypes.asReader());
|
||||
|
||||
}
|
||||
|
||||
test("Defaults") {
|
||||
val message = new MessageBuilder();
|
||||
val defaults = message.initRoot(TestDefaults.factory);
|
||||
|
|
|
@ -41,4 +41,9 @@ final class StructPointer{
|
|||
buffer.putShort(8 * offset + 4, size.data);
|
||||
buffer.putShort(8 * offset + 6, size.pointers);
|
||||
}
|
||||
|
||||
public static void set(ByteBuffer buffer, int offset, short dataSize, short pointerCount) {
|
||||
buffer.putShort(8 * offset + 4, dataSize);
|
||||
buffer.putShort(8 * offset + 6, pointerCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -503,6 +503,25 @@ final class WireHelpers {
|
|||
}
|
||||
|
||||
static SegmentBuilder setStructPointer(SegmentBuilder segment, int refOffset, StructReader value) {
|
||||
short dataSize = (short)roundBitsUpToWords(value.dataSize);
|
||||
int totalSize = dataSize + value.pointerCount * Constants.POINTER_SIZE_IN_WORDS;
|
||||
|
||||
AllocateResult allocation = allocate(refOffset, segment, totalSize, WirePointer.STRUCT);
|
||||
StructPointer.set(allocation.segment.buffer, allocation.ptr,
|
||||
dataSize, value.pointerCount);
|
||||
|
||||
if (value.dataSize == 1) {
|
||||
throw new Error("single bit case not handled");
|
||||
} else {
|
||||
memcpy(allocation.segment.buffer, allocation.refOffset * Constants.BYTES_PER_WORD,
|
||||
value.segment.buffer, value.data, value.dataSize / Constants.BITS_PER_BYTE);
|
||||
}
|
||||
|
||||
int pointerSection = allocation.ptr + dataSize;
|
||||
for (int i = 0; i < value.pointerCount; ++i) {
|
||||
copyPointer(allocation.segment, pointerSection + i, value.segment, value.pointers + i,
|
||||
value.nestingLimit);
|
||||
}
|
||||
throw new Error("setStructPointer is unimplemented");
|
||||
};
|
||||
|
||||
|
@ -535,13 +554,51 @@ final class WireHelpers {
|
|||
}
|
||||
|
||||
ListPointer.set(allocation.segment.buffer, allocation.refOffset, elementSize, value.elementCount);
|
||||
// memcpy
|
||||
memcpy(allocation.segment.buffer, allocation.ptr * Constants.BYTES_PER_WORD,
|
||||
value.segment.buffer, value.ptr * 8, totalSize * Constants.BYTES_PER_WORD);
|
||||
}
|
||||
return allocation.segment;
|
||||
} else {
|
||||
//# List of structs.
|
||||
AllocateResult allocation = allocate(refOffset, segment, totalSize + Constants.POINTER_SIZE_IN_WORDS, WirePointer.LIST);
|
||||
ListPointer.setInlineComposite(allocation.segment.buffer, allocation.refOffset, totalSize);
|
||||
|
||||
short dataSize = (short)roundBitsUpToWords(value.structDataSize);
|
||||
short pointerCount = value.structPointerCount;
|
||||
|
||||
WirePointer.setKindAndInlineCompositeListElementCount(allocation.segment.buffer, allocation.ptr,
|
||||
WirePointer.STRUCT, value.elementCount);
|
||||
StructPointer.set(allocation.segment.buffer, allocation.ptr,
|
||||
dataSize, pointerCount);
|
||||
|
||||
int dstOffset = allocation.ptr + Constants.POINTER_SIZE_IN_WORDS;
|
||||
int srcOffset = value.ptr;
|
||||
|
||||
for (int i = 0; i < value.elementCount; ++i) {
|
||||
memcpy(allocation.segment.buffer, dstOffset * Constants.BYTES_PER_WORD,
|
||||
value.segment.buffer, srcOffset * Constants.BYTES_PER_WORD,
|
||||
value.structDataSize / Constants.BITS_PER_BYTE);
|
||||
dstOffset += dataSize;
|
||||
srcOffset += dataSize;
|
||||
|
||||
for (int j = 0; j < pointerCount; ++j) {
|
||||
copyPointer(allocation.segment, dstOffset, value.segment, srcOffset, value.nestingLimit);
|
||||
dstOffset += Constants.POINTER_SIZE_IN_WORDS;
|
||||
srcOffset += Constants.POINTER_SIZE_IN_WORDS;
|
||||
}
|
||||
}
|
||||
return allocation.segment;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("setListPointer is unimplemented");
|
||||
static void memcpy(ByteBuffer dstBuffer, int dstByteOffset, ByteBuffer srcBuffer, int srcByteOffset, int length) {
|
||||
ByteBuffer dstDup = dstBuffer.duplicate();
|
||||
dstDup.position(dstByteOffset);
|
||||
dstDup.limit(length);
|
||||
ByteBuffer srcDup = srcBuffer.duplicate();
|
||||
srcDup.position(srcByteOffset);
|
||||
srcDup.limit(length);
|
||||
dstDup.put(srcDup);
|
||||
}
|
||||
|
||||
static SegmentBuilder copyPointer(SegmentBuilder dstSegment, int dstOffset,
|
||||
|
|
Loading…
Reference in a new issue