rename QCBOREncode_Finish and QCBOREncode_Finish2
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 741dfbc..176d6b7 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -1579,38 +1579,6 @@
QCBOREncode_AddEncodedToMap_2((pCtx), (szLabel), QCBOR_NO_INT_LABEL, (Encoded))
-
-/**
- Get the encoded CBOR and error status.
-
- @param[in] pCtx The context to finish encoding with.
- @param[out] uEncodedLen The length of the encoded or potentially encoded CBOR in bytes.
-
- @return
- One of the CBOR error codes.
-
- If this returns success QCBOR_SUCCESS the encoding was a success and
- the return length is correct and complete.
-
- If no buffer was passed to QCBOR_Init(), then only the length was
- computed. If a buffer was passed, then the encoded CBOR is in the
- buffer.
-
- If an error is returned, the buffer may have partially encoded
- incorrect CBOR in it and it should not be used. Likewise the length
- may be incorrect and should not be used.
-
- Note that the error could have occurred in one of the many
- QCBOR_AddXXX calls long before QCBOREncode_Finish() was called. This
- error handling reduces the CBOR implementation size, but makes
- debugging harder.
-
- */
-
-int QCBOREncode_Finish(QCBOREncodeContext *pCtx, size_t *uEncodedLen);
-
-
-
/**
Get the encoded result.
@@ -1642,7 +1610,36 @@
*/
-int QCBOREncode_Finish2(QCBOREncodeContext *pCtx, UsefulBufC *pEncodedCBOR);
+int QCBOREncode_Finish(QCBOREncodeContext *pCtx, UsefulBufC *pEncodedCBOR);
+
+/**
+ Get the encoded CBOR and error status.
+
+ @param[in] pCtx The context to finish encoding with.
+ @param[out] uEncodedLen The length of the encoded or potentially encoded CBOR in bytes.
+
+ @return
+ One of the CBOR error codes.
+
+ If this returns success QCBOR_SUCCESS the encoding was a success and
+ the return length is correct and complete.
+
+ If no buffer was passed to QCBOR_Init(), then only the length was
+ computed. If a buffer was passed, then the encoded CBOR is in the
+ buffer.
+
+ If an error is returned, the buffer may have partially encoded
+ incorrect CBOR in it and it should not be used. Likewise the length
+ may be incorrect and should not be used.
+
+ Note that the error could have occurred in one of the many
+ QCBOR_AddXXX calls long before QCBOREncode_Finish() was called. This
+ error handling reduces the CBOR implementation size, but makes
+ debugging harder.
+
+ */
+
+int QCBOREncode_FinishGetSize(QCBOREncodeContext *pCtx, size_t *uEncodedLen);
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index b595af2..45dfb47 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -554,7 +554,7 @@
/*
Public functions to finish and get the encoded result. See header qcbor.h
*/
-int QCBOREncode_Finish2(QCBOREncodeContext *me, UsefulBufC *pEncodedCBOR)
+int QCBOREncode_Finish(QCBOREncodeContext *me, UsefulBufC *pEncodedCBOR)
{
if(me->uError)
goto Done;
@@ -581,11 +581,12 @@
return me->uError;
}
-int QCBOREncode_Finish(QCBOREncodeContext *me, size_t *puEncodedLen)
+
+int QCBOREncode_FinishGetSize(QCBOREncodeContext *me, size_t *puEncodedLen)
{
UsefulBufC Enc;
- int nReturn = QCBOREncode_Finish2(me, &Enc);
+ int nReturn = QCBOREncode_Finish(me, &Enc);
if(nReturn == QCBOR_SUCCESS) {
*puEncodedLen = Enc.len;
diff --git a/test/float_tests.c b/test/float_tests.c
index c9861bc..091dc5c 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -431,7 +431,7 @@
QCBOREncode_CloseMap(&EC);
UsefulBufC EncodedHalfs;
- int nReturn = QCBOREncode_Finish2(&EC, &EncodedHalfs);
+ int nReturn = QCBOREncode_Finish(&EC, &EncodedHalfs);
if(nReturn) {
return -1;
}
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 70beff5..217a599 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -454,7 +454,7 @@
// calucate the length so buffer can be allocated correctly,
// and last with the buffer to do the actual encoding
do {
- QCBOREncode_Init(&ECtx, (UsefulBuf){*pEncoded, *pEncodedLen});
+ QCBOREncode_Init(&ECtx, (UsefulBuf){*pEncoded, *pEncodedLen});
QCBOREncode_OpenArray(&ECtx);
QCBOREncode_AddInt64(&ECtx, nInt1);
QCBOREncode_AddInt64(&ECtx, nInt2);
@@ -462,14 +462,16 @@
QCBOREncode_AddBytes(&ECtx, ((UsefulBufC) {"haven token", 11}));
QCBOREncode_CloseArray(&ECtx);
- if(QCBOREncode_Finish(&ECtx, pEncodedLen))
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish(&ECtx, &Encoded))
goto Done;
if(*pEncoded != NULL) {
+ *pEncodedLen = Encoded.len;
nReturn = 0;
goto Done;
}
- *pEncoded = malloc(*pEncodedLen);
+ *pEncoded = malloc(Encoded.len);
if(*pEncoded == NULL) {
nReturn = -1;
goto Done;
diff --git a/test/qcbor_encode_tests.c b/test/qcbor_encode_tests.c
index 28bb817..b42002e 100644
--- a/test/qcbor_encode_tests.c
+++ b/test/qcbor_encode_tests.c
@@ -113,7 +113,7 @@
QCBOREncode_CloseMap(&EC);
UsefulBufC Encoded;
- if(QCBOREncode_Finish2(&EC, &Encoded)) {
+ if(QCBOREncode_Finish(&EC, &Encoded)) {
return -1;
}
@@ -150,7 +150,7 @@
QCBOREncode_CloseArray(&EC);
UsefulBufC Encoded2;
- if(QCBOREncode_Finish2(&EC, &Encoded2)) {
+ if(QCBOREncode_Finish(&EC, &Encoded2)) {
return -5;
}
/*
@@ -629,7 +629,7 @@
UsefulBufC Enc;
- if(QCBOREncode_Finish2(&ECtx, &Enc)) {
+ if(QCBOREncode_Finish(&ECtx, &Enc)) {
nReturn = -1;
goto Done;
}
@@ -785,7 +785,7 @@
QCBOREncode_CloseArray(&ECtx);
UsefulBufC Enc;
- if(QCBOREncode_Finish2(&ECtx, &Enc)) {
+ if(QCBOREncode_Finish(&ECtx, &Enc)) {
nReturn = -1;
}
@@ -831,7 +831,7 @@
QCBOREncode_CloseArray(&ECtx);
UsefulBufC ECBOR;
- if(QCBOREncode_Finish2(&ECtx, &ECBOR)) {
+ if(QCBOREncode_Finish(&ECtx, &ECBOR)) {
nReturn = -1;
}
@@ -898,7 +898,7 @@
UsefulBufC ECBOR;
- if(QCBOREncode_Finish2(&ECtx, &ECBOR)) {
+ if(QCBOREncode_Finish(&ECtx, &ECBOR)) {
nReturn = -1;
}
@@ -922,8 +922,8 @@
for(i = QCBOR_MAX_ARRAY_NESTING; i; i--) {
QCBOREncode_CloseArray(&ECtx);
}
- size_t nEncodedLen;
- if(QCBOREncode_Finish(&ECtx, &nEncodedLen)) {
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish(&ECtx, &Encoded)) {
nReturn = -1;
}
@@ -946,8 +946,8 @@
QCBOREncode_CloseArray(&ECtx);
}
- size_t nEncodedLen;
- if(QCBOREncode_Finish(&ECtx, &nEncodedLen) != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish(&ECtx, &Encoded) != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
nReturn = -1;
}
@@ -969,8 +969,8 @@
for(i = QCBOR_MAX_ARRAY_NESTING+1 ; i; i--) {
QCBOREncode_CloseArray(&ECtx);
}
- size_t nEncodedLen;
- if(QCBOREncode_Finish(&ECtx, &nEncodedLen) != QCBOR_ERR_TOO_MANY_CLOSES) {
+ UsefulBufC Encoded;
+ if(QCBOREncode_Finish(&ECtx, &Encoded) != QCBOR_ERR_TOO_MANY_CLOSES) {
nReturn = -1;
}
@@ -1083,7 +1083,7 @@
UsefulBufC EncodedRawTest;
- if(QCBOREncode_Finish2(&ECtx, &EncodedRawTest)) {
+ if(QCBOREncode_Finish(&ECtx, &EncodedRawTest)) {
return -4;
}
@@ -1125,8 +1125,7 @@
QCBOREncode_CloseMap(&ECtx);
QCBOREncode_CloseMap(&ECtx);
-
- if(QCBOREncode_Finish(&ECtx, pEncodedLen))
+ if(QCBOREncode_FinishGetSize(&ECtx, pEncodedLen))
goto Done;
if(*pEncoded != NULL) {
if(uFirstSizeEstimate != *pEncodedLen) {
@@ -1290,7 +1289,7 @@
UsefulBufC Result;
- QCBOREncode_Finish2(&ECtx, &Result);
+ QCBOREncode_Finish(&ECtx, &Result);
return Result;
}
@@ -1388,7 +1387,7 @@
QCBOREncode_CloseArray(&EC);
UsefulBufC Encoded;
- if(QCBOREncode_Finish2(&EC, &Encoded)) {
+ if(QCBOREncode_Finish(&EC, &Encoded)) {
return -1;
}
@@ -1421,14 +1420,14 @@
QCBOREncode_CloseArray(&EC);
UsefulBufC Encoded2;
- if(QCBOREncode_Finish2(&EC, &Encoded2) != QCBOR_ERR_CLOSE_MISMATCH) {
+ if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_CLOSE_MISMATCH) {
return -1;
}
// ----------- test closing a bstrwrap when nothing is open ---------------------
QCBOREncode_Init(&EC, UsefulBuf_FROM_BYTE_ARRAY(spBigBuf));
QCBOREncode_CloseBstrWrap(&EC, &Wrapped);
- if(QCBOREncode_Finish2(&EC, &Encoded2) != QCBOR_ERR_TOO_MANY_CLOSES) {
+ if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_TOO_MANY_CLOSES) {
return -2;
}
@@ -1443,7 +1442,7 @@
QCBOREncode_CloseBstrWrap(&EC, &Wrapped);
}
- if(QCBOREncode_Finish2(&EC, &Encoded2) != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
+ if(QCBOREncode_Finish(&EC, &Encoded2) != QCBOR_ERR_ARRAY_NESTING_TOO_DEEP) {
return -3;
}
@@ -1667,7 +1666,7 @@
QCBOREncode_CloseArray(&EC);
UsefulBufC Encoded;
- if(QCBOREncode_Finish2(&EC, &Encoded)) {
+ if(QCBOREncode_Finish(&EC, &Encoded)) {
return -1;
}
@@ -1824,7 +1823,7 @@
// Finish and check the results
UsefulBufC COSE_Sign1;
- if(QCBOREncode_Finish2(&EC, &COSE_Sign1)) {
+ if(QCBOREncode_Finish(&EC, &COSE_Sign1)) {
return -2;
}