@Test public void testPeekLength() { ByteBuffer out = ByteBuffer.allocate(1024 * 1024 * 128); int size = 127; List<ByteArray> input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 1, rawSerializer.peekLength(out)); size = 128; out.clear(); input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 2, rawSerializer.peekLength(out)); size = 255; out.clear(); input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 2, rawSerializer.peekLength(out)); size = 256; out.clear(); input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 3, rawSerializer.peekLength(out)); size = 1024 * 63; out.clear(); input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 3, rawSerializer.peekLength(out)); size = 1024 * 64; out.clear(); input = getValueList(size); rawSerializer.serialize(input, out); out.rewind(); assertEquals(size * 2 + 4, rawSerializer.peekLength(out)); }
@Override public int peekLength(ByteBuffer in) { int mark = in.position(); int len = 0; if (in.hasRemaining()) { int size = BytesUtil.readVInt(in); len = in.position() - mark; for (int i = 0; i < size; i++) { int length = BytesUtil.peekByteArrayLength(in); in.position(in.position() + length); len += length; } } in.position(mark); return len; }
RawSerializer extends DataTypeSerializer<List<ByteArray>> { @Override public int peekLength(ByteBuffer in) { int mark = in.position(); int len = 0; if (in.hasRemaining()) { int size = BytesUtil.readVInt(in); len = in.position() - mark; for (int i = 0; i < size; i++) { int length = BytesUtil.peekByteArrayLength(in); in.position(in.position() + length); len += length; } } in.position(mark); return len; } }
RawSerializer extends DataTypeSerializer<List<ByteArray>> { @Override public int peekLength(ByteBuffer in) { int mark = in.position(); int len = 0; if (in.hasRemaining()) { int size = BytesUtil.readVInt(in); len = in.position() - mark; for (int i = 0; i < size; i++) { int length = BytesUtil.peekByteArrayLength(in); in.position(in.position() + length); len += length; } } in.position(mark); return len; } RawSerializer(DataType dataType); }
RawSerializer extends DataTypeSerializer<List<ByteArray>> { @Override public int peekLength(ByteBuffer in) { int mark = in.position(); int len = 0; if (in.hasRemaining()) { int size = BytesUtil.readVInt(in); len = in.position() - mark; for (int i = 0; i < size; i++) { int length = BytesUtil.peekByteArrayLength(in); in.position(in.position() + length); len += length; } } in.position(mark); return len; } RawSerializer(DataType dataType); @Override int peekLength(ByteBuffer in); @Override int maxLength(); @Override int getStorageBytesEstimate(); @Override void serialize(List<ByteArray> values, ByteBuffer out); @Override List<ByteArray> deserialize(ByteBuffer in); }
RawSerializer extends DataTypeSerializer<List<ByteArray>> { @Override public int peekLength(ByteBuffer in) { int mark = in.position(); int len = 0; if (in.hasRemaining()) { int size = BytesUtil.readVInt(in); len = in.position() - mark; for (int i = 0; i < size; i++) { int length = BytesUtil.peekByteArrayLength(in); in.position(in.position() + length); len += length; } } in.position(mark); return len; } RawSerializer(DataType dataType); @Override int peekLength(ByteBuffer in); @Override int maxLength(); @Override int getStorageBytesEstimate(); @Override void serialize(List<ByteArray> values, ByteBuffer out); @Override List<ByteArray> deserialize(ByteBuffer in); static final int RAW_BUFFER_SIZE; }