diff --git a/Cargo.lock b/Cargo.lock index d1234507..0b3e5c47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -335,6 +335,46 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "examples" +version = "0.1.0" +dependencies = [ + "ahash", + "anyhow", + "criterion", + "dashmap", + "derivative", + "diffy", + "faststr", + "heck 0.5.0", + "itertools 0.13.0", + "linkedbytes", + "normpath", + "paste", + "petgraph", + "phf", + "pilota", + "pilota-build", + "pilota-thrift-parser", + "proc-macro2", + "protobuf-parse2", + "protobuf2", + "quote", + "rand", + "rayon", + "rustc-hash", + "salsa", + "scoped-tls", + "serde", + "serde_yaml", + "syn 2.0.67", + "tempfile", + "tokio", + "toml", + "tracing", + "tracing-subscriber", +] + [[package]] name = "fastrand" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index 741701d9..0b23b7a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["pilota", "pilota-build", "pilota-thrift-parser"] +members = ["pilota", "pilota-build", "pilota-thrift-parser", "examples"] resolver = "2" [profile.bench] diff --git a/pilota/Cargo.toml b/pilota/Cargo.toml index d54397b2..fcbbe987 100644 --- a/pilota/Cargo.toml +++ b/pilota/Cargo.toml @@ -41,6 +41,7 @@ rand = "0.8" [features] unstable = [] +pb-encode-zero-value = [] [[bench]] name = "faststr" diff --git a/pilota/src/prost/encoding.rs b/pilota/src/prost/encoding.rs index d8d3fab0..a8355624 100644 --- a/pilota/src/prost/encoding.rs +++ b/pilota/src/prost/encoding.rs @@ -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) });