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 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 |
---|
ByteArrayEncoder() |
Modifier and Type | Method and Description |
---|---|
io.netty.buffer.ByteBuf |
encode(io.netty.channel.ChannelHandlerContext ctx,
byte[] msg) |
boolean |
isEncodable(Object msg)
Returns
true if and only if the specified message can be encoded by this encoder. |
io.netty.buffer.MessageBuf<byte[]> |
newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
flush
afterAdd, afterRemove, beforeAdd, beforeRemove, bind, close, connect, deregister, disconnect, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public io.netty.buffer.MessageBuf<byte[]> newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) throws Exception
newOutboundBuffer
in interface io.netty.channel.ChannelOutboundHandler
newOutboundBuffer
in interface io.netty.channel.ChannelOutboundMessageHandler<byte[]>
newOutboundBuffer
in class io.netty.channel.ChannelOutboundMessageHandlerAdapter<byte[]>
Exception
public boolean isEncodable(Object msg) throws Exception
MessageToMessageEncoder
true
if and only if the specified message can be encoded by this encoder.isEncodable
in class MessageToMessageEncoder<byte[],io.netty.buffer.ByteBuf>
msg
- the messageException
public io.netty.buffer.ByteBuf encode(io.netty.channel.ChannelHandlerContext ctx, byte[] msg) throws Exception
encode
in class MessageToMessageEncoder<byte[],io.netty.buffer.ByteBuf>
Exception
Copyright © 2008-2012 The Netty Project. All Rights Reserved.