From d589f9629e61e5afaa6b02d753a4aa998184d929 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Wed, 23 Aug 2023 21:34:06 -0700 Subject: [PATCH] make zero sized value limit adjustable --- rust/candid/src/de.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rust/candid/src/de.rs b/rust/candid/src/de.rs index 9dafbf15..cb17e0c2 100644 --- a/rust/candid/src/de.rs +++ b/rust/candid/src/de.rs @@ -28,6 +28,13 @@ impl<'de> IDLDeserialize<'de> { .with_context(|| format!("Cannot parse header {}", &hex::encode(bytes)))?; Ok(IDLDeserialize { de }) } + /// Create a new deserializer with IDL binary message. The config is used to adjust some parameters in the deserializer. + pub fn new_with_config(bytes: &'de [u8], config: Config) -> Result { + let mut de = Deserializer::from_bytes(bytes) + .with_context(|| format!("Cannot parse header {}", &hex::encode(bytes)))?; + de.zero_sized_values = config.zero_sized_values; + Ok(IDLDeserialize { de }) + } /// Deserialize one value from deserializer. pub fn get_value(&mut self) -> Result where @@ -100,6 +107,10 @@ impl<'de> IDLDeserialize<'de> { } } +pub struct Config { + zero_sized_values: usize, +} + macro_rules! assert { ( false ) => {{ return Err(Error::msg(format!(