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