-
Notifications
You must be signed in to change notification settings - Fork 533
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
Matching fields of builtin types? (string/int/etc) #145
Comments
Hi Lee, please provide some more background, as right now this seems more
like a serde question than Prost. Protobuf field defaults are specified
in the .proto file as a field annotation (see the protobuf language guide).
Also note that in proto3 all scalar types already have a default value.
- Dan
…On Mon, Jan 14, 2019 at 8:32 AM Lee Olayvar ***@***.***> wrote:
I'm trying to add default support for the Twirp JSON spec / Protobuf
compatibility. As far as I am aware, this means adding a default value to
every scalar type in Protobuf. In theory this should be simple to do with
Serde, but I'm having trouble applying an attribute to all fields of X
type. Eg:
conf.field_attribute("match strings", "#[serde(default_value = \"\")]");
The goal being that match strings would match Foo.bar and Foo.baz, if
they're of proto type string. How can this be done? I'm having trouble
making sense of the documentation for this use case.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/danburkert/prost/issues/145>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJx8u0EQxULDk-mX3WBosT9ExGd6yQYks5vDLEUgaJpZM4Z-rhG>
.
|
Hi, my trouble is in understanding Prost's ability to a Rust attribute to all Proto fields of a specific type. Eg, if I want to apply an Attribute to all |
That’s not currently possible.
- Dan
…On Mon, Jan 14, 2019 at 9:17 AM Lee Olayvar ***@***.***> wrote:
Hi, my trouble is in understanding Prost's ability to a Rust attribute to
all Proto fields of a specific type. Eg, if I want to apply an Attribute to
all string fields with Prost, how would I do that?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/danburkert/prost/issues/145#issuecomment-454085767>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJx8hYPD_rrOv1Ekg4mW1y4CsH5qS0_ks5vDLuNgaJpZM4Z-rhG>
.
|
Gotcha, appreciate the answer. Would you be opposed to PRs for that feature, if possible? The goal would be to apply attributes on fields based on the type; in this example that seems to be required to ensure that fields have default values when Serde serializes. Currently, without this feature, Serde is failing to serialize. As you mentioned, Proto specifies default values but serializing JSON to a Prost data structure will fail. It's worth noting that when I'm mentioning JSON, I'm referring to the Twirp JSON spec, which is a bit different than Protobuf encoded JSON, I believe. This is sort of irrelevant to the discussion, I just didn't want to confuse anyone. |
I'm trying to add default support for the Twirp JSON spec / Protobuf compatibility. As far as I am aware, this means adding a default value to every scalar type in Protobuf. In theory this should be simple to do with Serde, but I'm having trouble applying an attribute to all fields of X type. Eg:
The goal being that
match strings
would matchFoo.bar
andFoo.baz
, if they're of proto typestring
. How can this be done? I'm having trouble making sense of the documentation for this use case.The text was updated successfully, but these errors were encountered: