def test_pack2(self): u = Fields() u.add(I4('test')) u.add(U1('val')) u.add(Padding(2, 'res1')) u.test = 0x76543210 u.val = 0xAF data = u.pack() assert data == bytearray.fromhex('10 32 54 76 AF 00 00')
def test_set_field3(self): u = Fields() u.add(I4('test')) u.add(U1('val')) u.test = 0x12345678 u.val = 0xFF assert u._fields['test'].value == 0x12345678 assert u._fields['val'].value == 0xFF assert u.test == 0x12345678 assert u.val == 0xFF
def test_pack1(self): u = Fields() u.add(I4('test')) u.add(U1('val')) u.add(Padding(3, 'res1')) u.add(U4('test2')) u.test = 0x76543210 u.val = 0xAF u.test2 = 0xcafebabe data = u.pack() print(data) assert data == bytearray.fromhex('10 32 54 76 AF 00 00 00 be ba fe ca')