Skip to content

Commit

Permalink
Add support for decoding variable length arrays to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed May 9, 2024
1 parent da0cbc6 commit 9438e82
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/cli/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum InputFormat {
Stream,
StreamBase64,
StreamFramed,
VarArray,
}

impl Default for InputFormat {
Expand Down Expand Up @@ -107,6 +108,19 @@ macro_rules! run_x {
self.out(&t?)?;
}
}
InputFormat::VarArray => {
use crate::$m::ReadXdr;
let len = u32::read_xdr(&mut f)?;
for _ in 0..len {
let t = crate::$m::Type::read_xdr(r#type, &mut f)?;
self.out(&t)?;
}
// Check that any further reads, such as this read of one byte, read no
// data, indicating EOF. If a byte is read the data is invalid.
if f.read(&mut [0u8; 1])? != 0 {
Err(crate::$m::Error::Invalid)?;
}
}
};
}
Ok(())
Expand Down

0 comments on commit 9438e82

Please sign in to comment.