public class ByteArrayEncoder extends MessageToMessageEncoder<byte[],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(); ... }
ChannelHandler.Sharable| Constructor and Description |
|---|
ByteArrayEncoder() |
| Modifier and Type | Method and Description |
|---|---|
ByteBuf |
encode(ChannelHandlerContext ctx,
byte[] msg) |
boolean |
isEncodable(Object msg)
Returns
true if and only if the specified message can be encoded by this encoder. |
MessageBuf<byte[]> |
newOutboundBuffer(ChannelHandlerContext ctx) |
flushafterAdd, afterRemove, beforeAdd, beforeRemove, bind, close, connect, deregister, disconnect, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbind, close, connect, deregister, disconnectafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught, userEventTriggeredpublic MessageBuf<byte[]> newOutboundBuffer(ChannelHandlerContext ctx) throws Exception
newOutboundBuffer in interface ChannelOutboundHandlernewOutboundBuffer in interface ChannelOutboundMessageHandler<byte[]>newOutboundBuffer in class ChannelOutboundMessageHandlerAdapter<byte[]>Exceptionpublic boolean isEncodable(Object msg) throws Exception
MessageToMessageEncodertrue if and only if the specified message can be encoded by this encoder.isEncodable in class MessageToMessageEncoder<byte[],ByteBuf>msg - the messageExceptionpublic ByteBuf encode(ChannelHandlerContext ctx, byte[] msg) throws Exception
encode in class MessageToMessageEncoder<byte[],ByteBuf>ExceptionCopyright © 2008-2012 The Netty Project. All Rights Reserved.