Consume is working
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 95f41a0..ad8c354 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -866,6 +866,21 @@
/**
+ @brief QCBORDecode_GetNext() and consume entire map or array.
+
+ @param[in] pCtx The decoder context.
+ @param[out] pDecodedItem Holds the CBOR item just decoded.
+
+ This is the same as QCBORDecode_VGetNext() but the contents of the
+ entire map or array will be consumed if the next item is a map or array.
+
+ In order to go back to decode the contents of a map or array consumed
+ by this, the decoder must be rewound using QCBORDecode_Rewind().
+*/
+void QCBORDecode_VGetNextConsume(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem);
+
+
+/**
@brief Get the next data item without consuming it.
@param[in] pCtx The decoder context.
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 5fdbcfa..8989211 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2695,6 +2695,21 @@
return uReturn;
}
+
+void QCBORDecode_VGetNextConsume(QCBORDecodeContext *pMe, QCBORItem *pDecodedItem)
+{
+ uint8_t uNextNestLevel;
+
+ QCBORDecode_VGetNext(pMe, pDecodedItem);
+
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ pMe->uLastError = (uint8_t)ConsumeItem(pMe, pDecodedItem, &uNextNestLevel);
+ pDecodedItem->uNextNestLevel = uNextNestLevel;
+ }
+}
+
+
+
/* Call only on maps and arrays. Rewinds the cursor
* to the start as if it was just entered.
*/
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 949ccbd..a7ef065 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -5482,6 +5482,54 @@
}
#endif /* QCBOR_DISABLE_INDEFINITE_LENGTH_ARRAYS */
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded), 0);
+ QCBORDecode_VGetNextConsume(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_MAP) {
+ return 2401;
+ }
+ if(QCBORDecode_GetError(&DCtx)) {
+ return 2402;
+ }
+
+ QCBORDecode_Init(&DCtx, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(pValidMapEncoded), 0);
+ QCBORDecode_VGetNext(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_MAP ||
+ Item1.val.uCount != 3 ||
+ Item1.uNextNestLevel != 1) {
+ return 2403;
+ }
+ if(QCBORDecode_GetError(&DCtx)) {
+ return 2404;
+ }
+ QCBORDecode_VGetNextConsume(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_INT64 ||
+ Item1.uNextNestLevel != 1 ||
+ Item1.val.int64 != 42) {
+ return 2405;
+ }
+ if(QCBORDecode_GetError(&DCtx)) {
+ return 2406;
+ }
+ QCBORDecode_VGetNextConsume(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_ARRAY ||
+ Item1.uNestingLevel != 1 ||
+ Item1.uNextNestLevel != 1 ||
+ Item1.val.uCount != 2) {
+ return 2407;
+ }
+ if(QCBORDecode_GetError(&DCtx)) {
+ return 2408;
+ }
+ QCBORDecode_VGetNextConsume(&DCtx, &Item1);
+ if(Item1.uDataType != QCBOR_TYPE_MAP ||
+ Item1.uNestingLevel != 1 ||
+ Item1.uNextNestLevel != 0 ||
+ Item1.val.uCount != 4) {
+ return 2409;
+ }
+ if(QCBORDecode_GetError(&DCtx)) {
+ return 2410;
+ }
nReturn = DecodeNestedIterate();
@@ -7681,7 +7729,8 @@
QCBORDecode_EnterArray(&DCtx, NULL);
QCBORDecode_EnterBstrWrapped(&DCtx, 2, NULL);
if(QCBORDecode_GetError(&DCtx) != QCBOR_ERR_INPUT_TOO_LARGE) {
- /* this is what happens when trying to enter byte string
+ /* this is what happens when trying to enter
+ indefinite-length byte string
wrapped CBOR. Tolerate for now. Eventually it needs
to be fixed so this works, but that is not simple. */
return 7300;