Add API to encode bytestreams as references #278
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.