### Question:
Framer { @VisibleForTesting void frameMessage(final MessageData message, final ByteBuf buf) { final int frameSize = message.getSize() + LENGTH_MESSAGE_ID; final int pad = padding16(frameSize); final byte id = (byte) message.getCode(); final byte[] h = new byte[LENGTH_HEADER_DATA]; h[0] = (byte) ((frameSize >> 16) & 0xff); h[1] = (byte) ((frameSize >> 8) & 0xff); h[2] = (byte) (frameSize & 0xff); System.arraycopy(PROTOCOL_HEADER, 0, h, LENGTH_FRAME_SIZE, PROTOCOL_HEADER.length); Arrays.fill(h, LENGTH_FRAME_SIZE + PROTOCOL_HEADER.length, h.length - 1, (byte) 0x00); encryptor.processBytes(h, 0, LENGTH_HEADER_DATA, h, 0); byte[] hMac = Arrays.copyOf(secrets.getEgressMac(), LENGTH_MAC); macEncryptor.processBlock(hMac, 0, hMac, 0); hMac = secrets.updateEgress(xor(h, hMac)).getEgressMac(); hMac = Arrays.copyOf(hMac, LENGTH_MAC); buf.writeBytes(h).writeBytes(hMac); final MutableBytes f = MutableBytes.create(frameSize + pad); final Bytes bv = id == 0 ? RLP.NULL : RLP.encodeOne(Bytes.of(id)); assert bv.size() == 1; f.set(0, bv.get(0)); message.getData().copyTo(f, 1); encryptor.processBytes(f.toArrayUnsafe(), 0, f.size(), f.toArrayUnsafe(), 0); final byte[] fMacSeed = Arrays.copyOf(secrets.updateEgress(f.toArrayUnsafe()).getEgressMac(), LENGTH_MAC); byte[] fMac = new byte[16]; macEncryptor.processBlock(fMacSeed, 0, fMac, 0); fMac = Arrays.copyOf(secrets.updateEgress(xor(fMac, fMacSeed)).getEgressMac(), LENGTH_MAC); buf.writeBytes(f.toArrayUnsafe()).writeBytes(fMac); } Framer(final HandshakeSecrets secrets); void enableCompression(); void disableCompression(); synchronized MessageData deframe(final ByteBuf buf); synchronized void frame(final MessageData message, final ByteBuf output);  }### Answer:
@Test public void frameMessage() throws IOException { final JsonNode td = MAPPER.readTree(FramerTest.class.getResource("/peer1.json")); HandshakeSecrets secrets = secretsFrom(td, false); Framer framer = new Framer(secrets); final JsonNode messages = td.get("messages"); final List<MessageData> decrypted = stream(messages.spliterator(), false) .map(n -> decodeHexDump(n.get("data").asText())) .map(Unpooled::wrappedBuffer) .map(framer::deframe) .collect(toList()); secrets = secretsFrom(td, true); framer = new Framer(secrets); for (int i = 0; i < decrypted.size(); i++) { final ByteBuf b = Unpooled.buffer(); framer.frame(decrypted.get(i), b); final byte[] enc = new byte[b.readableBytes()]; b.readBytes(enc); final byte[] expected = decodeHexDump(messages.get(i).get("data").asText()); assertThat(expected).isEqualTo(enc); } }