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
79
80
81
82
83
84
//! Concise Diagnostic Notation (CDN) input helpers and output re-exports.
use Vec;
use DeserializeOwned;
pub use crateError;
pub use crate;
/// Encodes one Concise Diagnostic Notation (CDN) item as CBOR bytes.
///
/// This accepts the formalized diagnostic input syntax from
/// `draft-ietf-cbor-edn-literals`: JSON-compatible values, CBOR byte strings
/// (`'..'`, `h'..'`, `b64'..'`), comments, optional separator commas,
/// embedded CBOR sequence literals (`<<..>>`), tags, simple values, the core
/// encoding indicators (`_i`, `_0` through `_3`, and indefinite arrays or
/// maps with `[_` / `{_`), and the application extensions implemented by this
/// crate. The built-in extensions include `dt`/`DT`, `ip`/`IP`, `b1`/`t1`,
/// `ilbs`/`ilts`, `bytes`, `same`, and `float`; enabling the `cdn` feature
/// also enables the `hash`, `cri`, and `CRI` extensions that require external
/// crates. The default encoding is preferred serialization.
///
/// Encoding indicators that carry no defined meaning here — the reserved
/// `_4` through `_7`, indicator words from future registrations, and the
/// bare `_` on an item that has no indefinite-length form — are accepted
/// and ignored, as the CDN draft requires of consumers.
///
/// Two inputs encode as the draft's provisional (CPA) placeholder tags
/// rather than as final data: an ellipsis (`...`) becomes the Diagnostic
/// Notation Ellipsis Tag 888, and an application-extension prefix this
/// crate does not implement becomes the Unresolved Application-Extension
/// Tag 999 wrapping the prefix and its arguments (`cri`/`CRI` similarly
/// use the provisional tag 99). These tag numbers may change when IANA
/// assigns final values; consumers that cannot process elided or
/// unresolved data should treat those tags as errors.
///
/// ```rust
/// let bytes = cbor2::cdn_to_vec(r#"{ /kty/ 1: 4, "kid": h'deadbeef' }"#).unwrap();
/// assert_eq!(cbor2::to_cdn(&bytes[..]).unwrap(), r#"{1: 4, "kid": h'deadbeef'}"#);
/// ```
/// Encodes a CDN sequence as a CBOR sequence.
///
/// Top-level items may be separated by commas or by blank space/comments.
/// This is the same sequence grammar used inside CDN's `<<..>>` embedded
/// CBOR literals, but without wrapping the result as a byte string.
/// Deserializes one CDN item into a serde value.
///
/// Borrowed output fields are not supported by this helper because the CDN
/// text is first encoded into owned CBOR bytes. Use [`cdn_to_vec`] and
/// then [`from_slice`](crate::from_slice) directly when you need control over
/// the encoded bytes.