private static ByteBuffer serialize(WritableSupplier<ColumnarInts> writableSupplier) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize()); WritableByteChannel channel = new WritableByteChannel() { @Override public int write(ByteBuffer src) { int size = src.remaining(); buffer.put(src); return size; } @Override public boolean isOpen() { return true; } @Override public void close() { } }; writableSupplier.writeTo(channel, null); buffer.rewind(); return buffer; }
private static ByteBuffer serialize(WritableSupplier<ColumnarMultiInts> writableSupplier) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect((int) writableSupplier.getSerializedSize()); WritableByteChannel channel = new WritableByteChannel() { @Override public int write(ByteBuffer src) { int size = src.remaining(); buffer.put(src); return size; } @Override public boolean isOpen() { return true; } @Override public void close() { } }; writableSupplier.writeTo(channel, null); buffer.rewind(); return buffer; }
@Test public void testSerde() throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); columnarMultiIntsSupplier.writeTo(Channels.newChannel(baos), null); final byte[] bytes = baos.toByteArray(); Assert.assertEquals(columnarMultiIntsSupplier.getSerializedSize(), bytes.length); WritableSupplier<ColumnarMultiInts> deserializedColumnarMultiInts = fromByteBuffer(ByteBuffer.wrap(bytes)); assertSame(vals, deserializedColumnarMultiInts.get()); }