Open oliviermartin opened 5 years ago
I might have understood where my confusion comes from. But it is still unclear...
The CDDL specification mentions "group" in a "map" or "array" context. So I guess in this case the "group" is a kind of virtual representation that could be used independently in a map or array context and would adapt to the parent type (ie: "map" or "array").
But I also interpreted "group" could potentially be used by itself and representing a serialised data representation.
Example:
identity = (
age: int,
name: tstr,
)
would be represented in CBOR as CBORTypeInt|IntValue|CBorTypeTstr|TstrValue
. So not encapsulated in an array and no key.
Ultimately, a CDDL spec defines a type (which is named by the name of the first rule in the spec). While top-level groups have been discussed, they are not part of CDDL 1.0. A potential extension for the next CDDL version might allow a top-level group to specify not a type for a single data items but a group for a sequence of data items, which would be interpreted as in array context.
(A related issue is whether there should be a way to use a group in an array as a sequence of pairs. Again, a potential extension for the next CDDL version.)
Oh, and your specific example has a spurious "identity" in the second code block. If you define identity as a map as in the third code block, you could write
dog = {
~identity,
leash-length: float,
}
to achieve the same effect the example has now (the map type identity
is "unwrapped" by the ~
operator). This gets quite close to what inheritance/mixins are often used for in object-oriented languages.
Considering this example from "Figure 4: Using a group for factorization":
Is it equivalent to?
{...}
being a map, I would think so. But the syntax is a bit confusing. I find the(...)
a bit confusing. It can represent a group, choice/enum, substitution (in the case above).It would have been more logic to define identity as:
A CDDL tool could check if we could only substitute map inside a map. Or group inside a group.