adrianmo / go-nmea

A NMEA parser library in pure Go
MIT License
226 stars 77 forks source link

Support custom message types #73

Closed yavosh closed 4 years ago

yavosh commented 4 years ago

I would like to extend this lib to support custom message parsing, is this something you would consider merging. We are using this to parse some custom message which are not part of the NMEA standard. The idea is to have a way to register parsers for new message types.

adrianmo commented 4 years ago

Hi @yavosh, thanks for the interest in the library. What kind of messages are you considering implementing? Is this something like the PMTK (Mediatek) or PGRME (Garmin) proprietary messages? If that's the case, yes, we will review your contribution and eventually merge it.

I also like the idea of having the possibility to extend the library via external plugins or modules, but that would require a more in-depth design session.

yavosh commented 4 years ago

No these are proprietary messages we generate ourselves, they don't really fit NMEA in any way otherwise we would be contributing them.

yavosh commented 4 years ago

The extensibility suggestion is to replace implementation of func Parse(raw string) (Sentence, error) from the current switch on type to a map[string]func() where each existing supported message type would have its constructor added and there can be a method like RegisterParser which would allow you to add a new message type with its parser.

Should be fairly unobtrusive change.

adrianmo commented 4 years ago

Your suggestion looks good. If you are willing to put together a draft/prototype we will definitely review it and help with the integration. If not, no worries, we will add it to our backlog.

icholy commented 4 years ago

Being able to register parsers is something I've wanted for a while.

yavosh commented 4 years ago

Hey @adrianmo have a look at how it could work https://github.com/adrianmo/go-nmea/pull/75