Skip to content

Commit

Permalink
feat: support encode zero value in protobuf to adjust to go proto2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ggiggle committed Oct 17, 2024
1 parent f899030 commit 9bc3832
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
42 changes: 41 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["pilota", "pilota-build", "pilota-thrift-parser"]
members = ["pilota", "pilota-build", "pilota-thrift-parser", "examples"]
resolver = "2"

[profile.bench]
Expand Down
1 change: 1 addition & 0 deletions pilota/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ rand = "0.8"

[features]
unstable = []
pb-encode-zero-value = []

[[bench]]
name = "faststr"
Expand Down
10 changes: 8 additions & 2 deletions pilota/src/prost/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,14 @@ macro_rules! map {
VL: Fn(u32, &V) -> usize,
{
for (key, val) in values.iter() {
let skip_key = key == &K::default();
let skip_val = val == val_default;
let mut skip_key = key == &K::default();
let mut skip_val = val == val_default;

#[cfg(feature = "pb-encode-zero-value")]
{
skip_key = false;
skip_val = false;
}

let len = (if skip_key { 0 } else { key_encoded_len(1, key) })
+ (if skip_val { 0 } else { val_encoded_len(2, val) });
Expand Down

0 comments on commit 9bc3832

Please sign in to comment.