Skip to content

Commit b408e6a

Browse files
authored
Merge pull request #6 from cabo/more-text-about-maps
More fully address #5
2 parents c0bfe4b + 68fcc9b commit b408e6a

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

draft-mcnally-deterministic-cbor.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,31 @@ dCBOR implementations that support floating point numbers:
149149

150150
1. MUST check whether floating point values to be encoded have the numerically equal value in `DCBOR_INT` as defined above. If that is the case, it MUST be converted to that numerically equal integer value before encoding it. (Preferred encoding will then ensure the shortest length encoding is used.) If a floating point value has a non-zero fractional part, or an exponent that takes it out of `DCBOR_INT`, the original floating point value is used for encoding. (Specifically, conversion to a CBOR bignum is never considered.)
151151

152-
This also means that the three representations of a zero number in CBOR (`0`, `0.0`, `-0.0` in diagnostic notation) are all reduced to the basic integer `0` (with preferred encoding `0x00`).
152+
This also means that the three representations of a zero number in CBOR (`0`, `0.0`, `-0.0` in diagnostic notation) are all reduced to the basic integer `0` (with preferred encoding `0x00`).
153+
154+
{:aside}
155+
> Note that numeric reduction means that some maps that are valid CDE/CBOR cannot be reduced to valid dCBOR maps, as numeric reduction can result in multiple entries with the same keys ("duplicate keys"). For example, the following is a valid CBOR/CDE map:
156+
>
157+
> ~~~ cbor-diag
158+
> {
159+
> 10: "ten",
160+
> 10.0: "floating ten"
161+
> }
162+
> ~~~
163+
> {: title="Valid CBOR data item with numeric map keys (also valid CDE)"}
164+
>
165+
> Applying numeric reduction to this map would yield the invalid map:
166+
>
167+
> ~~~ cbor-diag
168+
> { / invalid: multiple entries with the same key /
169+
> 10: "ten",
170+
> 10: "floating ten"
171+
> }
172+
> ~~~
173+
> {: title="Numeric reduction turns valid CBOR invalid"}
174+
>
175+
> In general, dCBOR applications need to avoid maps that have entries with keys that are semantically equivalent in dCBOR's numeric model.
153176

154-
Note that numeric reduction means that some valid CDE/CBOR maps are not valid dCBOR maps, as numeric reduction can result in duplicate keys. For example, the following is a valid CBOR/CDE map, but would be rejected as invalid by a dCBOR decoder because the value `10.0` is not a valid dCBOR encoding:
155-
156-
~~~ cbor-diag
157-
{
158-
10: "ten",
159-
10.0: "floating ten"
160-
}
161-
~~~
162177

163178
2. MUST reduce all encoded NaN values to the quiet NaN value having the half-width CBOR representation `0xf97e00`.
164179
{:start="2"}

0 commit comments

Comments
 (0)