@Override
    protected void writeVarInt64(long value) throws IOException {
        //        ensureCapacity(10);
        //        int position = nioBuffer.position();
        //        while (true) {
        //            if ((value & ~0x7FL) == 0) {
        //                UnsafeDirectBufferUtil.setByte(address(position++), (byte) value);
        //                nioBuffer.position(position);
        //                return;
        //            } else {
        //                UnsafeDirectBufferUtil.setByte(address(position++), (byte) (((int) value & 0x7F) | 0x80));
        //                value >>>= 7;
        //            }
        //        }
        //
        // The following implementation is no different from the above code function,
        // just aggregate multiple setBytes into a setShort/setInt
        //
        ensureCapacity(10);
        int position = nioBuffer.position();
        // Handle two popular special cases up front ...
        if ((value & (~0L << 7)) == 0) {
            // size == 1
            UnsafeDirectBufferUtil.setByte(address(position++), (byte) value);
        } else if (value < 0L) {
            // size == 10
            UnsafeDirectBufferUtil.setLong(address(position), (((value & 0x7F) | 0x80) << 56)
                                                              | (((value >>> 7 & 0x7F) | 0x80) << 48)
                                                              | (((value >>> 14 & 0x7F) | 0x80) << 40)
                                                              | (((value >>> 21 & 0x7F) | 0x80) << 32)
                                                              | (((value >>> 28 & 0x7F) | 0x80) << 24)
                                                              | (((value >>> 35 & 0x7F) | 0x80) << 16)
                                                              | (((value >>> 42 & 0x7F) | 0x80) << 8)
                                                              | ((value >>> 49 & 0x7F) | 0x80));
            position += 8;
            UnsafeDirectBufferUtil.setShort(address(position), ((((int) (value >>> 56) & 0x7F) | 0x80) << 8)
                                                               | (int) (value >>> 63));
            position += 2;
        }
        // ... leaving us with 8 remaining [2, 3, 4, 5, 6, 7, 8, 9]
        else if ((value & (~0L << 14)) == 0) {
            // size == 2
            UnsafeDirectBufferUtil.setShort(address(position), ((((int) value & 0x7F) | 0x80) << 8)
                                                               | (byte) (value >>> 7));
            position += 2;
        } else if ((value & (~0L << 21)) == 0) {
            // size == 3
            UnsafeDirectBufferUtil.setShort(address(position), ((((int) value & 0x7F) | 0x80) << 8)
                                                               | (((int) value >>> 7 & 0x7F) | 0x80));
            position += 2;
            UnsafeDirectBufferUtil.setByte(address(position++), (byte) (value >>> 14));
        } else if ((value & (~0L << 28)) == 0) {
            // size == 4
            UnsafeDirectBufferUtil.setInt(address(position), ((((int) value & 0x7F) | 0x80) << 24)
                                                             | ((((int) value >>> 7 & 0x7F) | 0x80) << 16)
                                                             | ((((int) value >>> 14 & 0x7F) | 0x80) << 8)
                                                             | ((int) (value >>> 21)));
            position += 4;
        } else if ((value & (~0L << 35)) == 0) {
            // size == 5
            UnsafeDirectBufferUtil.setInt(address(position), ((((int) value & 0x7F) | 0x80) << 24)
                                                             | ((((int) value >>> 7 & 0x7F) | 0x80) << 16)
                                                             | ((((int) value >>> 14 & 0x7F) | 0x80) << 8)
                                                             | (((int) value >>> 21 & 0x7F) | 0x80));
            position += 4;
            UnsafeDirectBufferUtil.setByte(address(position++), (byte) (value >>> 28));
        } else if ((value & (~0L << 42)) == 0) {
            // size == 6
            UnsafeDirectBufferUtil.setInt(address(position), ((((int) value & 0x7F) | 0x80) << 24)
                                                             | ((((int) value >>> 7 & 0x7F) | 0x80) << 16)
                                                             | ((((int) value >>> 14 & 0x7F) | 0x80) << 8)
                                                             | (((int) value >>> 21 & 0x7F) | 0x80));
            position += 4;
            UnsafeDirectBufferUtil.setShort(address(position), ((((int) (value >>> 28) & 0x7F) | 0x80) << 8)
                                                               | (int) (value >>> 35));
            position += 2;
        } else if ((value & (~0L << 49)) == 0) {
            // size == 7
            UnsafeDirectBufferUtil.setInt(address(position), ((((int) value & 0x7F) | 0x80) << 24)
                                                             | ((((int) value >>> 7 & 0x7F) | 0x80) << 16)
                                                             | ((((int) value >>> 14 & 0x7F) | 0x80) << 8)
                                                             | (((int) value >>> 21 & 0x7F) | 0x80));
            position += 4;
            UnsafeDirectBufferUtil.setShort(address(position), ((((int) (value >>> 28) & 0x7F) | 0x80) << 8)
                                                               | (((int) (value >>> 35) & 0x7F) | 0x80));
            position += 2;
            UnsafeDirectBufferUtil.setByte(address(position++), (byte) (value >>> 42));
        } else if ((value & (~0L << 56)) == 0) {
            // size == 8
            UnsafeDirectBufferUtil.setLong(address(position), (((value & 0x7F) | 0x80) << 56)
                                                              | (((value >>> 7 & 0x7F) | 0x80) << 48)
                                                              | (((value >>> 14 & 0x7F) | 0x80) << 40)
                                                              | (((value >>> 21 & 0x7F) | 0x80) << 32)
                                                              | (((value >>> 28 & 0x7F) | 0x80) << 24)
                                                              | (((value >>> 35 & 0x7F) | 0x80) << 16)
                                                              | (((value >>> 42 & 0x7F) | 0x80) << 8) | (value >>> 49));
            position += 8;
        } else {
            // size == 9 (value & (~0L << 63)) == 0
            UnsafeDirectBufferUtil.setLong(address(position), (((value & 0x7F) | 0x80) << 56)
                                                              | (((value >>> 7 & 0x7F) | 0x80) << 48)
                                                              | (((value >>> 14 & 0x7F) | 0x80) << 40)
                                                              | (((value >>> 21 & 0x7F) | 0x80) << 32)
                                                              | (((value >>> 28 & 0x7F) | 0x80) << 24)
                                                              | (((value >>> 35 & 0x7F) | 0x80) << 16)
                                                              | (((value >>> 42 & 0x7F) | 0x80) << 8)
                                                              | ((value >>> 49 & 0x7F) | 0x80));
            position += 8;
            UnsafeDirectBufferUtil.setByte(address(position++), (byte) (value >>> 56));
        }
        BufferUtils.position(nioBuffer, position);
    }
Start address of the memory buffer The memory buffer should be non-movable, which normally means that is is allocated
off-heap
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/serialization/impl/protostuff/io/UnsafeNioBufOutput.java