public class MarshallingDecoder extends LengthFieldBasedFrameDecoder
MarshallingEncoder一起使用。
一个LengthFieldBasedFrameDecoder其使用Unmarshaller读取对象出的ByteBuf 。
ByteToMessageDecoder.CumulatorChannelHandler.SharableCOMPOSITE_CUMULATOR, MERGE_CUMULATOR| Constructor and Description |
|---|
MarshallingDecoder(UnmarshallerProvider provider)
创建一个新的解码器,其最大对象大小为
1048576字节。
|
MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize)
用指定的最大对象大小创建一个新的解码器。
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
decode(ChannelHandlerContext ctx, ByteBuf in)
从 ByteBuf中创建一个框架并将其返回。
|
protected ByteBuf |
extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length)
提取指定缓冲区的子区域。
|
decode, getUnadjustedFrameLengthactualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredchannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtensureNotSharable, handlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAddedpublic MarshallingDecoder(UnmarshallerProvider provider)
1048576字节。
如果接收到的对象的大小大于1048576字节,则会引发StreamCorruptedException 。
public MarshallingDecoder(UnmarshallerProvider provider, int maxObjectSize)
maxObjectSize - 序列化对象的最大字节长度。
如果接收到的对象的长度大于此值,则会引发TooLongFrameException 。
protected java.lang.Object decode(ChannelHandlerContext ctx, ByteBuf in) throws java.lang.Exception
LengthFieldBasedFrameDecoder
ByteBuf中创建一个框架并将其返回。
decode在课程
LengthFieldBasedFrameDecoder
ctx - 这是ByteToMessageDecoder所属的ChannelHandlerContext
in - 从中读取数据的ByteBuf
ByteBuf表示帧或null 。
java.lang.Exception
protected ByteBuf extractFrame(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length)
LengthFieldBasedFrameDecoder
如果您确定在当前的LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext, ByteBuf)调用返回后没有访问框架及其内容,您甚至可以通过返回切片的子区域(即return buffer.slice(index, length) )来避免内存复制。 将提取的帧转换为对象时通常很有用。 请参阅源代码ObjectDecoder以了解如何覆盖此方法以避免内存复制。
extractFrame in class
LengthFieldBasedFrameDecoder
Copyright © 2008–2018 The Netty Project. All rights reserved.