async def execute_task(self, **kwargs): extra = self.photons_app.extra_as_json if "extra_payload_kwargs" in kwargs: extra.update(kwargs["extra_payload_kwargs"]) packd = Messages.pack(extra, protocol_register, unknown_ok=True) print(binascii.hexlify(packd.tobytes()).decode())
async def pack(collector, **kwargs): """ Pack json found after the ``--`` into hexlified string ``pack -- '{"frame_address": {"ack_required": true, "res_required": true, "reserved2": "000000000000", "reserved3": "00", "sequence": 1, "target": "0000000000000000"}, "frame_header": {"addressable": true, "protocol": 1024, "reserved1": "00", "size": 68, "source": 591976603, "tagged": false}, "payload": {}, "protocol_header": {"pkt_type": 45, "reserved4": "0000000000000000", "reserved5": "0000"}}'`` """ extra = collector.configuration["photons_app"].extra_as_json protocol_register = collector.configuration["protocol_register"] if "extra_payload_kwargs" in kwargs: extra.update(kwargs["extra_payload_kwargs"]) packd = Messages.pack(extra, protocol_register, unknown_ok=True) print(binascii.hexlify(packd.tobytes()).decode())
data = mock.Mock(name="data") with assertRaises(BadConversion, "Unknown message type!", pkt_type=87): Messages.pack_payload(87, data, protocol_register.message_register(1024)) describe "pack": it "works", protocol_register, TestMessages: data = { "protocol": 1024, "pkt_type": 78, "one": "ii", "source": 4, "sequence": 1, "target": "d073d5000001", } bts = TestMessages.One.create(**data).pack() assert Messages.pack(data, protocol_register) == bts it "works with unknown packet", protocol_register: data = { "protocol": 1024, "pkt_type": 87, "payload": "AA", "source": 4, "sequence": 1, "target": "d073d5000001", } bts = LIFXPacket.create(**data).pack() assert Messages.pack(data, protocol_register, unknown_ok=True) == bts it "works out packet type and packs when you have a PacketKls", protocol_register: res = mock.Mock(name="res")