From 179496ac7d5bce2b5566277304a02040507266f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EB=AF=BC=EA=B7=9C?= <72372870+mingyuchi@users.noreply.github.com> Date: Mon, 5 Dec 2022 19:17:30 +0900 Subject: [PATCH 1/2] Do not omit zero values on fields containing oneof --- protobuf/src/reflect/dynamic/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protobuf/src/reflect/dynamic/mod.rs b/protobuf/src/reflect/dynamic/mod.rs index 96fa20216..a98553d54 100644 --- a/protobuf/src/reflect/dynamic/mod.rs +++ b/protobuf/src/reflect/dynamic/mod.rs @@ -229,7 +229,7 @@ impl DynamicMessage { RuntimeFieldType::Singular(..) => { if let Some(v) = field_desc.get_singular(self) { // Ignore default value for proto3. - if !is_proto3 || v.is_non_zero() { + if !is_proto3 || v.is_non_zero() || field_desc.containing_oneof() { handler.field(field_desc.proto().type_(), field_number, &v)?; } } From f0662cc4a8e6b255026badb83a3ffda7f0cce9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A7=80=EB=AF=BC=EA=B7=9C?= <72372870+mingyuchi@users.noreply.github.com> Date: Tue, 6 Dec 2022 10:09:24 +0900 Subject: [PATCH 2/2] Update mod.rs --- protobuf/src/reflect/dynamic/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protobuf/src/reflect/dynamic/mod.rs b/protobuf/src/reflect/dynamic/mod.rs index a98553d54..b5820aa20 100644 --- a/protobuf/src/reflect/dynamic/mod.rs +++ b/protobuf/src/reflect/dynamic/mod.rs @@ -229,7 +229,8 @@ impl DynamicMessage { RuntimeFieldType::Singular(..) => { if let Some(v) = field_desc.get_singular(self) { // Ignore default value for proto3. - if !is_proto3 || v.is_non_zero() || field_desc.containing_oneof() { + if !is_proto3 || v.is_non_zero() || field_desc.containing_oneof().is_some() + { handler.field(field_desc.proto().type_(), field_number, &v)?; } }