Beispiel #1
0
 def dump(cls, writer: Writer, elem: bytes) -> None:
     if cls.FIX_SIZE:
         if cls.SIZE != len(elem):
             raise ValueError("Size mismatch")
     else:
         dump_uvarint(writer, len(elem))
     writer.write(elem)
Beispiel #2
0
 def dump(cls, writer, elems, elem_type=None):
     if elem_type is None:
         elem_type = cls.ELEM_TYPE
     if cls.FIX_SIZE:
         if cls.SIZE != len(elems):
             raise ValueError("Size mismatch")
     else:
         dump_uvarint(writer, len(elems))
     for elem in elems:
         elem_type.dump(writer, elem)
    def test_varint(self):
        """
        Var int
        :return:
        """
        # fmt: off
        test_nums = [
            0, 1, 12, 44, 32, 63, 64, 127, 128, 255, 256, 1023, 1024, 8191,
            8192, 2**16, 2**16 - 1, 2**32, 2**32 - 1, 2**64, 2**64 - 1,
            2**72 - 1, 2**112
        ]
        # fmt: on

        for test_num in test_nums:
            writer = MemoryReaderWriter()

            dump_uvarint(writer, test_num)
            test_deser = load_uvarint(MemoryReaderWriter(writer.get_buffer()))

            self.assertEqual(test_num, test_deser)
Beispiel #4
0
 def uvarint(self, i):
     int_serialize.dump_uvarint(self.kwriter, i)
Beispiel #5
0
 def dump(writer: Writer, s: str) -> None:
     dump_uvarint(writer, len(s))
     writer.write(s.encode())
Beispiel #6
0
 def dump(writer, s):
     dump_uvarint(writer, len(s))
     writer.write(bytes(s))
 def uvarint(self, i: int) -> None:
     int_serialize.dump_uvarint(self.kwriter, i)
Beispiel #8
0
 def dump(writer: Writer, n: int) -> None:
     return dump_uvarint(writer, n)
Beispiel #9
0
 def dump(writer, n: int):
     return dump_uvarint(writer, n)