You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: draft-mcnally-deterministic-cbor.md
+50-45Lines changed: 50 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,15 +70,12 @@ This document's goal is to specify such a set of norms and practices for dCBOR c
70
70
71
71
It is important to stress that dCBOR is *not* a new dialect of CBOR, and that all dCBOR is well-formed CBOR that can be read by existing CBOR codecs.
72
72
73
-
Nonetheless, many existing implementations give little or no guidance at the API level as to whether the CBOR being read conforms to the dCBOR specification, for example by emitting errors or warnings at deserialization time. Conversely, many existing implementations do not carry any burden of ensuring that CBOR is serialized in conformance with the dCBOR specification, again putting that burden on developers.
74
-
75
-
The authors of this document believe that for applications where dCBOR correctness is important, the codec itself should carry as much of this burden as possible. This is important both to minimize cognitive load during development, and help ensure interoperability between implementations.
76
-
77
-
This document is segmented into three categories. They include norms and practices that:
73
+
This document is segmented into four sections. They include norms and practices that:
78
74
79
75
* MUST be implemented in the codec (Serialization level),
80
76
* MUST be implemented by developers of specifications dependent on dCBOR (Application level).
81
77
* are acknowledged to fall under the purview of this document, but which are not yet specified (Future work).
78
+
* are RECOMMENDED for dCBOR codec implementors (Recommendations).
82
79
83
80
# Terminology
84
81
@@ -93,7 +90,7 @@ codec
93
90
: "coder-decoder", a software suite that both encodes (serializes) and decodes (deserializes) a data format.
94
91
95
92
dCBOR
96
-
: "deterministic CBOR" encoded in conformance with the CBOR specifications §4.2 {{-CBOR}}.
93
+
: "deterministic CBOR" encoded in conformance with the CBOR specification in this document.
97
94
98
95
insert/extract
99
96
: To convert platform-native or application-centric data structures to/from an in-memory symbolic representation of CBOR.
@@ -105,14 +102,6 @@ serialize/deserialize
105
102
106
103
This section defines requirements and practices falling in the purview of the dCBOR codec.
107
104
108
-
## General Practices for dCBOR Codecs
109
-
110
-
dCBOR codecs SHOULD:
111
-
112
-
* Make it easy to emit compliant dCBOR.
113
-
* Make it hard to emit non-compliant dCBOR.
114
-
* Make it an error to read non-compliant dCBOR.
115
-
116
105
## Base Requirements
117
106
118
107
dCBOR encoders MUST only emit CBOR conforming to the requirements of {{-CBOR}} §4.2.1. To summarize:
@@ -159,37 +148,6 @@ Because of this incompatibility between the CBOR and standard representations, d
159
148
160
149
Implementations that support BIGNUM are able to encode and decode this value as BIGNUM.
161
150
162
-
## API Handling of Maps
163
-
164
-
dCBOR APIs SHOULD provide a dCBOR `Map` structure or similar that models the dCBOR canonical key encoding and order.
165
-
166
-
* Supports insertion of unencoded key-value pairs.
167
-
* Supports iteration through entries in dCBOR canonical key order.
168
-
* Supports treating keys as duplicate that have identical dCBOR encodings, e.g., `10` and `10.0`.
169
-
170
-
The dCBOR decoder MUST return an error if it encounters misordered or duplicate map keys.
171
-
172
-
## API Handling of Numeric Values
173
-
174
-
The above requirements of this section deal with how dCBOR encoders MUST serialize numeric values, and how dCBOR decoders MUST validate them. It does not specify requirements for the API, but the authors do make the following recommendations:
175
-
176
-
* The encoder API SHOULD accept any supported numeric type for insertion into the CBOR stream. The CBOR encoder SHALL decide the dCBOR-conformant form for its encoding.
177
-
* The API SHOULD allow any supported numeric type to be extracted, and return errors when the actual type encountered is not representable in the requested type. For example,
178
-
* If the encoded value is "1.5" then requesting extraction of the value as floating point will succeed but requesting extraction as an integer will fail.
179
-
* Similarly, if the value has a large exponent and therefore can be represented as either a floating point value or a BigNum, then attempting to extract it as a machine integer will fail.
180
-
181
-
## Validation Errors
182
-
183
-
A dCBOR decoder MUST return errors when it encounters any of these conditions in the input stream. The error symbol names below are informative.
* `nonCanonicalNumeric`: An integer, floating-point value, or BigNum was encoded in non-canonical form
188
-
* `invalidString`: An invalid UTF-8 string was encountered
189
-
* `unusedData`: Unused data encountered past the expected end of the input stream
190
-
* `misorderedMapKey`: A map has keys not in canonical order
191
-
* `duplicateMapKey`: A map has a duplicate key
192
-
193
151
# Application Level
194
152
195
153
## Optional/Default Values
@@ -221,6 +179,53 @@ The following issues are currently left for future work:
221
179
222
180
* How to deal with subnormal floating point values {{SUBNORMAL}}.
223
181
182
+
# API-Level Recommendations
183
+
184
+
This section is informative.
185
+
186
+
Many existing CBOR implementations give little or no guidance at the API level as to whether the CBOR being read conforms to the CBOR specification for deterministic encoding {{-CBOR}} §4.2, for example by emitting errors or warnings at deserialization time. Conversely, many existing implementations do not carry any burden of ensuring that CBOR is serialized in conformance with the CBOR determinstic encoding specification, again putting that burden on developers.
187
+
188
+
The authors of this document believe that for applications where dCBOR correctness as specified in this document is important, the codec itself should carry as much of this burden as possible. This is important both to minimize cognitive load during development, and help ensure interoperability between implementations.
189
+
190
+
## General Practices for dCBOR Codecs
191
+
192
+
It is RECOMMENDED that dCBOR codecs:
193
+
194
+
* Make it easy to emit compliant dCBOR.
195
+
* Make it hard to emit non-compliant dCBOR.
196
+
* Make it an error to read non-compliant dCBOR.
197
+
198
+
## API Handling of Maps
199
+
200
+
It is RECOMMENDED that dCBOR APIs provide a dCBOR `Map` structure or similar that models the dCBOR canonical key encoding and order:
201
+
202
+
* Supports insertion of unencoded key-value pairs.
203
+
* Supports iteration through entries in dCBOR canonical key order.
204
+
* Supports treating keys as duplicate that have identical dCBOR encodings, e.g., `10` and `10.0`.
205
+
206
+
The dCBOR decoder SHOULD return an error if it encounters misordered or duplicate map keys.
207
+
208
+
## API Handling of Numeric Values
209
+
210
+
The authors do make the following recommendations:
211
+
212
+
* The encoder API SHOULD accept any supported numeric type for insertion into the CBOR stream and decide the dCBOR-conformant form for its encoding.
213
+
* The API SHOULD allow any supported numeric type to be extracted, and return errors when the actual type encountered is not representable in the requested type. For example,
214
+
* If the encoded value is "1.5" then requesting extraction of the value as floating point will succeed but requesting extraction as an integer will fail.
215
+
* Similarly, if the value has a large exponent and therefore can be represented as either a floating point value or a BigNum, then attempting to extract it as a machine integer will fail.
216
+
217
+
## Validation Errors
218
+
219
+
It is RECOMMENDED that a dCBOR decoder return errors when it encounters any of these conditions in the input stream:
0 commit comments