fix ByteChannelMessageReader for multi-segment messages

This commit is contained in:
David Renshaw 2014-09-05 11:43:46 -04:00
parent 45f3dc4d23
commit 3272f8902b
3 changed files with 7 additions and 12 deletions

View file

@ -62,20 +62,18 @@ public final class ByteChannelMessageReader {
ByteBuffer[] segmentSlices = new ByteBuffer[segmentCount];
segmentSlices[0] = ByteBuffer.wrap(allSegments.array(),
0,
segment0Size * Constants.BYTES_PER_WORD);
allSegments.rewind();
segmentSlices[0] = allSegments.slice();
segmentSlices[0].limit(segment0Size * Constants.BYTES_PER_WORD);
segmentSlices[0].order(ByteOrder.LITTLE_ENDIAN);
segmentSlices[0].mark();
int offset = segment0Size;
for (int ii = 1; ii < segmentCount; ++ii) {
segmentSlices[ii] = ByteBuffer.wrap(allSegments.array(),
offset * Constants.BYTES_PER_WORD,
moreSizes.get(ii - 1) * Constants.BYTES_PER_WORD);
allSegments.position(offset * Constants.BYTES_PER_WORD);
segmentSlices[ii] = allSegments.slice();
segmentSlices[ii].limit(moreSizes.get(ii - 1) * Constants.BYTES_PER_WORD);
segmentSlices[ii].order(ByteOrder.LITTLE_ENDIAN);
segmentSlices[ii].mark();
offset += moreSizes.get(ii - 1);
}

View file

@ -4,9 +4,7 @@ import java.nio.ByteBuffer;
public class SegmentReader {
// invariant: buffer's mark is at its beginning.
final ByteBuffer buffer;
final Arena arena;
public SegmentReader(ByteBuffer buffer, Arena arena) {

View file

@ -337,7 +337,6 @@ final class WireHelpers {
int nestingLimit) {
// TODO error handling. is_null
if (nestingLimit <= 0) {
throw new DecodeException("Message is too deeply nested or contains cycles.");
}
@ -369,6 +368,7 @@ final class WireHelpers {
int refOffset,
byte expectedElementSize,
int nestingLimit) {
long ref = WirePointer.get(segment.buffer, refOffset);
if (WirePointer.isNull(ref)) {
@ -413,7 +413,6 @@ final class WireHelpers {
//# lists can also be interpreted as struct lists. We
//# need to compute the data size and pointer count for
//# such structs.
int dataSize = FieldSize.dataBitsPerElement(ListPointer.elementSize(resolved.ref));
int pointerCount = FieldSize.pointersPerElement(ListPointer.elementSize(resolved.ref));
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;