The AIS payloads are encapsulated within the NMEA message format -- NMEA sees them only as a black box -- so you should not expect a NMEA parser to be sensitive to the encoded AIS content.
If you were desperate, you could try to match the multipart messages by the expected lengths of each AIS payload message type, but you'd run into the following problems:
- Some message types (e.g. type 8: Binary Broadcast Message) have a variable length
- There are conventions for aligning messages on byte boundaries that are not always followed, so even fixed-length messages can be received with differing lengths (e.g. type 15).
The best you can do in practice is assume that multipart messages may only arrive interleaved if the two messages have different NMEA message types (e.g. one message is AIVDM
, and the other is SAVDM
). This is the approach taken in the NMEA parsing library I wrote, under each_complete_message
.
You could go further and use the total number of message parts as a way to differentiate messages, but in practice 3-part messages seem to be exceedingly rare.
TL;DR
No, there is no fail safe method of linking fragments.