Class MessageToByteEncoder<I>

java.lang.Object
All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler
Direct Known Subclasses:
ByteToMessageCodec.Encoder, Bzip2Encoder, CompatibleObjectEncoder, FastLzFrameEncoder, HAProxyMessageEncoder, ObjectEncoder, SnappyFrameEncoder, Socks4ClientEncoder, Socks4ServerEncoder, Socks5ClientEncoder, Socks5ServerEncoder, SocksMessageEncoder, TcpDnsQueryEncoder, ZlibEncoder

public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdapter
ChannelOutboundHandlerAdapter which encodes message in a stream-like fashion from one message to an ByteBuf. Example implementation which encodes Integers to a ByteBuf.
    public class IntegerEncoder extends MessageToByteEncoder<Integer> {
        @Override
        public void encode(ChannelHandlerContext ctx, Integer msg, ByteBuf out)
                throws Exception {
            out.writeInt(msg);
        }
    }
  • Field Details

    • matcher

      private final TypeParameterMatcher matcher
    • preferDirect

      private final boolean preferDirect
  • Constructor Details

    • MessageToByteEncoder

      protected MessageToByteEncoder()
      see MessageToByteEncoder(boolean) with true as boolean parameter.
    • MessageToByteEncoder

      protected MessageToByteEncoder(java.lang.Class<? extends I> outboundMessageType)
      see MessageToByteEncoder(Class, boolean) with true as boolean value.
    • MessageToByteEncoder

      protected MessageToByteEncoder(boolean preferDirect)
      Create a new instance which will try to detect the types to match out of the type parameter of the class.
      Parameters:
      preferDirect - true if a direct ByteBuf should be tried to be used as target for the encoded messages. If false is used it will allocate a heap ByteBuf, which is backed by an byte array.
    • MessageToByteEncoder

      protected MessageToByteEncoder(java.lang.Class<? extends I> outboundMessageType, boolean preferDirect)
      Create a new instance
      Parameters:
      outboundMessageType - The type of messages to match
      preferDirect - true if a direct ByteBuf should be tried to be used as target for the encoded messages. If false is used it will allocate a heap ByteBuf, which is backed by an byte array.
  • Method Details