-
Notifications
You must be signed in to change notification settings - Fork 145
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
Add Protobuf.Text #398
base: main
Are you sure you want to change the base?
Add Protobuf.Text #398
Conversation
Allows encoding to textproto
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.
Should we look at using Inspect.Algebra
to simplify the line splitting? Not sure what the spec of the format is and I don't have the bandwidth to go read it now, but it seems flexible enough that we could break lines in a few different places?
Thank you, @whatyouhide. I'll explore using |
Makes the code a lot simpler.
dcc90cb
to
6c73550
Compare
Pushed a new version using Some limitations/changes:
I'll address the other comments over the week :) |
@v0idpwn OK sounds good, lmk when this is gonna be ready for re-review. 🙃 |
# This is actually new. Should it be ported to Protobuf.Encoder? | ||
defp skip_field?(:proto3, value, %FieldProps{type: {:enum, enum_mod}, oneof: nil}) do | ||
enum_props = enum_mod.__message_props__() | ||
[first_tag | _] = enum_props.ordered_tags | ||
%{name_atom: name_atom, fnum: fnum} = enum_props.field_props[first_tag] | ||
value == name_atom or value == fnum | ||
end |
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.
I tried this on Protobuf.Encoder and it broke conformance tests, despite the fact that in the docs it seems like this is the expected behaviour there as well (just as we skip 0
for non-optional integers, I'd expect it to skip the default enum value...)
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.
I'll investigate this further
I think it's okay to be reviewed, @whatyouhide :) |
Actually, I found that there are conformance tests for text encoding. I'll work on them. |
This PR introduces support for encoding Protobuf messages into the textproto format.
Motivation
The primary motivation for this feature is to improve the ability to inspect and visualize Protobuf messages, while still conforming to some standard. The inspect protocol default implementation can be painful to work with large or complex structures. Finding the relevant, non-default fields in a inspected struct is not intuitive and takes an unnecessary amount of time. A textproto representation provides a human-readable alternative that is much closer to the actual data transmitted over the wire (specially when using transformers).
This implementation
and tab size areis configurable.Google.Protobuf.Any
.Future Considerations
I'm open to extending this implementation in the future to include:
Google.Protobuf.Any
.