jsoncons icon indicating copy to clipboard operation
jsoncons copied to clipboard

Add support for CDDL

Open lrosenthol opened this issue 4 years ago • 4 comments
trafficstars

Describe the proposed feature

CDDL is the notational convention for describing CBOR data structures (https://datatracker.ietf.org/doc/html/rfc8610) - think JSON Schema for CBOR - though it is also useful for JSON as well.

What other libraries (C++ or other) have this feature?

None :(. This page (https://github.com/cbor-wg/cddl/issues/29) tracks implementations and there seem to be none in C/C++. So you could be the first!

lrosenthol avatar Jun 16 '21 00:06 lrosenthol

It's on the list. It may take a while, though.

danielaparker avatar Jun 20 '21 15:06 danielaparker

You might find this interesting/useful - it's Python that produces C code based on a CDDL description - https://github.com/NordicSemiconductor/cddl-gen

lrosenthol avatar Jun 25 '21 14:06 lrosenthol

I think before looking at CDDL I need to revisit some aspects of the CBOR implementation. Currently it transforms CBOR events into jsoncons events during parsing, feeding those events into a json_visitor. I think I need another layer so we have a cbor_visitor that is first to receive raw CBOR events, and which users can intercept if they wish. I think I also need a big_decimal class for subsequent mapping of CBOR big decimal numbers. Other languages have this easier, standard C++ lacks so many types, no big integer, no big decimal, no portable int128, no portable float128. I'll probably get to CBOR Diagnostic Notation before CDDL.

danielaparker avatar Jul 01 '21 17:07 danielaparker

I think I need another layer so we have a cbor_visitor that is first to receive raw CBOR events, and which users can intercept if they wish.

That would indeed be helpful for a number of cases.

I think I also need a big_decimal class for subsequent mapping of CBOR big decimal numbers.

Yes and others, as you note. It's also important to make sure that the original CBOR type is available to this new cbor_visitor to improve handling of custom tags or simply adding support for other types not natively supported in jsoncons.

I'll probably get to CBOR Diagnostic Notation before CDDL.

That works for me!

lrosenthol avatar Jul 01 '21 17:07 lrosenthol