-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decoding MMSI as int loses leading zeroes #6
Comments
Hey, thank you for the tip. I think that you are right and these ints should rather be strings. But I am concerned that changing this would break backwards compatibility. Maybe we should add an option to decide whether one wants a string or an integer? I am open for discussion. Greetings |
Adding decoding to a string as an option sounds like a good idea to me. |
Store MMSI identifier as strings with leading zeros (#6)
I implemented this feature. From version |
It looks to me like this issue (or something similar) is still present in the latest release (v2.7.0). I noticed it and came here to see if it had been reported before. I wrote a simple script to verify:
When I run this, I get the following output:
As can be seen in the output, when I originally create the MessageType1 object, the mmsi is stored as a string, but then when I decode it later, as seen in the last line of the output, the MMSI gets decoded as an int and loses its leading zero. |
Hey @sethwellsNZ, This is intentional. We had some back-and-forth regarding the treatment of leading zeros, and ultimately, I decided to store the MMSI as an integer rather than a string. I made this decision because, according to gpsd.gitlab.io — the de facto reference for this implementation — its data type is an unsigned integer. Additionally, this behavior is consistent with many popular applications. For example, MarineTraffic, which is likely one of the largest platforms in this regard, also doesn't show leading zeros. The same goes for Aggsoft, another high-quality AIS decoder. If you require leading zeros, I recommend using |
Thanks for the info, good to know! |
added all examples
All of the messages in
pyais/decode.py
are decoding the MMSI value as an integer. However, if there are leading zeroes (which is possible and valid -- see navcen documentation) they are going to be lost. In order to preserve the full original MMSI value, shouldn't these be parsed into strings?The text was updated successfully, but these errors were encountered: