-
Notifications
You must be signed in to change notification settings - Fork 57
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
z_bytes_decode_into_string and z_bytes_encode_from_string are not symmetrical. #452
Comments
Same holds for slice too. But this was done on purpose to reduce amount of boilerplate code (and to stress that no extra allocation is required). Technically I would rather prefer to allow decoding into user provided buffer, with specified length (although similar behavior can already be achieved using z_bytes_reader). |
I think this doesn't stress the feature of "no-alllocation" enough. At least for me the existing naming doesn't make clear that the allocation doesn't happen. |
yes, this function just stores pointer (there is a _copy variant that makes a copy), but I meant no allocation in the sense that user does not have to create z_owned_string_t explicitly if he has const char (although he can always create z_view_string_t, which does not allocate - but this is more code to write). |
I think the primary thing to do is to rename |
Describe the release item
z_bytes_encode_from_string
requires null-terminated string, whilez_bytes_decode_into_string
don't add null to the end. In fact, the pair function for z_bytes_encode_from_string is z_bytes_decode_from_sllice.I'd propose to return previous behaviour and make
z_bytes_encode_from_string
take the loan ofz_owned_string_t
. And rename existingz_bytes_encode_from_string
to something which makes clear, that the parameter is null-terminatedRename also
z_bytes_serialize_from_silce
to..._from_buffer
as it actually accepts buffer and length, not our slice object. If needed, we can later add...from_slice
which accepts our slice.See also #451 about renaming these
The text was updated successfully, but these errors were encountered: