### Question:
ConnectionId { public static void write( final Optional<ConnectionId> first, final Optional<ConnectionId> second, final ByteBuf bb) { final int dcil = first.map(id -> id.getLength() - 3).orElse(0); final int scil = second.map(id -> id.getLength() - 3).orElse(0); final int cil = (dcil << 4 | scil) & 0xFF; bb.writeByte(cil); first.ifPresent(c -> c.write(bb)); second.ifPresent(c -> c.write(bb)); } ConnectionId(final byte[] id); static ConnectionId random(); static ConnectionId read(final int length, final ByteBuf bb); static Optional<ConnectionId> readOptional(final int length, final ByteBuf bb); static Pair<Optional<ConnectionId>, Optional<ConnectionId>> readPair(final ByteBuf bb); static int lastLength(final int cil); static void write(
      final Optional<ConnectionId> first, final Optional<ConnectionId> second, final ByteBuf bb); void write(final ByteBuf bb); int getLength(); byte[] asBytes(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); static final int LENGTH; }### Answer:
@Test public void writeIds() { final byte[] b16 = new byte[16]; final ConnectionId id16 = new ConnectionId(b16); final byte[] b18 = new byte[18]; Arrays.fill(b18, (byte) 1); final ConnectionId id18 = new ConnectionId(b18); final ByteBuf bb = Unpooled.buffer(); ConnectionId.write(of(id16), of(id18), bb); assertEquals(0xdf, bb.readByte() & 0xFF); final byte[] a16 = new byte[16]; bb.readBytes(a16); assertArrayEquals(b16, a16); final byte[] a18 = new byte[18]; bb.readBytes(a18); assertArrayEquals(b18, a18); }