Interface HttpDecoder<T>

Type Parameters:
T - the result type of being decoded
All Superinterfaces:
StreamDecoder<HttpData,T>
All Known Implementing Classes:
ArmeriaMessageDeframer

@UnstableApi public interface HttpDecoder<T> extends StreamDecoder<HttpData,T>
Decodes a stream of HttpObjects to N objects.

Follow the below steps to decode HTTP payload using HttpDecoder.

  1. Implement your decoding logic in HttpDecoder.
    
           > class FixedLengthDecoder implements HttpDecoder<String> {
           >     private final int length;
           >
           >     FixedLengthDecoder(int length) {
           >         this.length = length;
           >     }
           >
           >     @Override
           >     public void process(HttpDecoderInput in, HttpDecoderOutput<String> out) {
           >         int remaining = in.readableBytes();
           >         if (remaining < length) {
           >             // The input is not enough to process. Waiting for more data.
           >             return;
           >         }
           >
           >         do {
           >             // Read data from 'HttpDecoderInput' and
           >             // write the processed result to 'HttpDecoderOutput'.
           >             ByteBuf buf = in.readBytes(length);
           >             out.add(buf.toString(StandardCharsets.UTF_8));
           >             // Should release the returned 'ByteBuf'
           >             buf.release();
           >             remaining -= length;
           >         } while (remaining >= length);
           >     }
           > }
           
  2. Create a decoded StreamMessage using HttpMessage.decode(HttpDecoder) with the HttpDecoder instance.
    
           FixedLengthDecoder decoder = new FixedLengthDecoder(11);
           HttpRequest req = ...;
           StreamMessage<String> decoded = req.decode(decoder);
           
  3. Subscribe to the Publisher of the decoded data and connect to your business logic.
    
           import reactor.core.publisher.Flux;
           Flux.from(decoded).map(...); // Consume and manipulate the decoded data.