diff --git a/node/libs/protobuf/src/serde.rs b/node/libs/protobuf/src/serde.rs index 03fb1a54..1a2308fc 100644 --- a/node/libs/protobuf/src/serde.rs +++ b/node/libs/protobuf/src/serde.rs @@ -37,12 +37,24 @@ pub fn serialize(x: &T, s: S) -> Result>( d: D, +) -> Result { + deserialize_proto_with_options(d, true) +} + +/// Implementation of serde::Deserialize for arbitrary ReflectMessage with deny_unknown_fields option +pub fn deserialize_proto_with_options< + 'de, + T: ReflectMessage + Default, + D: serde::Deserializer<'de>, +>( + d: D, + deny_unknown_fields: bool, ) -> Result { let mut p = T::default(); - let options = prost_reflect::DeserializeOptions::new().deny_unknown_fields(false); + let options = prost_reflect::DeserializeOptions::new().deny_unknown_fields(deny_unknown_fields); let msg = prost_reflect::DynamicMessage::deserialize_with_options(p.descriptor(), d, &options)?; p.merge(msg.encode_to_vec().as_slice()).unwrap(); Ok(p)