ByteBuf buffer = Unpooled.buffer(4); buffer.writeInt(1234); int numOfBytesToRead = buffer.readableBytes();
ChannelHandlerContext ctx; ByteBuf buffer = ctx.alloc().buffer(); while (buffer.readableBytes() > 0) { // do something with each byte in the buffer }In this example, we have a `ChannelHandlerContext` object and create a new ByteBuf using `ctx.alloc().buffer()`. We then loop over the buffer's readable bytes and do something with each byte. Overall, `readableBytes()` is a useful method for determining how many bytes can be read from a ByteBuf, which can be helpful for efficient network programming. The package library used in these examples is the Netty package, which is commonly used for networking in Java applications.