public static long readVLong(ByteBuff buf) {
    byte firstByte = buf.get();
    int len = WritableUtils.decodeVIntSize(firstByte);
    if (len == 1) {
      return firstByte;
    } else {
      int remaining = len - 1;
      long i = 0;
      int offsetFromPos = 0;
      if (remaining >= Bytes.SIZEOF_INT) {
        // The int read has to be converted to unsigned long so the & op
        i = (buf.getIntAfterPosition(offsetFromPos) & 0x00000000ffffffffL);
        remaining -= Bytes.SIZEOF_INT;
        offsetFromPos += Bytes.SIZEOF_INT;
      }
      if (remaining >= Bytes.SIZEOF_SHORT) {
        short s = buf.getShortAfterPosition(offsetFromPos);
        i = i << 16;
        i = i | (s & 0xFFFF);
        remaining -= Bytes.SIZEOF_SHORT;
        offsetFromPos += Bytes.SIZEOF_SHORT;
      }
      for (int idx = 0; idx < remaining; idx++) {
        byte b = buf.getByteAfterPosition(offsetFromPos + idx);
        i = i << 8;
        i = i | (b & 0xFF);
      }
      buf.skip(len - 1);
      return WritableUtils.isNegativeVInt(firstByte) ? ~i : i;
    }
  }
Similar to {@link WritableUtils#readVLong(java.io.DataInput)} but reads from a
{@link ByteBuff}.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java