ByteBuf absolute vs relative access¶
In Netty's ByteBuf class, data can be retrieved using either absolute or relative access methods. The primary distinction between the two lies in whether the operation affects the internal indices used for tracking read and write positions.^[600-developer-big-data-netty-netty-bytebuf.md]
Absolute access¶
Absolute access targets a specific index in the buffer without modifying the internal pointers. When using methods like getByte(i), the readerIndex remains unchanged regardless of the read operation.^[600-developer-big-data-netty-netty-bytebuf.md]
This allows for random access to the buffer's content, typically used for inspection or when the read position should not advance.^[600-developer-big-data-netty-netty-bytebuf.md]
Relative access¶
Relative access relies on the current readerIndex to determine the position of the next read. When a method like readByte() is called, the data is read from the current readerIndex, and the index is subsequently incremented to move past the read byte.^[600-developer-big-data-netty-netty-bytebuf.md]
This mode facilitates sequential processing of data, such as looping through the buffer's readable bytes until isReadable() returns false.^[600-developer-big-data-netty-netty-bytebuf.md]
Related Concepts¶
- [[ByteBuf structure]]
- [[Netty]]
- Reference counting
Sources¶
600-developer-big-data-netty-netty-bytebuf.md