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) |
boolean |
isDecodable(Object msg)
Returns
true if and only if the specified message can be decoded by this decoder. |
inboundBufferUpdated, newInboundBuffer
afterAdd, afterRemove, beforeAdd, beforeRemove, channelActive, channelInactive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public boolean isDecodable(Object msg) throws Exception
MessageToMessageDecoder
true
if and only if the specified message can be decoded by this decoder.isDecodable
in class MessageToMessageDecoder<io.netty.buffer.ByteBuf,byte[]>
msg
- the messageException
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.