public class ByteArrayEncoder extends MessageToMessageEncoder<byte[],io.netty.buffer.ByteBuf>
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(ChannelHandlerContextctx,MessageEvente) { byte[] bytes = (byte[]) e.getMessage(); ... }
| Constructor and Description |
|---|
ByteArrayEncoder() |
| Modifier and Type | Method and Description |
|---|---|
io.netty.buffer.ByteBuf |
encode(io.netty.channel.ChannelHandlerContext ctx,
byte[] msg) |
io.netty.buffer.MessageBuf<byte[]> |
newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
flush, isEncodableafterAdd, afterRemove, beforeAdd, beforeRemove, bind, close, connect, deregister, disconnect, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic io.netty.buffer.MessageBuf<byte[]> newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
newOutboundBuffer in interface io.netty.channel.ChannelOutboundHandlernewOutboundBuffer in interface io.netty.channel.ChannelOutboundMessageHandler<byte[]>newOutboundBuffer in class io.netty.channel.ChannelOutboundMessageHandlerAdapter<byte[]>Exceptionpublic io.netty.buffer.ByteBuf encode(io.netty.channel.ChannelHandlerContext ctx,
byte[] msg)
throws Exception
encode in class MessageToMessageEncoder<byte[],io.netty.buffer.ByteBuf>ExceptionCopyright © 2008-2012 The Netty Project. All Rights Reserved.