def write_varint(i, data: nil, stream: nil)
      buf = encode_varint(i)
      data << buf if data
      stream.write(buf) if stream
      buf
    end
def write_varint(i, data: nil, stream: nil)
      buf = encode_varint(i)
      data << buf if data
      stream.write(buf) if stream
      buf
    end
Encodes integer and returns its binary varint representation.
 If data is given, appends to a data.
 If stream is given, writes to a stream.