Skip to content

Commit

Permalink
decode option event arg
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <[email protected]>
  • Loading branch information
gregdhill committed Sep 7, 2020
1 parent af45c39 commit c1d3598
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ impl<T: System> EventsDecoder<T> {
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() {
Expand Down
14 changes: 14 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ pub enum EventArg {
Primitive(String),
Vec(Box<EventArg>),
Tuple(Vec<EventArg>),
Option(Box<EventArg>),
}

impl FromStr for EventArg {
Expand All @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit c1d3598

Please sign in to comment.