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

Storing fixed sized strings in parsed C struct #368

Open mkschreder opened 9 months ago

mkschreder commented 9 months ago

Is it possible to instruct zcbor to store string data as value in generated structure instead of just a pointer?

It would be convenient to avoid dependency on the CBOR binary blob sometimes and to have everything within the C data structure instead.

oyvindronningstad commented 8 months ago

zcbor is built to not use malloc, so acheiving this would require some choices regarding memory management. Maybe the answer is to have a callback for allocating memory. In case I find time for this, what sort of context are you working in? Constrained, or would malloc be fine?

mkschreder commented 8 months ago

be

I think it would be nice if it was possible to set maximum text size in CDDL using an attribute like .size and then reserving this space in the C struct. Not ideal but would be good to have this possibility where one does not want to store the blob side by side with parsed data.

Also, for the case using malloc it would be good to allow custom allocator so that it is possible to allocate them in a slab or a custom heap.