Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    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 = []
Ejemplo n.º 4
0
    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 = []
Ejemplo n.º 5
0
    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 = []
Ejemplo n.º 6
0
 def _write_varint(self, v):
     data = encodeVarint(v)
     self._fd.write(data)
Ejemplo n.º 7
0
 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''