Ejemplo n.º 1
0
 def to_pb(self) -> agent_pb2.Envelope:
     envelope = agent_pb2.Envelope()
     envelope.msg_id = self.msg_id
     envelope.agent_uri = self.uri.toString()
     envelope.register_service.CopyFrom(
         self.service_description.to_agent_description_pb())
     return envelope
Ejemplo n.º 2
0
    def to_pb(self) -> agent_pb2.Agent.Message:
        fipa_msg = fipa_pb2.Fipa.Message()
        fipa_msg.target = self.target
        propose = fipa_pb2.Fipa.Propose()
        if isinstance(self.proposals, bytes):
            propose.content = self.proposals
        else:
            proposals_pb = fipa_pb2.Fipa.Propose.Proposals()
            for p in self.proposals:
                po = proposals_pb.objects.add()
                po.CopyFrom(p.to_pb())
            #proposals_pb.objects.extend([propose.to_pb() for propose in self.proposals])
            #print(self.proposals)
            propose.proposals.CopyFrom(proposals_pb)
        fipa_msg.propose.CopyFrom(propose)
        agent_msg = agent_pb2.Agent.Message()
        agent_msg.dialogue_id = self.dialogue_id
        agent_msg.destination = self.destination
        agent_msg.fipa.CopyFrom(fipa_msg)
        agent_msg.source_uri = self.context.sourceURI.toString()
        agent_msg.target_uri = self.context.targetURI.toString()

        envelope = agent_pb2.Envelope()
        envelope.msg_id = self.msg_id
        envelope.send_message.CopyFrom(agent_msg)
        return envelope
Ejemplo n.º 3
0
    def test1(self):
        weather_service_description = Description(
            {
                "wind_speed": False,
                "temperature": True,
                "air_pressure": True,
                "humidity": True,
            }, WEATHER_DATA_MODEL)

        #        data = {
        #            "msg_id": 1,
        #            "register_service": {
        #                "description": weather_service_description.to_dict()
        #            },
        #        }
        #        pb = agent_pb2.Envelope()
        #        self.tryit(pb, data)

        data = {
            "msg_id": 1,
            "register_service": {
                "description": weather_service_description
            },
        }
        pb = agent_pb2.Envelope()
        self.tryit(pb, data)
Ejemplo n.º 4
0
    def to_pb(self) -> agent_pb2.Envelope:
        agent_msg = agent_pb2.Agent.Message()
        agent_msg.dialogue_id = self.dialogue_id
        agent_msg.destination = self.destination
        agent_msg.content = self.msg
        agent_msg.source_uri = self.context.sourceURI.toString()
        agent_msg.target_uri = self.context.targetURI.toString()

        envelope = agent_pb2.Envelope()
        envelope.msg_id = self.msg_id
        envelope.send_message.CopyFrom(agent_msg)
        return envelope
Ejemplo n.º 5
0
    def test3(self):
        proposal = Description({
            "lat": float(8.9),
            "lon": float(8.11),
            "price": float(123.45),
            "friendly_name": "i am legend",
            "last_detection_time": float(1000.88888),
            "max_spaces": 99,
        })
        proposals = [proposal]
        data = {
            "msg_id": 102,
            "agent_uri": "wibble1",
            "send_message": {
                "dialogue_id": 101,
                "destination": "wibble2",
                "target_uri": "I_AM_URL1",
                "source_uri": "I_AM_URL2",
                "fipa": {
                    "target": 102,
                    "propose": {
                        ("content" if type(proposals) == bytes else None):
                        proposals,
                        ("proposals" if type(proposals) != bytes else None): {
                            "objects": proposals,
                        },
                    }
                }
            }
        }
        oefagent = OefMessageHandler()
        senddata = oefagent.make_message(bytes=None,
                                         json=None,
                                         message_class=agent_pb2.Envelope,
                                         data=data,
                                         pb=None)
        #print(senddata)

        assert b"I_AM_URL1" in senddata
        assert b"I_AM_URL2" in senddata

        inbound = agent_pb2.Envelope()
        inbound.ParseFromString(senddata)
        contents = protoToDict(inbound)
        #print(contents)

        oink = contents
        #print(oink['send_message']['fipa']['propose']['proposals']['objects'])
        assert len(oink) > 1
Ejemplo n.º 6
0
    def to_pb(self):
        fipa_msg = fipa_pb2.Fipa.Message()
        fipa_msg.target = self.target
        decline = fipa_pb2.Fipa.Decline()
        fipa_msg.decline.CopyFrom(decline)
        agent_msg = agent_pb2.Agent.Message()
        agent_msg.dialogue_id = self.dialogue_id
        agent_msg.destination = self.destination
        agent_msg.fipa.CopyFrom(fipa_msg)
        agent_msg.source_uri = self.context.sourceURI.toString()
        agent_msg.target_uri = self.context.targetURI.toString()

        envelope = agent_pb2.Envelope()
        envelope.msg_id = self.msg_id
        envelope.send_message.CopyFrom(agent_msg)
        return envelope
Ejemplo n.º 7
0
    def to_pb(self) -> agent_pb2.Agent.Message:
        fipa_msg = fipa_pb2.Fipa.Message()
        fipa_msg.target = self.target
        cfp = fipa_pb2.Fipa.Cfp()

        if self.query is None:
            cfp.nothing.CopyFrom(fipa_pb2.Fipa.Cfp.Nothing())
        elif isinstance(self.query, bytes):
            cfp.content = self.query
        fipa_msg.cfp.CopyFrom(cfp)
        agent_msg = agent_pb2.Agent.Message()
        agent_msg.dialogue_id = self.dialogue_id
        agent_msg.destination = self.destination
        agent_msg.fipa.CopyFrom(fipa_msg)
        agent_msg.source_uri = self.context.sourceURI.toString()
        agent_msg.target_uri = self.context.targetURI.toString()

        envelope = agent_pb2.Envelope()
        envelope.msg_id = self.msg_id
        envelope.send_message.CopyFrom(agent_msg)
        return envelope
Ejemplo n.º 8
0
 def to_pb(self) -> agent_pb2.Envelope:
     envelope = agent_pb2.Envelope()
     envelope.msg_id = self.msg_id
     envelope.search_services_wide.query.CopyFrom(self.query.to_pb())
     return envelope