forked from btlines/pbdirect
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
Support oneof fields #30
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Don't skip writing a oneof field even if it has a default scalar value. The implementation for this is a bit nasty. I added a boolean parameter to the signature of `PBFieldWriter` that is only used when writing a scalar field and is ignored in all other cases. Will have a think about a cleaner solution.
This is so we can set the field to None when it is missing when reading a message from protobuf. If it was a plain coproduct type (e.g. `Int :+: String :+: CNil`), there is no sensible default value we can set it to. We could arbitrarily set it to `Inr(0)`, but we would lose the information that the field was missing from the message.
juanpedromoreno
approved these changes
Dec 27, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outstanding job
gen: Generic.Aux[A, R], | ||
repr: Lazy[PBMessageReader[R]]): PBMessageReader[A] = instance { (bytes: Array[Byte]) => | ||
gen.from(repr.value.read(bytes)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🔥
BenFradet
approved these changes
Dec 27, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cb372
added a commit
to higherkindness/skeuomorph
that referenced
this pull request
Jan 2, 2020
This is for compatibility with pbdirect. See 47degrees/pbdirect#30
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support for reading/writing shapeless coproducts as protobuf
oneof
fields.The field must be annotated with a
@pbIndex
annotation containing the field numbers for each branch of the coproduct. Also the coproduct type must be wrapped inOption
so that we can handle missing fields sensibly.e.g.
Also updated the readme to document both this feature and the new support for default values/missing fields.
This PR also removes a feature that I didn't think should exist: reading and writing sealed traits of messages, e.g.
The same functionality can now be achieved more safely and protobuf-compliantly using a
oneof
field.