public class MarshallingDecoder extends LengthFieldBasedFrameDecoder
MarshallingEncoder
.
A LengthFieldBasedFrameDecoder
which use an Unmarshaller
to read the Object out
of the ByteBuf
.Constructor and Description |
---|
MarshallingDecoder(UnmarshallerProvider provider)
Creates a new decoder whose maximum object size is
1048576
bytes. |
MarshallingDecoder(UnmarshallerProvider provider,
int maxObjectSize)
Creates a new decoder with the specified maximum object size.
|
Modifier and Type | Method and Description |
---|---|
Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in) |
protected io.netty.buffer.ByteBuf |
extractFrame(io.netty.buffer.ByteBuf buffer,
int index,
int length)
Extract the sub-region of the specified buffer.
|
beforeAdd, callDecode, channelInactive, decodeLast, inboundBufferUpdated, newInboundBuffer, replace
afterAdd, afterRemove, beforeRemove, channelActive, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public MarshallingDecoder(UnmarshallerProvider provider)
1048576
bytes. If the size of the received object is greater than
1048576
bytes, a StreamCorruptedException
will be
raised.public MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize)
maxObjectSize
- the maximum byte length of the serialized object.
if the length of the received object is greater
than this value, TooLongFrameException
will be raised.public Object decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in) throws Exception
decode
in class LengthFieldBasedFrameDecoder
Exception
protected io.netty.buffer.ByteBuf extractFrame(io.netty.buffer.ByteBuf buffer, int index, int length)
LengthFieldBasedFrameDecoder
#decode(ChannelInboundHandlerContext, ByteBuf)
for each
frame. The default implementation returns a copy of the sub-region.
For example, you could override this method to use an alternative
ByteBufFactory
.
If you are sure that the frame and its content are not accessed after
the current #decode(ChannelInboundHandlerContext, ByteBuf)
call returns, you can even avoid memory copy by returning the sliced
sub-region (i.e. return buffer.slice(index, length)).
It's often useful when you convert the extracted frame into an object.
Refer to the source code of ObjectDecoder
to see how this method
is overridden to avoid memory copy.
extractFrame
in class LengthFieldBasedFrameDecoder
Copyright © 2008-2012 The Netty Project. All Rights Reserved.