Skip to content

Commit

Permalink
Add decode to CBOR
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Sep 13, 2024
1 parent b551684 commit c1c179e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ clap = { version = "4.2.4", default-features = false, features = ["std", "derive
serde_json = { version = "1.0.89", optional = true }
thiserror = { version = "1.0.37", optional = true }
schemars = { version = "0.8.16", optional = true }
serde_cbor = { version = "0.11.2", optional = true }

[dev-dependencies]
serde_json = "1.0.89"
Expand All @@ -50,7 +51,7 @@ arbitrary = ["std", "dep:arbitrary"]
hex = []

# Features for the CLI.
cli = ["std", "curr", "next", "base64", "serde", "serde_json", "schemars", "dep:clap", "dep:thiserror"]
cli = ["std", "curr", "next", "base64", "serde", "serde_json", "schemars", "dep:clap", "dep:thiserror", "dep:serde_cbor"]

[package.metadata.docs.rs]
all-features = true
Expand Down
6 changes: 6 additions & 0 deletions src/cli/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum Error {
ReadFile(#[from] std::io::Error),
#[error("error generating JSON: {0}")]
GenerateJson(#[from] serde_json::Error),
#[error("error generating CBOR: {0}")]
GenerateCbor(#[from] serde_cbor::Error),
}

#[derive(Args, Debug, Clone)]
Expand Down Expand Up @@ -66,6 +68,7 @@ pub enum OutputFormat {
JsonFormatted,
RustDebug,
RustDebugFormatted,
Cbor,
}

impl Default for OutputFormat {
Expand Down Expand Up @@ -158,6 +161,9 @@ impl Cmd {
OutputFormat::JsonFormatted => println!("{}", serde_json::to_string_pretty(v)?),
OutputFormat::RustDebug => println!("{v:?}"),
OutputFormat::RustDebugFormatted => println!("{v:#?}"),
OutputFormat::Cbor => {
serde_cbor::to_writer(std::io::stdout(), v).map_err(Error::GenerateCbor)?
}
}
Ok(())
}
Expand Down

0 comments on commit c1c179e

Please sign in to comment.