def VarintReader(buf, pos=0):
  result = 0
  shift = 0
  while 1:
    b = buf[pos]

    result |= (ORD_MAP_AND_0X7F[b] << shift)
    pos += 1
    if not ORD_MAP_AND_0X80[b]:
      return (result, pos)
    shift += 7
    if shift >= 64:
      raise rdfvalue.DecodeError("Too many bytes when decoding varint.")
A 64 bit decoder from google.protobuf.internal.decoder.
dataset/ETHPy150Open google/grr/grr/lib/rdfvalues/structs.py/VarintReader