code: def decode_int(stream, signed=False):
      
      n = result = 0
      b = stream.read_uchar()
  
      while b & 0x80 != 0 and n < 3:
          result <<= 7
          result |= b & 0x7f
          b = stream.read_uchar()
          n += 1
  
      if n < 3:
          result <<= 7
          result |= b
      else:
          result <<= 8
          result |= b
  
          if result & 0x10000000 != 0:
              if signed:
                  result -= 0x20000000
              else:
                  result <<= 1
                  result += 1
  
      return result
docs: Decode C{int}.