Closed jnz86 closed 6 months ago
Is it ever going to be possible to use .size
on byte strings? It's been some time since 0.7.0 came out... Any movement towards 0.8.0?
Thanks for the report, apologies for the delay. This is a bug, and should be fixed in #375. Feel free to test and leave a review.
Confirmed working.
However... for CDDL:
nonce : "n" => bstr .size 12,
I think this is could be slightly better optimized to not be two conditionals that oddly check the size.
...
&& (((zcbor_tstr_expect(state, ((tmp_str.value = (uint8_t *)"n", tmp_str.len = sizeof("n") - 1, &tmp_str)))))
&& (zcbor_bstr_decode(state, (&(*result).nonce)))
&& ((((*result).nonce.len >= 12)
&& ((*result).nonce.len <= 12)) || (zcbor_error(state, ZCBOR_ERR_WRONG_RANGE), false)))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_map_end_decode(state))));
...
This does get to len == 12
but with steps.
I know that a couple of my bytestrings will be of specific size. So I used .size n on them which should be allowed, but there is an error with the generated code getting the structure members wrong.
CDDL:
Generated types file:
Generated decode:
Result:
It's not wrong.
some_label_m
is ofsome_label_s
type and notstruct zcbor_string
type directly, so it does not have a len member. It's like it was supposed to besome_label_m.s.len