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
+28-6Lines changed: 28 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,7 +115,29 @@ dCBOR codecs MUST validate and return errors for any CBOR that is not conformant
115
115
116
116
## Reduction of Floating Point Values to Integers
117
117
118
-
While there is no requirement that dCBOR codecs implement support for floating point numbers, dCBOR codecs that do support them MUST reduce floating point values with no fractional part to the smallest integer value that can accurately represent it. If a numeric value has a fractional part or an exponent that takes it out of the range of representable integers, then it SHALL be encoded as a floating point value.
118
+
While there is no requirement that dCBOR codecs implement support for floating point numbers, dCBOR codecs that do support them MUST reduce floating point values with no fractional part to the integer value that can accurately represent it in the fewest bits. If a numeric value has a fractional part or an exponent that takes it out of the range of representable integers, then it SHALL be encoded as a floating point value. If it cannot be represented as a floating point value, then it SHALL be encoded as a BIGNUM by encoders that support them.
119
+
120
+
For the unsigned integers, from most to least preferred:
Float: [… -2^63 - 1 U 2^63 …] [… -9223372036854775809 U 9223372036854775808 …]
139
+
BIGNUM: [… -2^63 - 1 U 2^63 …] [… -9223372036854775809 U 9223372036854775808 …]
140
+
~~~
119
141
120
142
This practice still produces well-formed CBOR according to the standard, and all existing implementations will be able to read it. It does exclude a map such as the following from being validated as dCBOR, as it would have a duplicate key:
121
143
@@ -138,15 +160,15 @@ Similarly, encoders that support floating point MUST reduce all `+INF` values to
138
160
139
161
While there is no requirement that dCBOR codecs implement support for BigNums ≥ 2^64 (tags 2 and 3), codecs that do support them MUST use regular integer encodings where integers can represent the value.
140
162
141
-
## CBOR_NEGATIVE_INT_MAX disallowed
163
+
## 65-bit negative integers disallowed
142
164
143
-
The largest negative integer that can be represented in 64 bits two's complement (STANDARD_NEGATIVE_INT_MAX) is -2^63 (0x8000000000000000).
165
+
The largest negative integer that can be represented in 64-bit two's complement (STANDARD_NEGATIVE_INT_MAX) is -2^63 (0x8000000000000000).
144
166
145
-
However, the largest negative integer that can be represented in CBOR (CBOR_NEGATIVE_INT_MAX) is -2^64 (0x10000000000000000), which requires 65 bits. The CBOR encoding for CBOR_NEGATIVE_INT_MAX is 0x3BFFFFFFFFFFFFFFFF.
167
+
However, CBOR can encode negative integers as low as CBOR_NEGATIVE_INT_MAX, which is -2^64 (two's complement: 0x10000000000000000, CBOR: 0x3BFFFFFFFFFFFFFFFF). Negative integers in the range [CBOR_NEGATIVE_INT_MAX ... STANDARD_NEGATIVE_INT_MAX - 1] would require 65 bits, and are thus not representable in machine-sized integers.
146
168
147
-
Because of this incompatibility between the CBOR and standard representations, dCBOR disallows CBOR_NEGATIVE_INT_MAX: conformant encoders MUST never encode this sequence and conformant decoders MUST reject CBOR_NEGATIVE_INT_MAX as not well-formed.
169
+
Because of this incompatibility between the CBOR and standard representations, dCBOR disallows encoding negative integer values in the range [CBOR_NEGATIVE_INT_MAX ... STANDARD_NEGATIVE_INT_MAX - 1]: conformant encoders MUST never encode these values and conformant decoders MUST reject these values as invalid.
148
170
149
-
Implementations that support BIGNUM are able to encode and decode this value as BIGNUM.
171
+
Implementations that support BIGNUM are able to encode and decode these values as BIGNUM.
0 commit comments