fit icon indicating copy to clipboard operation
fit copied to clipboard

reader: decode message by message

Open ktye opened this issue 7 years ago • 4 comments

Can you decode messages in a loop, instead of decoding the whole file in on call? An application is a corrupted fit file, where you want to extract all record messages that are available.

ktye avatar Jul 24 '16 15:07 ktye

Hi, thanks for your interest in the library. I don´t have time at the moment to make any major changes, but would be happy to take any contributions.

I don´t think it´s possible to have a generic decode-one-message-at-a-time function, since the messages can be of different types. A function could return an interface{}, but the the user would have to type cast them, and that would not be a good solution.

I have not looked in detail on how to official SDK does this, but I think it uses some kind of message listener for each message type a user is interested in. It may be possible to be something similar for Go, where a user could subscribe to the messages they are interested in, and receive each type of messages on separate channels. The user could then process them in a for-select-loop.

A more manageable fix would be to change the semantics of the Decode function, and return all messages seen before any decoding error occurred. Now the decode function returns nil if there is any error, but this could be changed to be any successful decoded messages seen before the error.

tormoder avatar Jul 30 '16 20:07 tormoder

I think returning an empty interface is OK. I see no other way. You will process the messages in a type switch. Types which you are not interested, you will not implement. This is similar to registering them in the first place. It has more applications than just corrupted files, it allows to get the messages in the order they appear in the file.

Anyway it's a great package and I know the effort it must have taken to implement, as i was trying to do the same. I stopped and use yours now!

ktye avatar Jul 31 '16 06:07 ktye

I forgot about the order of messages; that is a good point.

tormoder avatar Jul 31 '16 10:07 tormoder

I suppose this is related to encoding (#1) as well, if the goal is a byte-for-byte equal result after a decode-encode round trip.

tormoder avatar Jan 18 '17 19:01 tormoder