-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue decoding similar message types #117
Comments
@IvantheTricourne: Encoded protobuf messages are schema-free, meaning that you cannot necessarily infer from the encoded value which type they should decode into. For example, an empty This implies that you need to know out-of-band which type you expect to decode into rather than inferring which type by trying to decode each candidate type in succession. |
Thanks for the reply @Gabriel439 I wrote the equivalent protobuf file for the example HS above:
This has the semantic equivalent of representing a sum type over a set of messages as another message type. In this way, the codecs for each type are simply the bytestring encoders/decoders from the decodeMessage _
= (Hs.pure FooBar) <*>
(HsProtobuf.oneof Hs.Nothing
[((HsProtobuf.FieldNumber 1),
(Hs.pure (Hs.fmap FooBarValueFoo)) <*>
(Hs.coerce @(_ (HsProtobuf.Nested Test.Foo))
@(_ (Hs.Maybe Test.Foo))
HsProtobuf.decodeMessageField)),
((HsProtobuf.FieldNumber 2),
(Hs.pure (Hs.fmap FooBarValueBar)) <*>
(Hs.coerce @(_ (HsProtobuf.Nested Test.Bar))
@(_ (Hs.Maybe Test.Bar))
HsProtobuf.decodeMessageField))]) So, assuming this haskell snippet does successfully decode |
@IvantheTricourne: This package supports deriving instances from Haskell types using GHC generics (i.e. |
Say we have 2 message types defined in Haskell and attempt to write codec instances for each:
Let's assume
HasCodec
is a type class that provides the properencode
/decode
functionality for a type. Next, we try to wrap both messages in a sum type that has its ownHasCodec
type:Currently, I have
NBar
messages being incorrectly decoded asNFoo
messages under this context. Is this a known behavior? Or am I perhaps missing/misusing something? Is there any constraint on derivingGeneric
for sum types?The text was updated successfully, but these errors were encountered: