예제 #1
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
예제 #2
0
 def test_6():
     with pytest.raises(struct.error):
         pack_uint_bytes(-1)
예제 #3
0
 def test_5():
     assert pack_uint_bytes(5000000000) == b'\x00\x00\x00\x01*\x05\xf2\x00'
예제 #4
0
 def test_4():
     assert pack_uint_bytes(65537) == b'\x00\x01\x00\x01'
예제 #5
0
 def test_3():
     assert pack_uint_bytes(256) == b'\x01\x00'
예제 #6
0
 def test_2():
     assert pack_uint_bytes(255) == b'\xff'
예제 #7
0
 def test_1():
     assert pack_uint_bytes(1) == b'\x01'