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

Support minimum represented value in generated for known integer sizes #293

Open
jnz86 opened this issue Jan 17, 2023 · 3 comments
Open
Labels
enhancement New feature or request

Comments

@jnz86
Copy link

jnz86 commented Jan 17, 2023

In my cddl: "d" => uint 0..100

Later in the generated types.h: uint32_t d;

Any way to limit the size in the generated structure? It seems wasteful to generate a uint32_t for something we know will not be decoded if it's not within size uint8_t.

I get that the decoder may try and use this memory and the default int type of cbor can use all 32bits. But, wouldn't this be rather easy to handle if the decoding step went to a temporary first and was stored into the smaller type if it met the conditions?

@jnz86
Copy link
Author

jnz86 commented Jan 21, 2023

Perhaps even more egregious in terms of memory usage is this for optional ? values

CDDL: ?bool_value : "b" => bool,

Generated header:

struct header_bstr_bool_value bool_value;       // Structure that defines with a single bool member
uint_fast32_t bool_value_present;               // Bool used elsewhere, but an obvious case for one is uint32?

@oyvindronningstad
Copy link
Collaborator

Hi, this has been changed for _present values. Integers may not be changed, at least not for a while, since it requires more changes to pull off.

@jnz86
Copy link
Author

jnz86 commented Jan 9, 2024

Confirmed, there are bools for present. As to the others, I'm not in a hurry, it would just be a nice change to see uint8_t over uint32_t for something that can only store a few options.

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

No branches or pull requests

2 participants