Skip to content

Commit

Permalink
fix: add the default value len when turn on the encode default value …
Browse files Browse the repository at this point in the history
…feature (#276)
  • Loading branch information
Ggiggle authored Oct 18, 2024
1 parent cddd656 commit 69f4396
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

5 changes: 4 additions & 1 deletion examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ fn test_pb_encode_zero_value() {
a.encode(&mut buf).unwrap();

println!("{:?}", buf);
println!("{:?}", buf.freeze().as_ref());
// println!("{:?}", buf.freeze().as_ref());

let parsed_a = zero_value::zero_value::A::decode(buf).unwrap();
println!("{:?}", parsed_a);
}
2 changes: 1 addition & 1 deletion pilota/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pilota"
version = "0.11.5"
version = "0.11.6"
edition = "2021"
description = "Pilota is a thrift and protobuf implementation in pure rust with high performance and extensibility."
documentation = "https://docs.rs/pilota"
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 @@ -1658,15 +1658,21 @@ macro_rules! map {
KL: Fn(u32, &K) -> usize,
VL: Fn(u32, &V) -> usize,
{
let mut skip_default_value = false;

Check warning on line 1661 in pilota/src/prost/encoding.rs

View workflow job for this annotation

GitHub Actions / clippy

value assigned to `skip_default_value` is never read

warning: value assigned to `skip_default_value` is never read --> pilota/src/prost/encoding.rs:1661:21 | 1661 | let mut skip_default_value = false; | ^^^^^^^^^^^^^^^^^^ ... 1693 | map!(BTreeMap); | -------------- in this macro invocation | = help: maybe it is overwritten before being read? = note: this warning originates in the macro `map` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 1661 in pilota/src/prost/encoding.rs

View workflow job for this annotation

GitHub Actions / clippy

value assigned to `skip_default_value` is never read

warning: value assigned to `skip_default_value` is never read --> pilota/src/prost/encoding.rs:1661:21 | 1661 | let mut skip_default_value = false; | ^^^^^^^^^^^^^^^^^^ ... 1689 | map!(AHashMap); | -------------- in this macro invocation | = help: maybe it is overwritten before being read? = note: this warning originates in the macro `map` (in Nightly builds, run with -Z macro-backtrace for more info)
#[cfg(feature = "pb-encode-default-value")]
{
skip_default_value = true;
}

key_len(tag) * values.len()
+ values
.iter()
.map(|(key, val)| {
let len = (if key == &K::default() {
let len = (if key == &K::default() && skip_default_value {
0
} else {
key_encoded_len(1, key)
}) + (if val == val_default {
}) + (if val == val_default && skip_default_value {
0
} else {
val_encoded_len(2, val)
Expand Down

0 comments on commit 69f4396

Please sign in to comment.