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.
|
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.
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:
QCBOREncode_FinishGetSize()to determine if the buffer was large enough or notQCBOREncode_Finish()to finalizeMy problem is currently that
QCBOREncode_FinishGetSize()only sets the encoded size if the error state isQCBOR_SUCCESSbut not if it isQCBOR_ERR_BUFFER_TOO_SMALL.QCBOR/src/qcbor_encode.c
Lines 1081 to 1083 in 9f09f0c
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.