public static void readRaw(final Buffer buffer, final Consumer<ByteBuf> consumer) {
        if (buffer instanceof NettyBuffer) {
            consumer.accept(((NettyBuffer)buffer).getUnderlyingBuffer());
            return;
        }

        // Create a new ByteBuf as a wrapper
        final int initialIndex = buffer.readerIndex();
        final ByteBuf newBuffer = getFromIndex(buffer, initialIndex);

        try {
            // Invoke the consumer to read from the ByteBuf
            consumer.accept(newBuffer);

            // Advance the reader index of the Buffer implementation
            buffer.readerIndex(initialIndex + newBuffer.readerIndex());
        } finally {
            newBuffer.release();
        }
    }
Utility method to allow reading from the underlying bytes using a Netty {@link ByteBuf} instance for
interoperability, advancing the reader index of the {@link Buffer} after the consumer is called.

Note that the {@link ByteBuf} used by the consumer should not be released by the caller.
In case the provided {@link Buffer} instance is not a {@link NettyBuffer}, it will create a {@link ByteBuf}
wrapper for the consumer to use, releasing it after use.
gremlin-util/src/main/java/org/apache/tinkerpop/gremlin/util/ser/NettyBufferFactory.java