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