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
+71-16Lines changed: 71 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,9 +80,9 @@ This application profile is intended to be used in conjunction with an applicati
80
80
81
81
## Base Requirements
82
82
83
-
dCBOR encoders MUST only emit CBOR conforming to the requirements "Core Deterministic Encoding Requirements" of {{-CBOR}} §4.2.1.
83
+
dCBOR encoders MUST only emit CBOR conforming to the requirements "Core Deterministic Encoding Requirements" of {{-CBOR}} §4.2.1. To summarize,
84
84
85
-
To summarize, dCBOR codecs:
85
+
dCBOR encoders:
86
86
87
87
1. MUST encode variable-length integers using the shortest form possible.
88
88
2. MUST encode floating-point values using the shortest form that preserves the value.
@@ -91,26 +91,48 @@ To summarize, dCBOR codecs:
91
91
92
92
In addition, dCBOR decoders:
93
93
94
-
5\. MUST validate and return errors for any encoded CBOR that is not conformant to any part of this specification.
94
+
5. MUST reject any variable length integers that are not encoded in the shortest form possible.
95
+
{:start="5"}
96
+
6. MUST reject any floating-point values that are not encoded in the shortest form that preserves the value.
97
+
{:start="6"}
98
+
7. MUST reject any indefinite-length arrays or maps.
99
+
{:start="7"}
100
+
8. MUST reject any maps whose keys are not sorted in bytewise lexicographic order of their deterministic encodings.
101
+
{:start="8"}
95
102
96
103
## Duplicate Map Keys
97
104
98
105
Standard CBOR {{-CBOR}} defines maps with duplicate keys as invalid, but leaves how to handle such cases to the implementor (§2.2, §3.1, §5.4, §5.6).
99
106
100
-
dCBOR codecs:
107
+
dCBOR encoders:
101
108
102
109
1. MUST NOT emit CBOR that contains duplicate map keys.
110
+
111
+
dCBOR decoders:
112
+
103
113
2. MUST reject encoded maps with duplicate keys.
114
+
{:start="2"}
104
115
105
116
## Numeric Reduction
106
117
107
118
dCBOR codecs that support floating point numbers (CBOR major type 7):
108
119
109
-
1. MUST reduce floating point values with no fractional part to the shortest integer encoding that can accurately represent it.
110
-
2. MUST reduce floating point values with a non-zero fractional part to the shortest floating point encoding that can accurately represent it.
111
-
3. MUST support floating point {{IEEE754}} binary16 as the most-preferred encoding for floating point values, followed by binary32, then binary64.
120
+
1. MUST support floating point {{IEEE754}} binary16 as the most-preferred encoding for floating point values, followed by binary32, then binary64.
121
+
122
+
dCBOR encoders that support floating point numbers:
123
+
124
+
2. MUST reduce floating point values with no fractional part to the shortest integer encoding that can accurately represent them.
125
+
{:start="2"}
126
+
127
+
3. MUST reduce floating point values with a non-zero fractional part to the shortest floating point encoding that can accurately represent them.
128
+
{:start="3"}
129
+
130
+
dCBOR decoders that support floating point numbers:
112
131
113
-
This practice still produces well-formed CBOR according to the standard, and all existing generic decoders will be able to read it. It does exclude a map such as the following from being validated as dCBOR, even though it would be allowed in standard CBOR because:
132
+
4. MUST reject any encoded floating point values that are not encoded as the shortest encoding that can accurately represent them.
133
+
{:start="4"}
134
+
135
+
The above rules still produce well-formed CBOR according to the standard, and all existing generic decoders will be able to read it. It does exclude a map such as the following from being validated as dCBOR, even though it would be allowed in standard CBOR because:
114
136
115
137
* `10.0` is an invalid numeric value in dCBOR, and
116
138
* using the unsigned integer value `10` more than once as a map key is not allowed.
@@ -124,10 +146,16 @@ This practice still produces well-formed CBOR according to the standard, and all
124
146
125
147
### Reduction of Negative Zero
126
148
127
-
{{IEEE754}} defines a negative zero value `-0.0`. dCBOR codecs that support floating point:
149
+
{{IEEE754}} defines a negative zero value `-0.0`.
150
+
151
+
dCBOR encoders that support floating point:
128
152
129
153
1. MUST reduce all negative zero values to the integer value `0`.
154
+
155
+
dCBOR decoders that support floating point:
156
+
130
157
2. MUST reject any encoded negative zero values.
158
+
{:start="2"}
131
159
132
160
Therefore with dCBOR, `0.0`, `-0.0`, and `0` all encode to the same canonical single-byte value `0x00`.
133
161
@@ -138,22 +166,49 @@ Therefore with dCBOR, `0.0`, `-0.0`, and `0` all encode to the same canonical si
138
166
dCBOR encoders that support floating point:
139
167
140
168
1. MUST reduce all `NaN` values to the binary16 quiet `NaN` value having the canonical bit pattern `0x7e00`.
141
-
2. MUST reject any other encoded `NaN` values.
142
-
3. MUST reduce all `+INF` values to the binary16 `+INF` having the canonical bit pattern `0x7c00` and likewise with `-INF` to `0xfc00`.
143
-
4. MUST reject any encoded `INF` or `-INF` values other than these.
169
+
2. MUST reduce all `+INF` values to the binary16 `+INF` having the canonical bit pattern `0x7c00`.
170
+
3. MUST reduce all `-INF` values to the binary16 `-INF` having the canonical bit pattern `0xfc00`.
171
+
172
+
dCBOR decoders that support floating point:
173
+
174
+
4. MUST reject any encoded `NaN` values not having the canonical bit pattern `0x7e00`.
175
+
{:start="4"}
176
+
5. MUST reject any encoded `+INF` values not having the canonical bit pattern `0x7c00`.
177
+
{:start="5"}
178
+
6. MUST reject any encoded `-INF` values not having the canonical bit pattern `0xfc00`.
179
+
{:start="6"}
144
180
145
181
## 65-bit Negative Integers
146
182
147
-
The largest negative integer that can be represented in 64-bit two's complement (STANDARD_NEGATIVE_INT_MAX) is -2^63 (0x8000000000000000).
183
+
The largest negative integer that can be represented in 64-bit two's complement (`STANDARD_NEGATIVE_INT_MAX`) is -2<sup>63</sup> (`0x8000000000000000`).
184
+
185
+
However, standard CBOR major type 1 can encode negative integers as low as `CBOR_NEGATIVE_INT_MAX`, which is -2<sup>64</sup> (two's complement: `0x10000000000000000`, CBOR: `0x3BFFFFFFFFFFFFFFFF`).
148
186
149
-
However, standard CBOR major type 1 can encode negative integers as low as CBOR_NEGATIVE_INT_MAX, which is -2^64 (two's complement: 0x10000000000000000, CBOR: 0x3BFFFFFFFFFFFFFFFF).
187
+
Negative integers in the range \[`CBOR_NEGATIVE_INT_MAX` ... `STANDARD_NEGATIVE_INT_MAX` - 1\] require 65 bits of precision, and are thus not representable in typical machine-sized integers.
150
188
151
-
Negative integers in the range \[CBOR_NEGATIVE_INT_MAX ... STANDARD_NEGATIVE_INT_MAX - 1\] require 65 bits of precision, and are thus not representable in typical machine-sized integers.
189
+
Because of this incompatibility between standard CBOR and typical machine-size representations, dCBOR disallows encoding negative integer values in the range \[`CBOR_NEGATIVE_INT_MAX` ... `STANDARD_NEGATIVE_INT_MAX` - 1\].
152
190
153
-
Because of this incompatibility between standard CBOR and typical machine-size representations, dCBOR disallows encoding negative integer values in the range \[CBOR_NEGATIVE_INT_MAX ... STANDARD_NEGATIVE_INT_MAX - 1\]. dCBOR codecs:
191
+
dCBOR encoders:
154
192
155
193
1. MUST NOT encode these values as CBOR major type 1.
194
+
195
+
dCBOR decoders:
196
+
156
197
2. MUST reject these encoded major type 1 CBOR values.
198
+
{:start="2"}
199
+
200
+
## Simple Values
201
+
202
+
CBOR Major Type 7 includes the floating point values (`0xf7`, `0xfa`, `0xfb`) and also the "simple values" `false` (`0xf4`), `true` (`0xf5`), and `null` (`0xf6`).
203
+
204
+
dCBOR encoders:
205
+
206
+
1. MUST NOT encode major type 7 values other than `false`, `true`, `null`, and the floating point values.
207
+
208
+
dCBOR decoders:
209
+
210
+
2. MUST reject any encoded major type 7 values other than `false`, `true`, `null`, and the floating point values.
0 commit comments