def test_welcome_decode(): packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes' decoded, trailer = p.decode(packet) eq_(len(decoded), 1) decoded = decoded[0] assert isinstance(decoded, p.WelcomePacket) eq_(decoded.message, 'Welcome to eyes')
def test_version_decode(): packet = b'\xef\xbe\xad\xde\x2c\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x4a\xe7\x48\xe5\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00' decoded, trailer = p.decode(packet) eq_(len(decoded), 1) decoded = decoded[0] assert isinstance(decoded, p.VersionPacket) eq_(decoded.major, 2) eq_(decoded.minor, 1) eq_(decoded.patch, 1)
def test_undecoded_round_trip(): packet = (b'\xef\xbe\xad\xde' # packet heading b'\x1c\x00\x00\x00' # total packet length b'\x02\x00\x00\x00' # origin b'\x00\x00\x00\x00' # padding b'\x08\x00\x00\x00' # remaining length b'\xdd\xcc\xbb\xaa' # packet type b'\xfe\x83\x4c\x00') # packet data decoded, rest = p.decode(packet, provenance=p.PacketProvenance.client) eq_(len(decoded), 1) eq_(rest, b'') encoded = p.encode(decoded[0], provenance=p.PacketProvenance.client) eq_(packet, encoded)
def test_undecoded_round_trip(): packet = ( b'\xef\xbe\xad\xde' # packet heading b'\x1c\x00\x00\x00' # total packet length b'\x02\x00\x00\x00' # origin b'\x00\x00\x00\x00' # padding b'\x08\x00\x00\x00' # remaining length b'\xdd\xcc\xbb\xaa' # packet type b'\xfe\x83\x4c\x00') # packet data decoded, rest = p.decode(packet, provenance=p.PacketProvenance.client) eq_(len(decoded), 1) eq_(rest, b'') encoded = p.encode(decoded[0], provenance=p.PacketProvenance.client) eq_(packet, encoded)
def eat(self, data): self.buffer += data packets, self.buffer = packet.decode(self.buffer, provenance=self.provenance) return packets
def test_double_decode(): packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes' packet = packet + packet decoded, trailer = p.decode(packet) eq_(len(decoded), 2) eq_(trailer, b'')
def test_overflow_payload(): packet = b'\xef\xbe\xad\xde+\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x17\x00\x00\x00\xda\xb3\x04m\x0f\x00\x00\x00Welcome to eyes\xef' decoded, trailer = p.decode(packet) eq_(trailer, b'\xef')
def test_truncated_payload(): packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x13\x00\x00\x00\xda\xb3\x04\x6dWelcome to ' decoded, trailer = p.decode(packet) eq_(decoded, []) eq_(trailer, packet)
def test_truncated_header(): packet = b'\xef\xbe\xad\xde\x27\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00' decoded, trailer = p.decode(packet) eq_(decoded, []) eq_(trailer, packet)