BunchedTupleSerializer implements BunchedSerializer<Tuple, Tuple> { @Nonnull @Override public byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple, Tuple>> entries) { if (entries.isEmpty()) { throw new BunchedSerializationException("cannot serialize empty entry list"); } List<byte[]> serializedEntries = new ArrayList<>(1 + entries.size()); serializedEntries.add(PREFIX); if (!entries.isEmpty()) { Iterator<Map.Entry<Tuple, Tuple>> iterator = entries.iterator(); Map.Entry<Tuple, Tuple> firstEntry = iterator.next(); serializedEntries.add(Tuple.from(firstEntry.getValue()).pack()); while (iterator.hasNext()) { Map.Entry<Tuple, Tuple> entry = iterator.next(); serializedEntries.add(serializeEntry(entry)); } } return ByteArrayUtil.join(null, serializedEntries); } private  BunchedTupleSerializer(); static BunchedTupleSerializer instance(); @Nonnull @Override byte[] serializeKey(@Nonnull Tuple key); @Nonnull @Override byte[] serializeEntry(@Nonnull Tuple key, @Nonnull Tuple value); @Nonnull @Override byte[] serializeEntries(@Nonnull List<Map.Entry<Tuple, Tuple>> entries); @Nonnull @Override Tuple deserializeKey(@Nonnull byte[] data, int offset, int length); @Nonnull @Override List<Map.Entry<Tuple, Tuple>> deserializeEntries(@Nonnull Tuple key, @Nonnull byte[] data); @Override boolean canAppend();  }
@Test public void serializeEntries() { List<Map.Entry<Tuple,Tuple>> entries = TEST_TUPLES.stream() .map(t -> new AbstractMap.SimpleImmutableEntry<>(t, t)) .collect(Collectors.toList()); List<Map.Entry<Tuple,Tuple>> deserializedEntries = serializer.deserializeEntries(TEST_TUPLES.get(0), serializer.serializeEntries(entries)); assertEquals(entries, deserializedEntries); }
@Test public void serializeEmptyList() { assertThrows(BunchedSerializationException.class, () -> serializer.serializeEntries(Collections.emptyList())); }