@Test public void decodePayload_shouldReturnErrorWhenPayloadTooShort() { final Bytes correctMessage = createValidStatusMessage(); final int truncatedSize = correctMessage.size() - 5; List<List<ByteBuf>> testByteBufSlices = Utils.generateTestSlices(correctMessage.slice(0, truncatedSize)); for (Iterable<ByteBuf> bufSlices : testByteBufSlices) { RpcByteBufDecoder<StatusMessage> decoder = encoding.createDecoder(StatusMessage.class); List<ByteBuf> usedBufs = new ArrayList<>(); assertThatThrownBy( () -> { for (ByteBuf bufSlice : bufSlices) { assertThat(decoder.decodeOneMessage(bufSlice)).isEmpty(); bufSlice.release(); usedBufs.add(bufSlice); } decoder.complete(); }) .isInstanceOf(PayloadTruncatedException.class); assertThat(usedBufs).allMatch(b -> b.refCnt() == 0); } }
@Override public <T> RpcByteBufDecoder<T> createDecoder(Class<T> payloadType) { if (payloadType.equals(EmptyMessage.class)) { return getEmptyMessageDecoder(); } else { return new LengthPrefixedPayloadDecoder<>( payloadEncoders.getEncoder(payloadType), compressor); } }
LengthPrefixedEncoding implements RpcEncoding { @Override public <T> RpcByteBufDecoder<T> createDecoder(Class<T> payloadType) { if (payloadType.equals(EmptyMessage.class)) { return getEmptyMessageDecoder(); } else { return new LengthPrefixedPayloadDecoder<>( payloadEncoders.getEncoder(payloadType), compressor); } } }
LengthPrefixedEncoding implements RpcEncoding { @Override public <T> RpcByteBufDecoder<T> createDecoder(Class<T> payloadType) { if (payloadType.equals(EmptyMessage.class)) { return getEmptyMessageDecoder(); } else { return new LengthPrefixedPayloadDecoder<>( payloadEncoders.getEncoder(payloadType), compressor); } } LengthPrefixedEncoding(
      final String name, final RpcPayloadEncoders payloadEncoders, final Compressor compressor); }
LengthPrefixedEncoding implements RpcEncoding { @Override public <T> RpcByteBufDecoder<T> createDecoder(Class<T> payloadType) { if (payloadType.equals(EmptyMessage.class)) { return getEmptyMessageDecoder(); } else { return new LengthPrefixedPayloadDecoder<>( payloadEncoders.getEncoder(payloadType), compressor); } } 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(); }
LengthPrefixedEncoding implements RpcEncoding { @Override public <T> RpcByteBufDecoder<T> createDecoder(Class<T> payloadType) { if (payloadType.equals(EmptyMessage.class)) { return getEmptyMessageDecoder(); } else { return new LengthPrefixedPayloadDecoder<>( payloadEncoders.getEncoder(payloadType), compressor); } } 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();  }