dcSpark / cddl-codegen

Codegen serialization logic for CBOR automatically from a CDDL specification
MIT License
40 stars 14 forks source link

Single element array members are treated as multiple #121

Open rooooooooob opened 1 year ago

rooooooooob commented 1 year ago
foo = [
   single: [uint]
]

is treated as:

foo = [
   single: [* uint]
]

As per the CDDL RFC:

If no occurrence indicator is specified, the group entry is to occur exactly once (as if 1*1 were specified)

You can work around this by doing:

single_uint = [uint]
foo = [
   single: single_uint
]

but it's not ideal. Ideally the fix would make this totally invisible to end-users and have Foo::single be of type uint directly with the array part just being a serialization detail.

rooooooooob commented 8 months ago

210 addresses this for basic groups but the issue remains for other types e.g. [uint]. This is lower priority because the only time we've seen single element arrays like this in Cardano was for basic groups.