Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Determine buffer size needed without encoding. #51

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

Conversation

sbertin-telular
Copy link

If a NULL buffer is passed to cn_cbor_encoder_write, it will determine the necessary size of the buffer without doing the encoding. The buf_size parameter can still set an upper limit on the size.

This should address issue #24.

If a NULL buffer is passed to cn_cbor_encoder_write, it will determine
the necessary size of the buffer without doing the encoding. The
buf_size parameter can still set an upper limit on the size.
@@ -125,7 +126,9 @@ CTEST(cbor, parse)
ASSERT_EQUAL(err.err, CN_CBOR_NO_ERROR);
ASSERT_NOT_NULL(cb);

enc_sz2 = cn_cbor_encoder_write(NULL, 0, sizeof(encoded), cb);
enc_sz = cn_cbor_encoder_write(encoded, 0, sizeof(encoded), cb);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If #49 is merged, the size passed here could change to enc_sz2 to also test that.

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

Successfully merging this pull request may close these issues.

1 participant