`
scliu0718
  • 浏览: 51479 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
FrameDecoder Netty笔记:FrameDecoder
  if (cumulation == null) {
            // the cumulation buffer is not created yet so just pass the input to callDecode(...) method 第一次的时候,累积器还没有创建,这时先解码,然后把剩余的部分加到累积器中。如果每次input都变完整的解码成一帧,没有/剩余则不会创建累积器
            callDecode(ctx, e.getChannel(), input, e.getRemoteAddress());
   //如果有剩余放入累积
            if (input.readable()) {
                // seems like there is something readable left in the input buffer. So create the cumulation buffer and copy the input into it
                (this.cumulation = newCumulationBuffer(ctx, input.readableBytes())).writeBytes(input);
            }
        } else {
            assert cumulation.readable();
            boolean fit = false;
            
            int readable = input.readableBytes();
            int writable = cumulation.writableBytes();
            int w = writable - readable;
            if (w < 0) {
                int readerIndex = cumulation.readerIndex();
                if (w + readerIndex >= 0) {
                    // the input will fit if we discard all read bytes, so do it
                    cumulation.discardReadBytes();
                    fit = true;
                }
Global site tag (gtag.js) - Google Analytics