Question regarding update of reader/writer indexes of ByteBuf in our client API
- Dominant language
- Java
- Stars
- 2k
- Forks
- 976
- Avg merge
- 6d 15h
- Merged PRs (30d)
- 7
Description
**QUESTION**
Regarding the updates to readerIndex/writerIndex of ByteBuf by API method, AFAIU if the API method is doing read operation from the ByteBuf then after calling API method with ByteBuf argument, I wouldn’t expect the readerIndex of the ByteBuf to be at 0.
I mean
```
myApplicationMethod() {
ByteBuf byteBuf = createNewInstanceOfByteBuf();
// add data to byteBuf
APIClass.APIReadMethod(bytebuf);
// here I would expect the readerIndex and writerIndex of byteBuf to be the same,
// since APIReadMethod has consumed/read all of the data in the byteBuf
}
```
But in our case, WriteAdvHandle.write(long entryId, ByteBuf data) doesn’t advances readerIndex of data ByteBuf and this might be because of the following clone https://github.com/apache/bookkeeper/blob/19846b23de3be13e28082d4ba73e21bb8fa39ad2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieProtocol.java#L271
I would expect it to behave in the same way as other core java APIs deal with ByteBuffer - for eg: https://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#read(java.nio.ByteBuffer) https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html#readBytes-io.netty.buffer.ByteBuf- here position of ByteBuffer and readerIndex of ByteBuf is advanced.
**Que:** Are we following general practices of Buffers with our API? Have we mentioned the expected behavior in detail in our API docs?
Contributor guide
Assessment
This issue has not been assessed yet.