@Test public void decodePayload_shouldRejectEmptyMessages() { final ByteBuf input = Utils.emptyBuf(); RpcByteBufDecoder<StatusMessage> decoder = encoding.createDecoder(StatusMessage.class); assertThatThrownBy( () -> { decoder.decodeOneMessage(input); decoder.complete(); }) .isInstanceOf(MessageTruncatedException.class); input.release(); assertThat(input.refCnt()).isEqualTo(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();  }