|
48 | 48 | )
|
49 | 49 | from pyais.stream import ByteStream
|
50 | 50 | from pyais.util import b64encode_str, bits2bytes, bytes2bits, decode_into_bit_array
|
| 51 | +from pyais.exceptions import MissingPayloadException |
51 | 52 |
|
52 | 53 |
|
53 | 54 | def ensure_type_for_msg_dict(msg_dict: typing.Dict[str, typing.Any]) -> None:
|
@@ -1743,3 +1744,27 @@ def test_that_decode_nmea_and_ais_works_with_proprietary_messages(self):
|
1743 | 1744 | self.assertEqual(decoded.msg_type, 1)
|
1744 | 1745 | self.assertEqual(decoded.mmsi, 538090443)
|
1745 | 1746 | self.assertEqual(decoded.speed, 10.9)
|
| 1747 | + |
| 1748 | + def test_that_decode_works_for_fragmented_messages_with_empty_payloads(self): |
| 1749 | + """Issue: https://github.com/M0r13n/pyais/issues/157""" |
| 1750 | + # WHEN decoding a fragmented message where the second message has an empty payload. |
| 1751 | + decoded = decode( |
| 1752 | + b"!AIVDM,2,1,0,A,8@2R5Ph0GhRbUqe?n>KS?wvlFR06EuOwiOl?wnSwe7wvlOwwsAwwnSGmwvwt,0*4E", |
| 1753 | + b"!AIVDM,2,2,0,A,,0*16", |
| 1754 | + ) |
| 1755 | + # THEN the message is decoded without an error |
| 1756 | + # Verified against https://www.aggsoft.com/ais-decoder.htm |
| 1757 | + self.assertEqual(decoded.msg_type, 8) |
| 1758 | + self.assertEqual(decoded.repeat, 1) |
| 1759 | + self.assertEqual(decoded.mmsi, 2655619) |
| 1760 | + self.assertEqual(decoded.data, b'\x08\xaa\x97\x9bO\xd8\xe6\xe3?\xff\xb4Z \x06W\xd7\xff\xc5\xfd\x0f\xffh\xff\xb4\x7f\xfe\xd1\xff\xff\xed\x1f\xff\xda5\xf5\xff\xef\xfc') |
| 1761 | + |
| 1762 | + def test_decode_with_empty_payload(self): |
| 1763 | + """Variation of test_that_decode_works_for_fragmented_messages_with_empty_payloads""" |
| 1764 | + # WHEN decoding message without payload an exception is raised |
| 1765 | + with self.assertRaises(MissingPayloadException) as err: |
| 1766 | + _ = decode( |
| 1767 | + b"!AIVDM,1,1,0,A,,0*16", |
| 1768 | + ) |
| 1769 | + |
| 1770 | + self.assertEqual(str(err.exception), '!AIVDM,1,1,0,A,,0*16') |
0 commit comments