@ChannelHandler.Sharable public class ByteArrayEncoder extends MessageToMessageEncoder<byte[]>
ByteBuf.
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());
ByteBuf
as a message:
void messageReceived(ChannelHandlerContext ctx, byte[] bytes) {
...
}
| Constructor and Description |
|---|
ByteArrayEncoder() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
encode(io.netty.channel.ChannelHandlerContext ctx,
byte[] msg,
io.netty.channel.MessageList<Object> out)
Encode from one message to an other.
|
acceptOutboundMessage, writebind, close, connect, deregister, disconnect, readexceptionCaught, handlerAdded, handlerRemovedprotected void encode(io.netty.channel.ChannelHandlerContext ctx,
byte[] msg,
io.netty.channel.MessageList<Object> out)
throws Exception
MessageToMessageEncoderMessageList has nothing
left or till this method returns null.encode in class MessageToMessageEncoder<byte[]>ctx - the ChannelHandlerContext which this MessageToMessageEncoder belongs tomsg - the message to encode to an other oneout - the MessageList into which the encoded msg should be added
needs to do some kind of aggragationException - is thrown if an error accourCopyright © 2008-2013 The Netty Project. All Rights Reserved.