pyais: Decoding messages with a unexpected bit_arr length silently fails returning None

When decoding messages, if the bit_arr length is less than what is needed for every property expected to be decoded None is returned with no error.

Test Code:

import pyais
print(pyais.NMEAMessage(bytes("!ARVDM,2,1,3,B,E>m1c1>9TV`9WW@97QUP0000000F@lEpmdceP00003b,0*5C", 'utf-8')).decode().content)

As you can see below I have commented out several properties except for assigned which attempts to access index 270 of the bit_arr. When this is uncommented the returned value is None, however when commented (there are no properties that access outside of the bit_arr length) you can see the message decodes as expected. image

Ideally properties that do not have data or fail to decode would result in None. I appear to be getting this for most if not all of my type 21 messages.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 55 (55 by maintainers)

Most upvoted comments

This seems like an error of your code, right?

Not technically an error those are part 2 messages that were unable to be matched to a part 1 (I’m not using the built in matching from pyais), something you can ignore.

May I ask where you got your large dataset from?

Unfortunately it’s not publically available and I don’t have permission to share it sorry ❤️

I guess, that we’re ready for a v2 release, don’t you think so?

Definitely looks like it, if you want to wait a day or two I will re-decode the ~203M test dataset with the new changes to see if anything else pops up. After its ready for release I intend to re-decode the full historical dataset of 7Billion reports.

With the new decoding method errors for the test dataset are down to 0.01% which is a order of magnitude improvement.

Looks like there is a issue with asdict attempting to cast enums which are None…

Traceback (most recent call last):
  File "/pyais/messages.py", line 438, in asdict
    d = {slt: int(getattr(self, slt)) if slt in ENUM_FIELDS else getattr(self, slt) for slt in self.__slots__}
  File "/pyais/messages.py", line 438, in <dictcomp>
    d = {slt: int(getattr(self, slt)) if slt in ENUM_FIELDS else getattr(self, slt) for slt in self.__slots__}
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

Happy to test it and see how things go. Could I get a link to the repo/branch that contains the new code?

Thanks 😃

Not sure yet. I am think about moving the current state to a different branch (e.g version-1). Then Main would be the place for the new, active development.

Looks good