Ejemplo n.º 1
0
 def encode(self) -> bytearray:
     component_wires = [v.encode() for v in self.value]
     length = sum(len(w) for w in component_wires)
     buf_len = length + get_tl_num_size(length) + get_tl_num_size(
         StateVectorModelTypes.VECTOR.value)
     ret = bytearray(buf_len)
     pos = write_tl_num(StateVectorModelTypes.VECTOR.value, ret)
     pos += write_tl_num(length, ret, pos)
     for w in component_wires:
         ret[pos:pos + len(w)] = w
         pos += len(w)
     return ret
Ejemplo n.º 2
0
 def encode(self) -> bytearray:
     length, component_wires = 0, []
     for v in self.value:
         ba = v.encode()
         length += len(ba)
         component_wires.append(ba)
     buf_len = length + get_tl_num_size(length) + get_tl_num_size(
         SVSyncTlvTypes.VECTOR.value)
     ret = bytearray(buf_len)
     pos = write_tl_num(SVSyncTlvTypes.VECTOR.value, ret)
     pos += write_tl_num(length, ret, pos)
     for w in component_wires:
         ret[pos:pos + len(w)] = w
         pos += len(w)
     return ret
Ejemplo n.º 3
0
 def encode(self) -> bytearray:
     bseqno, bnid = pack_uint_bytes(self.seqno), self.nid.encode()
     # nid
     size = len(bnid) + get_tl_num_size(len(bnid)) + get_tl_num_size(
         SVSyncTlvTypes.VECTOR_ENTRY.value)
     temp1 = bytearray(size)
     pos = write_tl_num(SVSyncTlvTypes.VECTOR_ENTRY.value, temp1)
     pos += write_tl_num(len(bnid), temp1, pos)
     temp1[pos:pos + len(bnid)] = bnid
     # seqno
     size = len(bseqno) + get_tl_num_size(len(bseqno)) + get_tl_num_size(
         SVSyncTlvTypes.SEQNO.value)
     temp2 = bytearray(size)
     pos = write_tl_num(SVSyncTlvTypes.SEQNO.value, temp2)
     pos += write_tl_num(len(bseqno), temp2, pos)
     temp2[pos:pos + len(bseqno)] = bseqno
     return temp1 + temp2
Ejemplo n.º 4
0
 def test_5():
     buf = bytearray(9)
     siz = write_tl_num(5000000000, buf)
     assert buf == b'\xff\x00\x00\x00\x01*\x05\xf2\x00'
     assert siz == 9
Ejemplo n.º 5
0
 def test_4():
     buf = bytearray(5)
     siz = write_tl_num(65537, buf)
     assert buf == b'\xfe\x00\x01\x00\x01'
     assert siz == 5
Ejemplo n.º 6
0
 def test_3():
     buf = bytearray(1)
     siz = write_tl_num(192, buf)
     assert buf == b'\xc0'
     assert siz == 1
Ejemplo n.º 7
0
 def test_2():
     buf = bytearray(10)
     siz = write_tl_num(255, buf, 1)
     assert buf == b'\x00\xfd\x00\xff\x00\x00\x00\x00\x00\x00'
     assert siz == 3
Ejemplo n.º 8
0
 def test_1():
     buf = bytearray(10)
     siz = write_tl_num(0, buf, 1)
     assert buf == b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
     assert siz == 1