cbor2-cli
The cbor command line tool for CBOR
(RFC 8949), built on the
cbor2 crate:
Or install it from the ldclabs Homebrew tap:
Usage: cbor [COMMAND] [INPUT]
Commands:
(none) Show each CBOR item as one line of diagnostic notation (§8)
decode Convert CBOR items to pretty-printed JSON, or to
pretty-printed diagnostic notation with --diag
encode Convert JSON values to CBOR items
INPUT is a file path, a hex string (optionally 0x-prefixed), a
base64/base64url string, or - for stdin; stdin is the default. An
argument containing a path separator is always a file path. Everything
streams: multiple JSON values become a CBOR sequence (RFC 8742), and a
CBOR sequence becomes one output document or line per item. Data errors
exit with status 1, usage errors with status 2.
Show: cbor
The everyday command. It renders each item as the human-readable text
form of RFC 8949 §8 — what CBOR specs and test vectors are written in —
and it is exact: every item is captured as its wire bytes, so
indefinite-length items keep their _ markers, segmented strings appear
as (_ ...), undefined and unassigned simple values appear as
themselves, byte strings render as h'...' and bignums print as plain
integers, exactly as in RFC 8949 Appendix A.
}
}
)
}
decode
cbor decode decodes each item into the data model and pretty-prints it
as JSON, or — with -d/--diag — as indented diagnostic notation.
Unlike the bare cbor, this re-spells the item (indefinite lengths and
non-preferred encodings are not preserved).
{
}
{
}
JSON conversion is best-effort where CBOR is richer: byte strings become
lowercase hex strings, non-string map keys are JSON-encoded into strings,
non-finite floats and undefined become null, integers beyond the
64-bit ranges become strings, and tags are dropped (keeping the inner
value).
encode
cbor encode reads JSON text (from a file or stdin) and writes each
value as a CBOR item:
| |
}
| |
License
Dual-licensed under MIT or the UNLICENSE.