public class ByteArrayDecoder extends MessageToMessageDecoder<io.netty.buffer.ByteBuf,byte[]>
ByteBuf
into an array of bytes.
A typical setup for TCP/IP would be:
and then you can use an array of bytes instead of aChannelPipeline
pipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLengthFieldBasedFrameDecoder
(1048576, 0, 4, 0, 4)); pipeline.addLast("bytesDecoder", newByteArrayDecoder
()); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender
(4)); pipeline.addLast("bytesEncoder", newByteArrayEncoder
());
ByteBuf
as a message:
void messageReceived(ChannelHandlerContext
ctx,MessageEvent
e) { byte[] bytes = (byte[]) e.getMessage(); ... }
Constructor and Description |
---|
ByteArrayDecoder() |
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg) |
inboundBufferUpdated, isDecodable, newInboundBuffer
afterAdd, afterRemove, beforeAdd, beforeRemove, channelActive, channelInactive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public byte[] decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg) throws Exception
decode
in class MessageToMessageDecoder<io.netty.buffer.ByteBuf,byte[]>
Exception
Copyright © 2008-2012 The Netty Project. All Rights Reserved.