ByteArrayAdapter extends TypeAdapter<byte[]> { @Override public byte[] deserialize(byte[] buffer, int bufferPosition) { int length = Serialization.readInt(buffer, bufferPosition); return Serialization.subArray(buffer, bufferPosition + SIZE_OF_INT, bufferPosition + SIZE_OF_INT + length); } ByteArrayAdapter(); @Override byte[] serialize(byte[] data); @Override byte[] deserialize(byte[] buffer, int bufferPosition); @Override int getSerializedSize(byte[] value);  }
@Test public void testDecodeEmptyArray() { byte[] buffer = {0, 0, 0, 0}; byte[] expected = {}; assertArrayEquals(expected, adapter.deserialize(buffer, 0)); }
@Test public void testDecode() { byte[] array = {0, 0, 0, 7, 1, 2, 3, 4, 0x7F, (byte) 0x80, (byte) 0xFF}; byte[] expected = {1, 2, 3, 4, 0x7F, (byte) 0x80, (byte) 0xFF}; assertArrayEquals(expected, adapter.deserialize(array, 0)); }