838 Star 4.9K Fork 1.2K

GVPsmartboot/smart-socket

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

Done
Opened this issue  
2022-10-31 16:52

有点没看懂哎

@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);
}

Comments (1)

同学的可爱女友糖糖 created任务 3 years ago
351975 smartdms 1578921064 头像挂件 三刀 owner 3 years ago

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

同学的可爱女友糖糖 changed issue state from 待办的 to 已完成 3 years ago
三刀 set branch to v1.5.23(tag) 3 years ago

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(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

Search