Skip to content

Commit

Permalink
make zero sized value limit adjustable
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Aug 24, 2023
1 parent aa51899 commit d589f96
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rust/candid/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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<T>(&mut self) -> Result<T>
where
Expand Down Expand Up @@ -100,6 +107,10 @@ impl<'de> IDLDeserialize<'de> {
}
}

pub struct Config {
zero_sized_values: usize,
}

macro_rules! assert {
( false ) => {{
return Err(Error::msg(format!(
Expand Down

0 comments on commit d589f96

Please sign in to comment.