public class JsonObjectDecoder extends ByteToMessageDecoder
ChannelPipeline 。
这个类不做任何真正的解析或验证。
如果字节序列包含匹配数量的开始和结束大括号/括号,则该字节序列被视为JSON对象/数组。
这取决于随后的ChannelHandler将JSON文本解析为更可用的形式,即POJO。
ByteToMessageDecoder.CumulatorChannelHandler.SharableCOMPOSITE_CUMULATOR, MERGE_CUMULATOR| Constructor and Description |
|---|
JsonObjectDecoder() |
JsonObjectDecoder(boolean streamArrayElements) |
JsonObjectDecoder(int maxObjectLength) |
JsonObjectDecoder(int maxObjectLength, boolean streamArrayElements) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
解码从一个 ByteBuf到另一个。
|
protected ByteBuf |
extractObject(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length)
如果要过滤通过管道传递的json对象/数组,则覆盖此方法。
|
actualReadableBytes, 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 JsonObjectDecoder()
public JsonObjectDecoder(int maxObjectLength)
public JsonObjectDecoder(boolean streamArrayElements)
public JsonObjectDecoder(int maxObjectLength,
boolean streamArrayElements)
maxObjectLength - JSON对象/数组可能使用的最大字节数(包括大括号和全部)。
超过此长度的对象被丢弃,并抛出TooLongFrameException 。
streamArrayElements - 如果设置为true,并且“顶层”JSON对象是一个数组,则每个条目都会在完全接收后立即通过管道单独传递,从而允许具有“无限”多个元素的数组。
protected void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
ByteToMessageDecoder
decode在课程
ByteToMessageDecoder
ctx - ByteToMessageDecoder属于的ChannelHandlerContext
in - 从中读取数据的ByteBuf
out - 应该添加解码消息的
List
java.lang.Exception - 发生错误时抛出
protected ByteBuf extractObject(ChannelHandlerContext ctx, ByteBuf buffer, int index, int length)
Copyright © 2008–2018 The Netty Project. All rights reserved.