Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for decoding variable length arrays to cli #366

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/cli/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub enum InputFormat {
Stream,
StreamBase64,
StreamFramed,
VarArray,
VarArrayBase64,
}

impl Default for InputFormat {
Expand Down Expand Up @@ -107,6 +109,36 @@ 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)?;
}
}
InputFormat::VarArrayBase64 => {
use crate::$m::ReadXdr;
let mut dec = crate::$m::Limited::new(
base64::read::DecoderReader::new(&mut f, base64::STANDARD),
crate::$m::Limits::none(),
);
let len = u32::read_xdr(&mut dec)?;
for _ in 0..len {
let t = crate::$m::Type::read_xdr(r#type, &mut dec)?;
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 dec.read(&mut [0u8; 1])? != 0 {
Err(crate::$m::Error::Invalid)?;
}
}
};
}
Ok(())
Expand Down
Loading