public static int sizeOfVarlong(long value) {
        return sizeOfUnsignedVarlong((value << 1) ^ (value >> 63));
    }
@Test
    public void testSizeOfVarlong() {
        // The old well-known implementation for sizeOfVarlong
        LongFunction<Integer> simpleImplementation = (long value) -> {
            long v = (value << 1) ^ (value >> 63);
            int bytes = 1;
            while ((v & 0xffffffffffffff80L) != 0L) {
                bytes += 1;
                v >>>= 7;
            }
            return bytes;
        };

        for (long l = 1; l < Long.MAX_VALUE && l >= 0; l = l << 1) {
            final int expected = simpleImplementation.apply(l);
            final int actual = ByteUtils.sizeOfVarlong(l);
            assertEquals(expected, actual);
        }

        // check zero as well
        assertEquals(simpleImplementation.apply(0), ByteUtils.sizeOfVarlong(0));
    }