-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcbor.rs
More file actions
78 lines (61 loc) · 2.08 KB
/
cbor.rs
File metadata and controls
78 lines (61 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*!
CBOR Tools - A CLI for working with CBOR data
This tool provides utilities for inspecting CBOR data and converting between
CBOR binary format and CBOR Diagnostic Notation (CDN).
# Commands
- `inspect`: Display CBOR data in various formats (CDN, JSON, hex)
- `compose`: Convert text formats (CDN, JSON) to CBOR binary
# Examples
```bash
# Inspect a CBOR file (CDN format - lossless)
cbor inspect bundle.cbor
# Inspect with embedded CBOR decoding (decodes byte strings as CBOR - useful for BPv7!)
cbor inspect -e bundle.cbor
# Inspect as JSON (lossy)
cbor inspect --format json data.cbor
# Inspect as hex dump
cbor inspect --format hex data.cbor
# Convert CDN to CBOR (default)
echo '[1, 2, h"deadbeef"]' | cbor compose -o data.cbor
# Convert JSON to CBOR
echo '{"name": "Alice", "age": 30}' | cbor compose --format json -o data.cbor
# Round-trip test
cbor inspect data.cbor | cbor compose | cbor inspect
```
*/
use clap::{Parser, Subcommand};
mod cdn;
mod compose;
mod inspect;
mod io;
/// A CLI tool for working with CBOR data
#[derive(Parser, Debug)]
#[command(
author,
version,
about = "A CLI tool for inspecting and manipulating CBOR data",
long_about = "CBOR Tools provides utilities for working with CBOR (Concise Binary Object Representation) data.\n\n\
Features:\n\
- Inspect CBOR data in human-readable formats\n\
- Convert between CBOR and CBOR Diagnostic Notation (CDN)\n\
- Lossless round-trip conversion (CBOR ↔ CDN)\n\
- Support for all CBOR features (tags, indefinite-length containers, etc.)"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
/// Available subcommands
#[derive(Subcommand, Debug)]
enum Commands {
/// Inspect and display CBOR data in various formats
Inspect(inspect::Command),
/// Convert CBOR Diagnostic Notation (CDN) to CBOR binary
Compose(compose::Command),
}
fn main() -> anyhow::Result<()> {
match Cli::parse().command {
Commands::Inspect(args) => args.exec(),
Commands::Compose(args) => args.exec(),
}
}