- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<Buffer>
-
- io.netty5.handler.codec.bytes.ByteArrayDecoder
-
- All Implemented Interfaces:
ChannelHandler
public class ByteArrayDecoder extends MessageToMessageDecoder<Buffer>
Decodes a receivedBufferinto an array of bytes. A typical setup for TCP/IP would be:
and then you can use an array of bytes instead of aChannelPipelinepipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4)); pipeline.addLast("bytesDecoder", newByteArrayDecoder()); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("bytesEncoder", newByteArrayEncoder());Bufferas a message:void channelRead(
ChannelHandlerContextctx, byte[] bytes) { ... }
-
-
Constructor Summary
Constructors Constructor Description ByteArrayDecoder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecode(ChannelHandlerContext ctx, Buffer msg)Decode from one message to another.-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead, decodeAndClose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Method Detail
-
decode
protected void decode(ChannelHandlerContext ctx, Buffer msg) throws Exception
Description copied from class:MessageToMessageDecoderDecode from one message to another. This method will be called for each written message that can be handled by this decoder.The message will be disposed of after this call.
Subclasses that wish to sometimes pass messages through, should instead override the
MessageToMessageDecoder.decodeAndClose(ChannelHandlerContext, Object)method.- Overrides:
decodein classMessageToMessageDecoder<Buffer>- Parameters:
ctx- theChannelHandlerContextwhich thisMessageToMessageDecoderbelongs tomsg- the message to decode to another one- Throws:
Exception- is thrown if an error occurs
-
-