Closed MyrnsWork closed 1 month ago
@MyrnsWork If I understand your proposal correctly, you are suggesting an extension of the streaming API of pyais to allow a custom pre-process function for handling different kinds of formats of metadata.
That sounds like a great idea. However, special care needs to be taken to avoid breaking backward compatibility. I will think about this when time allows. Feel free to open a PR with your changes so that I can take a look and possibly draw some inspiration.
Have a great day!
If I understand your proposal correctly, you are suggesting an extension of the streaming API of pyais to allow a custom pre-process function for handling different kinds of formats of metadata
@M0r13n You're right !
Before opening a PR, a word about the tests. As far as I'm concerned, all the tests passed except:
If I change the path ‘tests/ais_test_messages’ to ‘ais_test_messages’ in test_decode_from_file and test_parser then :
Anyways, when I git checkout on master (without any modifications), the same tests don't pass. Is this normal for these tests?
Hey @MyrnsWork,
Thank you for the PR; I appreciate your effort. I took some inspiration from you but ultimately settled on a slightly different approach that is more robust and flexible. All instances implementing the streaming API of pyais now optionally accept the keyword preprocessor
. This must be an instance of a class implementing the PreprocessorProtocol
protocol, which essentially requires the implementation of a process
method that accepts some bytes and returns some bytes in NMEA 0183 format. The user is free to add additional logic in this class. I added an example that provides access to the metadata.
Please note that IterMessages()
does not accept the preprocessor
keyword, as this class requires the messages to be already in memory, meaning it should be trivial to parse the custom format.
Feel free to look at my changes and provide your feedback. You can expect the changes to be available in the coming days.
Have a great day!
Indeed, you're implementation is better !
@MyrnsWork Thank you. So I am closing this now. :)
It may be useful to read or stream NMEA messages containing any kind of metadata like this:
And the result would be:
I've already coded the functionality (by keeping the current behaviour of IterMessages (or any class that has inherited from AssembleMessages) with 1 argument) on a local branch if you're interested (I'm not sure of the quality of my code though).