Esempio n. 1
0
    def dataReceived(self, data):
        self.buf += data

        packets, self.buf = parse_packets(self.buf)

        if packets:
            self.resetTimeout()

        for header, payload in packets:
            if header in self.handlers:
                self.handlers[header](payload)
            else:
                log.err("Didn't handle parseable packet %d!" % header)
                log.err(payload)
Esempio n. 2
0
    def dataReceived(self, data):
        self.buf += data

        packets, self.buf = parse_packets(self.buf)

        if packets:
            self.resetTimeout()

        for header, payload in packets:
            if header in self.handlers:
                d = maybeDeferred(self.handlers[header], payload)

                @d.addErrback
                def eb(failure):
                    log.err("Error while handling packet %d" % header)
                    log.err(failure)
                    return None
            else:
                log.err("Didn't handle parseable packet %d!" % header)
                log.err(payload)
Esempio n. 3
0
    def test_location_round_trip(self):
        """
        Test whether we are affected by an older Construct bug.
        """

        packet = """
        DUAaAAAAAAAAQFDPXCkAAABAUGeuFIAAAEAeAAAAAAAAAAAAAAAAAAAA
        """.decode("base64")

        header, payload = parse_packets(packet)[0][0]
        self.assertEqual(header, 13)
        self.assertEqual(payload.position.x, 6.5)
        self.assertEqual(payload.position.y, 67.24000000953674)
        self.assertEqual(payload.position.stance, 65.62000000476837)
        self.assertEqual(payload.position.z, 7.5)
        self.assertEqual(payload.orientation.rotation, 0.0)
        self.assertEqual(payload.orientation.pitch, 0.0)
        self.assertEqual(payload.grounded.grounded, 0)
        reconstructed = make_packet("location", payload)
        self.assertEqual(packet, reconstructed)
Esempio n. 4
0
 def do_parse(self, msg_id):
     packets, leftover = parse_packets(self.sample[msg_id])
     self.assertEqual(len(packets), 1, 'Message not parsed')
     self.assertEqual(len(leftover), 0, 'Bytes left after parsing')
     return packets[0][1]