Netty ByteBuf writerIndex和readerIndex理解

最近在看 Netty ,给我的感觉是很强大,但是也很难学习。这里记录一个关于 ByteBuf 的小知识

ByteBuf.readableBytes() 返回可读的字节数
其实就是等于
writerIndex - readerIndex ,这里我们 debug 看看,如下图
这里写图片描述

所以同理

ByteBuf.readable()

也就很好理解了,ByteBuf是否有可读的内容,如果有则返回 true 没有则 false 判断标准也是
writerIndex > readerIndex

猜你喜欢

转载自blog.csdn.net/guozhaohui628/article/details/81114592
今日推荐