code: def writeVarint(trans, n):
      assert (
          n >= 0
      ), "Input to TCompactProtocol writeVarint cannot be negative!"
      out = bytearray()
      while True:
          if n & ~0x7F == 0:
              out.append(n)
              break
          else:
              out.append((n & 0xFF) | 0x80)
              n = n >> 7
      trans.write(bytes(out))
  
imports: from .TProtocol import TType, TProtocolBase, TProtocolException, TProtocolFactory, checkIntegerLimits
  from struct import pack, unpack
  from ..compat import binary_to_str, str_to_binary
label_desc: Use image node_id 4 for calling a global function with example usage: writeVarint(trans, n) without return types