### Question:
LengthPrefixedEncoding implements RpcEncoding { @Override @SuppressWarnings("unchecked") public <T> Bytes encodePayload(final T message) { if (message instanceof EmptyMessage) { return Bytes.EMPTY; } final RpcPayloadEncoder<T> payloadEncoder = payloadEncoders.getEncoder((Class<T>) message.getClass()); final Bytes payload = payloadEncoder.encode(message); if (payload.isEmpty()) { return payload; } return encodeMessageWithLength(payload); } LengthPrefixedEncoding(
      final String name, final RpcPayloadEncoders payloadEncoders, final Compressor compressor); @Override @SuppressWarnings("unchecked") Bytes encodePayload(final T message); @Override RpcByteBufDecoder<T> createDecoder(Class<T> payloadType); @Override String getName();  }### Answer:
@Test public void encodePayload_shouldEncodeBlocksByRootRequest() { final Bytes encoded = encoding.encodePayload(new BeaconBlocksByRootRequestMessage(singletonList(Bytes32.ZERO))); assertThat(encoded).isEqualTo(Bytes.wrap(Bytes.fromHexString("0x20"), Bytes32.ZERO)); }
@Test void encodePayload_shouldReturnZeroBytesForEmptyMessages() { final Bytes result = encoding.encodePayload(new EmptyMessage()); assertThat(result).isEqualTo(Bytes.EMPTY); }