private static long innerUnsignedReadVarLong(ByteBuffer buffer, long result) {
        byte tmp;
        if ((tmp = buffer.get()) >= 0) {
            result |= (long) tmp << 35;
        } else {
            result |= (long) (tmp & 0x7f) << 35;
            if ((tmp = buffer.get()) >= 0) {
                result |= (long) tmp << 42;
            } else {
                result |= (long) (tmp & 0x7f) << 42;
                if ((tmp = buffer.get()) >= 0) {
                    result |= (long) tmp << 49;
                } else {
                    result |= (long) (tmp & 0x7f) << 49;
                    if ((tmp = buffer.get()) >= 0) {
                        result |= (long) tmp << 56;
                    } else {
                        result |= (long) (tmp & 0x7f) << 56;
                        result |= (long) (tmp = buffer.get()) << 63;
                        if (tmp < 0) {
                            throw new IllegalArgumentException();
                        }
                    }
                }
            }
        }
        return result;
    }
Implementation extended from Int implementation from Netty
see: https://github.com/netty/netty/blob/59aa6e635b9996cf21cd946e64353270679adc73/codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufVarint32FrameDecoder.java#L73
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/util/ByteUtilsBenchmark.java