Help with using OneOf to handle different parse data #280
-
Building a parser of vehicle OBDII responses and have a case where the normal and error responses are different. For example I typically receive the response:
But I can also get an error responses similar to these:
My initial parser for the non-error response is to parser the command followed by the response:
but now I am trying to add in parsing of the error cases so I replaced the
The problem is I get a compiler error that has me confused and could use some help resolving. If I comment out either of the OneOf parsers I get correct results but with both there I get a compiler error:
I naively wished for the non-error response to be tried first and if it failed match the error conditions would be parsed but this compiler error has me stuck. Any suggestions for writing a parser for the two types of responses would get me going again. Thanks Rick P.S. If it helps here some other bits of the parser that might be useful:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
After much playing around (and learning) I decided to leave OneOf behind - seems all the types must match and it isn't possible or I am unable to figure out a solution. So I added a parser just for the error case and went to top of parser and added it to the failing case:
Now my test cases pass and I can start using the parser in real code. But if anyone has a comment or suggestion on using OneOf I would love to learn a better way of doing things. |
Beta Was this translation helpful? Give feedback.
-
I’ll give that a try, right now I am just running in a playground seeing what works. None of the benchmarks had anything other than Substrings in the OneOf examples I could find so this is a nice idea to follow up with. Thanks a bunch for replying need all the help I can get building two TCA apps, this one pulling real-time vehicle data over Bluetooth from an OBDII dongle and sending it to the cloud. And the dongle uses the AT protocol from the 1980’s which looked perfect for the Pointfree parsing package. |
Beta Was this translation helpful? Give feedback.
I’ll give that a try, right now I am just running in a playground seeing what works. None of the benchmarks had anything other than Substrings in the OneOf examples I could find so this is a nice idea to follow up with.
Thanks a bunch for replying need all the help I can get building two TCA apps, this one pulling real-time vehicle data over Bluetooth from an OBDII dongle and sending it to the cloud. And the dongle uses the AT protocol from the 1980’s which looked perfect for the Pointfree parsing package.