813 Star 4.3K Fork 1.1K

GVPsmartboot / smart-socket

 / 详情

DelimiterFrameDecoder中bufferList的最后一个为啥要放到for外面呢?

已完成
创建于  
2022-10-31 16:52

有点没看懂哎 :joy:

@Override
public ByteBuffer getBuffer() {
    if (position == 0) {
        return bufferList.get(position);
    }
    byte[] data = new byte[(position) * bufferList.get(0).capacity() + bufferList.get(position).limit()];
    int index = 0;
    for (int i = 0; i < position; i++) {
        ByteBuffer b = bufferList.get(i);
        System.arraycopy(b.array(), b.position(), data, index, b.remaining());
        index += b.remaining();
    }
    ByteBuffer lastBuffer = bufferList.get(position);
    System.arraycopy(lastBuffer.array(), lastBuffer.position(), data, index, lastBuffer.remaining());
    return ByteBuffer.wrap(data);
}

评论 (1)

好像确实不需要放到外面,应该是当初写代码的时候疏忽了。

同学的可爱女友糖糖 任务状态待办的 修改为已完成
三刀 关联分支设置为v1.5.23(tag)

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
351975 smartdms 1578921064 1503076 trdmm 1677933415
Java
1
https://gitee.com/smartboot/smart-socket.git
git@gitee.com:smartboot/smart-socket.git
smartboot
smart-socket
smart-socket

搜索帮助