Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoding a group with optional entry #25

Open
oliviermartin opened this issue Dec 9, 2018 · 1 comment
Open

Decoding a group with optional entry #25

oliviermartin opened this issue Dec 9, 2018 · 1 comment

Comments

@oliviermartin
Copy link

The current CDDL specification uses in "Figure 5: Personal Data: Example for extensibility" this example:

NameComponents = (
	? firstName: tstr,
	? familyName: tstr,
)

How do you know when parsing a CBOR buffer which tstr is which one if the CBOR buffer only contains one tstr?

The group as it does not use key, there is no way to identify which tstr is represented.

@cabo
Copy link
Contributor

cabo commented Dec 19, 2018

This group can be used in an array or a map. In a map, the keys tell you which of the group entries are present. In an array, you have no such information. The stickiness of PEG causes the first text string found to be matched to the firstName entry, and the second one to the familyName entry. In a way, the array works as if you had written

NameComponents = (
    ? (firstName: tstr,
    ? familyName: tstr)
)

which may be a better way to write it as it exposes the semantics more visibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants