-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Description
I would like to use a simple pattern to encode variable-length PDUs with an optimistic initial size estimate to avoid double-encoding under good conditions.
The pattern is:
- Allocate a small fixed-size buffer
- Encode to that buffer as normal
- Use
QCBOREncode_FinishGetSize()to determine if the buffer was large enough or not - If it was not, allocate a properly sized (larger) buffer
- Encode to the dynamically sized buffer
- Use
QCBOREncode_Finish()to finalize
My problem is currently that QCBOREncode_FinishGetSize() only sets the encoded size if the error state is QCBOR_SUCCESS but not if it is QCBOR_ERR_BUFFER_TOO_SMALL.
Lines 1081 to 1083 in 9f09f0c
| if(nReturn == QCBOR_SUCCESS) { | |
| *puEncodedLen = Enc.len; | |
| } |
Is there a reason for that condition to be present in FinishGetSize at all?
Let the caller check the error code to see if the size is meaningful in its context.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels