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

any and cbor-any are ignored when generating code #432

Open aangert opened 1 month ago

aangert commented 1 month ago

When generating code with zcbor code -c pet.cddl -d -e -t Pet --output-cmake ~/generated/pet any element of type any or cbor-any is ignored and missing in the generated struct. zcbor doesn't generate a warning about this

pet.cddl:

Pet = [
    name: [ +tstr ],
    missing: any,
    also_missing: cbor-any,
]

pet_types.h:

struct Pet {
    struct zcbor_string Pet_name_tstr[10];
    size_t Pet_name_tstr_count;
};
oyvindronningstad commented 2 weeks ago

That's the current way "any" works. Representing a decoded "any" object in code is complex so this hasn't been done yet. There's some work looking into this, so I will update here when that is merged.

In a pinch you can use a union with all the possible types.