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

Provide an encoder interface for known-size arrays and maps #241

Open
BrianSipos opened this issue Jun 25, 2024 · 1 comment
Open

Provide an encoder interface for known-size arrays and maps #241

BrianSipos opened this issue Jun 25, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@BrianSipos
Copy link
Contributor

The current interface with paired functions like QCBOREncode_OpenArray() and QCBOREncode_CloseArray() use a late insertion of the array head during close when the size of the array is known by the encoder. This requires the use of memory insertion and memmove() though.

In cases where the size of an definite-length array or map is known by the application before opening it, could there be a public function to write the size immediately at open?

Something like

void QCBOREncode_OpenArrayDefiniteLength(QCBOREncodeContext *pMe, size_t length);

This wouldn't be a change in capability of the encoder, just one of efficiency if the length is known at time of opening. The existing bookkeeping of number of items actually encoded could still be checked against this definite length so that an error occurs at CloseArray if the actual differed from the open length. Because it's not a difference of capability this is just a wishlist request.

@laurencelundblade
Copy link
Owner

Hi Brian, it's a good idea and happy to have it on the list. May take a while to get to it.

Do you have any specific issues with the memmove? For example, is it a performance issue with really large CBOR structures?

It could also be a part of make the object code of the encoder smaller.

@laurencelundblade laurencelundblade added the enhancement New feature or request label Jun 27, 2024
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