Skip to content

Commit

Permalink
Merge #50
Browse files Browse the repository at this point in the history
50: gen-prost-serde: add missing pbjson-build options r=neoeinstein a=torkelrogstad

Fixes #49

Literally my first time writing Rust code, so might be something obvious I've missed. Happy to fix any issues, if you point me in the right direction!

Co-authored-by: Torkel Rogstad <torkel@rogstad.io>
  • Loading branch information
bors[bot] and torkelrogstad authored Feb 24, 2023
2 parents 39faedb + 398935b commit 0571a5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions protoc-gen-prost-serde/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ from that crate:
* `extern_path=<proto_path>=<rust_path>`: [extern_path](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.extern_path)
* `retain_enum_prefix(=<boolean>)`: [retain_enum_prefix](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.retain_enum_prefix)
* `preserve_proto_field_names=(<boolean>)`: `[preserve_proto_field_names](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.preserve_proto_field_names)
* `ignore_unknown_fields=(<boolean>)`: `[ignore_unknown_fields](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.ignore_unknown_fields)
* `emit_fields=(<boolean>)`: `[emit_fields](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.emit_fields)
* `use_integers_for_enums=(<boolean>)`: `[use_integers_for_enums](https://docs.rs/pbjson-build/latest/pbjson_build/struct.Builder.html#method.use_integers_for_enums)

In addition, the following options can also be specified:

Expand Down
36 changes: 36 additions & 0 deletions protoc-gen-prost-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct Parameters {
extern_path: Vec<(String, String)>,
retain_enum_prefix: bool,
preserve_proto_field_names: bool,
ignore_unknown_fields: bool,
emit_fields: bool,
use_integers_for_enums: bool,
no_include: bool,
}

Expand All @@ -60,6 +63,18 @@ impl Parameters {
builder.preserve_proto_field_names();
}

if self.ignore_unknown_fields {
builder.ignore_unknown_fields();
}

if self.emit_fields {
builder.emit_fields();
}

if self.use_integers_for_enums {
builder.use_integers_for_enums();
}

builder
}
}
Expand Down Expand Up @@ -99,6 +114,27 @@ impl str::FromStr for Parameters {
param: "preserve_proto_field_names",
value: "false",
} => (),
Param::Parameter {
param: "ignore_unknown_fields",
}
| Param::Value {
param: "ignore_unknown_fields",
value: "true",
} => ret_val.ignore_unknown_fields = true,
Param::Parameter {
param: "emit_fields",
}
| Param::Value {
param: "emit_fields",
value: "true",
} => ret_val.emit_fields = true,
Param::Parameter {
param: "use_integers_for_enums",
}
| Param::Value {
param: "use_integers_for_enums",
value: "true",
} => ret_val.use_integers_for_enums = true,
Param::Parameter {
param: "no_include",
}
Expand Down

0 comments on commit 0571a5a

Please sign in to comment.