async def json(self, data: str, channel: ServiceChannel) -> None:
        """
        Send json message

        Args:
            data: JSON dict
            channel: Channel to send the message to

        Returns: None
        """
        msg = factory.json(data)
        await self.send_message(msg, channel=channel)
Esempio n. 2
0
    def json(self, data, channel):
        """
        Send json message

        Args:
            data (dict): JSON dict
            channel (:class:`ServiceChannel`): Channel to send the message to

        Returns: None
        """
        msg = factory.json(data)
        self.send_message(msg, channel=channel)
Esempio n. 3
0
def test_json(packets, crypto):
    bin_name = 'json'
    msg = factory.json(text={
        'request': 'GetConfiguration',
        'msgid': '2ed6c0fd.2'
    })
    msg.header(sequence_number=11, source_participant_id=31, channel_id=151)
    msg.header.flags(need_ack=True)
    packed = _pack(msg, crypto)

    assert msg.header.pkt_type == enum.PacketType.Message
    assert msg.header.flags.msg_type == enum.MessageType.Json

    assert msg.protected_payload.text == {
        'request': 'GetConfiguration',
        'msgid': '2ed6c0fd.2'
    }

    assert len(packed) == len(packets[bin_name])
    assert packed == packets[bin_name]