quick-protobuf
quick-protobuf copied to clipboard
Default values not respected
For example:
syntax = "proto2";
...
required bool foo = 1 [default = true];
Generated rust code still defaults to false for field foo.
I assume you mean when doing MyMessage::default(). It looks like default values should be respected when deserializing a proto.
I don't know much about deserialization in this case but if the Default implementation doesn't respect the default value in the proto definition then the boolean will end up being false, hence it will be deserialized as false?
I guess what I'm asking is should the Default implementation follow the field definition in the proto file?
Minimal Reproducible Example
schema.proto:
syntax = "proto2";
message Foo {
required uint64 bar = 1;
optional bool baz = 2 [default = true];
}
main.rs:
pub mod schema;
fn main() {
let foo = schema::Foo{bar: 420, ..Default::default()};
print!("foo.bar: {} foo.baz: {}\n", foo.bar, foo.baz);
}
expected result:
$ cargo run
foo.bar: 420 foo.baz: true
observed result:
$ cargo run
foo.bar: 420 foo.baz: false
Oh, by the way I think #247 should solve this (as part of our implementation of field presence, we had to fix the impl Default system).