docs: def encode_varint(v, f):
      """Encode integer `v` to file `f`.
  
      Parameters
      ----------
      v: int
          Integer v >= 0.
      f: file
          Object containing a write method.
  
      Returns
      -------
      int
          Number of bytes written.
      """
      assert v >= 0
      num_bytes = 0
  
      while True:
          b = v % 0x80
          v = v // 0x80
  
          if v > 0:
              b = b | 0x80
  
          f.write(FIELD_U8.pack(b))
  
          num_bytes += 1
          if v == 0:
              break
  
      return num_bytes