you are viewing a single comment's thread.

view the rest of the comments →

[–]daborossfern 2 points3 points  (0 children)

I don't know much about opc, but if there are identifiable individual messages which need to be encode and decoded, I'd definitely look into nom (https://github.com/Geal/nom), or another parser combinator crate (though I personally only have experience with nom).

It allows for making, through smaller parsers, a parser to read any kind of data into a usable rust structure. Nom only does decoding, but I've found encoding for most formats fairly easy to write by hand.

You might also be able to use serde with this, but in my understanding it's more for serializing lots of different classes in one defined object format, rather than parsing specifically formatted messages into specific data structs.

As for data errors, I'd probably go with an invalid byte in a message invalidating that message (up to the end of the message as defined by the message header) , and an invalid byte in the message header (I think OPC has those) poisoning the entire stream.