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

Add API to encode bytestreams as references #278

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

matetothpal
Copy link
Contributor

This PR Introduces a new set of APIs for adding bytes to an encoded CBOR in a way that those bytes are not copied to the result buffer that is provided to the encoding context. Using any of the new APIs for adding data to a CBOR makes the QCBOREncode_Finish return an error, as the result buffer is not containing a valid CBOR in this case. Instead a new API is introduced to copy the encoded data in chunks to a user provided buffer.

The motivation for this PR is to be able to use QCBOR in constrained systems where there are large binary data blobs that need to be inserted in CBOR object. The data blobs are allocated outside, and for example mapped in the address space of the constrained system, but it doesn't have big enough memory of its own to hold the copy of the blobs.

This PR contains the new APIs, and some tests to validate the implementation. The change only affects the encoder implementation, it has no impact on the decoding side.

I added some documentation to the code to explain the usage of the new APIs, and explain how the references are stored and how the encoded CBOR is reconstructed using the references.

I'm not sure what would be the best terminology to be used for the new method of adding data to the CBOR. The APIs use the word 'external', like QCBOREncode_Private_AddExternalBuffer, but using the word reference may sound good as well, like QCBOREncode_Private_AddBufferReference.

Add API to encode bytestreams so that the encoder context only contains
references to the data instead of explicitly copying it into the
encoding buffer.

This commit also adds documentation on the new APIs, and tests.

The commit has no impact on the decoding.

Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
Change-Id: If5f74a61f5eca48b89017ec5f3dee9e4e5c05920
@soby-mathew
Copy link

Would be a very useful change to avoid allocating intermediate buffers.

@laurencelundblade
Copy link
Owner

I'm planning to integrate this, but it begs the question of a streaming interface for all of encoding, so it won't happen right away.

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

Successfully merging this pull request may close these issues.

3 participants