def encode(value): """Output the encoded value to the standard output. Args: value (int): the integer to be encoded. """ encodeVarint(sys.stdout.buffer.write, value, True)
def encode(x): """Output the encoded value to the standard output. Args: x (int): the integer to be encoded. """ encodeVarint(sys.stdout.buffer.write, x, True)
def flush(self): """Write down buffer to the file.""" if not self.is_output(): return for obj in self._write_buff: obj_str = obj.SerializeToString() encodeVarint(self._fd.write, len(obj_str), True) self._fd.write(obj_str) self._write_buff = []
def flush(self): """Write down buffer to the file.""" if not self.is_output(): return count = len(self._write_buff) if count == 0: return encodeVarint(self._fd.write, count, True) for obj in self._write_buff: obj_str = obj.SerializeToString() encodeVarint(self._fd.write, len(obj_str), True) self._fd.write(obj_str) self._write_buff = []
def flush(self): """Write down buffer to the file.""" if not self.is_output(): return count = len(self._write_buff) + int(bool(self._header)) if count == 0: return encodeVarint(self._fd.write, count, True) if self._header: self._write_header() for obj in self._write_buff: obj_str = self._serialize(obj) encodeVarint(self._fd.write, len(obj_str), True) self._fd.write(obj_str) self._write_buff = []
def _write_varint(self, v): data = encodeVarint(v) self._fd.write(data)
def _write_header(self): """Write the header into the stream.""" assert self._header encodeVarint(self._fd.write, len(self._header), True) self._fd.write(self._header) self._header = b''