public <R> R addSequenceNumber(final ByteBuffer keyBuffer,
                                   final int offset,
                                   final long sequenceNumber,
                                   final Function<ByteBuffer, R> keyBufferConsumer) {
        final UnsignedBytes unsignedBytes = UnsignedBytesInstances.forValue(sequenceNumber);

        // See if the key byte buffer is big enough to add the sequence number.
        if (keyBuffer.capacity() - keyBuffer.limit() >= unsignedBytes.length()) {
            keyBuffer.limit(offset + unsignedBytes.length());
            unsignedBytes.put(keyBuffer, offset, sequenceNumber);
            return keyBufferConsumer.apply(keyBuffer);

        } else {
            // We need to make a bigger buffer to store the sequence number.
            return byteBuffers.use(offset + unsignedBytes.length(), newBuffer -> {
                newBuffer.put(keyBuffer);
                unsignedBytes.put(newBuffer, sequenceNumber);
                newBuffer.flip();
                return keyBufferConsumer.apply(newBuffer);
            });
        }
    }
Updates the keyBuffer with the provided sequence number value.
Absolute, no flip required.
stroom-lmdb/src/main/java/stroom/lmdb2/LmdbKeySequence.java