Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Debugging

This section provides an overview of the cbor_serialization debugging tools.

Diagnostic Notation

The CBOR diagnostic notation is a human-readable format defined in RFC8949, RFC8610 and RFC8742. It's based on JSON, but it's not compatible with it.

The toEdn API will decode CBOR bytes (including CBOR Sequences) into a string in diagnostic notation format:

# Decode the CBOR blob into Diagnostic Notation
doAssert CborBytes(encoded).toEdn() ==
  """{"cborrpc": "2.0", "method": "subtract", "params": [42, 3], "id": 1}"""

Deviation from JSON includes:

  • Non-finite floating-point: Infinity, -Infinity, NaN
  • Tags: tagNumer(tagValue), ex: 0("2013-03-21T20:04:00Z")
  • Byte strings: h'base16Value', ex: h'01020304'
  • Simple: simple(simpleValue), ex: simple(42)
  • Non-string map keys: {key: value}, ex: {1: 2}, {[1]: 2}, {{1: 2}: 3}
  • Indefinite length: Undercore + space after {, [; ex: {_ "a": "b"}, [_ 1, 2]
  • Sequences: Each CBOR is separated by ,; ex: 1, "a", [2, 3]