TextIndexBunchedSerializer implements BunchedSerializer<Tuple, List<Integer>> { @Nonnull @Override public byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple, List<Integer>>> entries) { if (entries.isEmpty()) { throw new BunchedSerializationException("cannot serialize empty entry list"); } try { int size = PREFIX.length; List<byte[]> serializedKeys = new ArrayList<>(entries.size() - 1); int[] listSizes = new int[entries.size()]; for (int i = 0; i < entries.size(); i++) { Map.Entry<Tuple, List<Integer>> entry = entries.get(i); if (i != 0) { byte[] serializedKey = entry.getKey().pack(); size += getVarIntSize(serializedKey.length) + serializedKey.length; serializedKeys.add(serializedKey); } int listSize = getListSize(entry.getValue()); listSizes[i] = listSize; size += getVarIntSize(listSize) + listSize; } ByteBuffer buffer = ByteBuffer.allocate(size); buffer.put(PREFIX); for (int i = 0; i < entries.size(); i++) { if (i != 0) { byte[] key = serializedKeys.get(i - 1); serializeVarInt(buffer, key.length); buffer.put(key); } serializeList(buffer, entries.get(i).getValue(), listSizes[i]); } return buffer.array(); } catch (RuntimeException e) { throw new BunchedSerializationException("could not serialize entry list", e).setValue(entries); } } private  TextIndexBunchedSerializer(); static TextIndexBunchedSerializer instance(); @Nonnull @Override byte[] serializeKey(@Nonnull Tuple key); @Nonnull @Override byte[] serializeEntry(@Nonnull Tuple key, @Nonnull List<Integer> value); @Nonnull @Override byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple, List<Integer>>> entries); @Nonnull @Override Tuple deserializeKey(@Nonnull byte[] data, int offset, int length); @Nonnull @Override List<Map.Entry<Tuple, List<Integer>>> deserializeEntries(@Nonnull Tuple key, @Nonnull byte[] data); @Nonnull @Override List<Tuple> deserializeKeys(@Nonnull Tuple key, @Nonnull byte[] data); @Override boolean canAppend();  }
@Test public void example() { final List<Map.Entry<Tuple, List<Integer>>> entries = Arrays.asList( entryOf(Tuple.from(1066L), Arrays.asList(1, 3, 5, 8)), entryOf(Tuple.from(1415L), Arrays.asList(0, 600, 605)) ); final byte[] expectedBytes = new byte[]{0x20, 0x04, 0x01, 0x02, 0x02, 0x03, 0x03, 0x16, 0x05, (byte)0x87, 0x04, 0x00, (byte)0x84, 0x58, 0x05}; assertArrayEquals(expectedBytes, serializer.serializeEntries(entries)); }