NordicSemiconductor / zcbor

Low footprint C/C++ CBOR library and Python tool providing code generation from CDDL descriptions.
Apache License 2.0
105 stars 34 forks source link

How does decoding unordered maps work? #411

Open mkschreder opened 4 months ago

mkschreder commented 4 months ago

It seems that current code generator is still outputting code that expects map keys in the exact order that they are defined in cddl.

Type = {
   key_a: int,
   key_b: int
}

The code generated from this will be a long if statement where the fields are in exact order with && between. So decoding in any order does not work.

Is there a workaround for this?

oyvindronningstad commented 4 months ago

No, the code generator does not yet use the unordered maps API, but this is planned to be implemented soon-ish.

mkschreder commented 4 months ago

I think it's really important because the following passage of the specification does not hold true for the current decoder:

image

In the current implementation the map behaves like a list where all fields must come in exact order.