#cbor #diagnostics #binary-format #representation #notation #concise #hex

app cbor-diag-cli

用于在不同诊断编码之间转换 Concise Binary Object Representation (CBOR) 的工具

9 个版本

0.1.8 2023年5月26日
0.1.7 2022年9月10日
0.1.6 2022年6月12日
0.1.5 2020年8月1日
0.1.2 2019年9月20日

#539 in 解析器实现

MIT/Apache

150KB
3K SLoC

cbor-diag-cli

用于操作 Concise Binary Object Representation (CBOR) 的诊断工具。此工具可以解析 CBOR 项的二进制、十六进制和 诊断表示;然后将它们输出为二进制、十六进制(带或不带注释)和诊断表示(紧凑或“美观”)。

安装

目前 cbor-diag-cli 只通过 crates.io 分发,先安装 Rust 然后使用以下命令安装

> cargo install cbor-diag-cli
Updating crates.io index
[...]

> cbor-diag --help
cbor-diag 0.1.0
A utility for converting between binary, diagnostic, hex and annotated hex formats for CBOR.
[...]

示例

解析十六进制编码的有效负载到诊断表示

> cbor-diag --to diag <<-END
a26568656c6c6f65776f726c64a163796f756673686f756c64a165766973
6974d820781868747470733a2f2f63626f722e6e656d6f3135372e636f6d
END
{
    "hello": "world",
    { "you": "should" }: { "visit": 32_0("https://cbor.nemo157.com") },
}

解析十六进制编码的有效负载到带注释的十六进制

> cbor-diag --to annotated <<-END
a26568656c6c6f65776f726c64a163796f756673686f756c64a165766973
6974d820781868747470733a2f2f63626f722e6e656d6f3135372e636f6d
END
a2                                                           # map(2)
   65                                                        #   text(5)
      68656c6c6f                                             #     "hello"
   65                                                        #   text(5)
      776f726c64                                             #     "world"
   a1                                                        #   map(1)
      63                                                     #     text(3)
         796f75                                              #       "you"
      66                                                     #     text(6)
         73686f756c64                                        #       "should"
   a1                                                        #   map(1)
      65                                                     #     text(5)
         7669736974                                          #       "visit"
      d8 20                                                  #     uri, tag(32)
         78 18                                               #       text(24)
            68747470733a2f2f63626f722e6e656d6f3135372e636f6d #         "https://cbor.nemo157.com"
                                                             #       valid URL (checked against URL Standard, not RFC 3986)

将诊断表示输出为字节

> cbor-diag --to bytes <<-END | xxd
{"hello":"world","5 + 5 =": 10}
END
00000000: a265 6865 6c6c 6f65 776f 726c 6467 3520  .ehelloeworldg5
00000010: 2b20 3520 3d0a                           + 5 =.

依赖项

~9–23MB
~336K SLoC