From c1d3598d7cd71f621390a37da5273257fff1b346 Mon Sep 17 00:00:00 2001 From: Gregory Hill Date: Mon, 7 Sep 2020 10:33:37 +0100 Subject: [PATCH] decode option event arg Signed-off-by: Gregory Hill --- src/events.rs | 11 +++++++++++ src/metadata.rs | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/events.rs b/src/events.rs index 9a05de14cc5..e8ae9146c50 100644 --- a/src/events.rs +++ b/src/events.rs @@ -154,6 +154,17 @@ impl EventsDecoder { self.decode_raw_bytes(&[*arg.clone()], input, output)? } } + EventArg::Option(arg) => { + match input.read_byte()? { + 0 => (), + 1 => self.decode_raw_bytes(&[*arg.clone()], input, output)?, + _ => { + return Err(Error::Other( + "unexpected first byte decoding Option".into(), + )) + } + } + } EventArg::Tuple(args) => self.decode_raw_bytes(args, input, output)?, EventArg::Primitive(name) => { let result = match name.as_str() { diff --git a/src/metadata.rs b/src/metadata.rs index 3ef160cfc93..ee32301acbe 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -398,6 +398,7 @@ pub enum EventArg { Primitive(String), Vec(Box), Tuple(Vec), + Option(Box), } impl FromStr for EventArg { @@ -413,6 +414,15 @@ impl FromStr for EventArg { "Expected closing `>` for `Vec`", )) } + } else if s.starts_with("Option<") { + if s.ends_with('>') { + Ok(EventArg::Option(Box::new(s[7..s.len() - 1].parse()?))) + } else { + Err(ConversionError::InvalidEventArg( + s.to_string(), + "Expected closing `>` for `Option`", + )) + } } else if s.starts_with('(') { if s.ends_with(')') { let mut args = Vec::new(); @@ -439,6 +449,10 @@ impl EventArg { match self { EventArg::Primitive(p) => vec![p.clone()], EventArg::Vec(arg) => arg.primitives(), + EventArg::Option(arg) => { + println!("event: {:?}", arg); + arg.primitives() + } EventArg::Tuple(args) => { let mut primitives = Vec::new(); for arg in args {