partial work on new end / enter of decode
diff --git a/inc/qcbor/UsefulBuf.h b/inc/qcbor/UsefulBuf.h
index 16a53d3..e49b8c7 100644
--- a/inc/qcbor/UsefulBuf.h
+++ b/inc/qcbor/UsefulBuf.h
@@ -162,6 +162,9 @@
 
 #ifdef __cplusplus
 extern "C" {
+#if 0
+} // Keep editor indention formatting happy
+#endif
 #endif
 
 /**
@@ -1489,6 +1492,24 @@
 static int UsefulInputBuf_GetError(UsefulInputBuf *pUInBuf);
 
 
+/**
+ @brief Sets the input buffer length (use with caution)
+
+ @param[in] pUInBuf  Pointer to the @ref UsefulInputBuf.
+
+ This changes the internal remembered length of the input buffer
+ set when UsefulInputBuf_Init() was called. It is used by QCBOR
+ to handle CBOR that is wrapped and embedded in CBOR.
+
+ Since this allows setting the length beyond the length of the
+ original input buffer it allows the overall safety to
+ be undermined.
+
+ The new length given here should always be equal to or less than
+ the length given when UsefulInputBuf_Init() was called.
+
+ */
+static void UsefulInputBuf_SetBufferLen(UsefulInputBuf *pUInBuf, size_t uNewLen);
 
 
 /*----------------------------------------------------------
@@ -2125,6 +2146,13 @@
    return pMe->err;
 }
 
+
+static inline void UsefulInputBuf_SetBufferLen(UsefulInputBuf *pMe, size_t uNewLen)
+{
+    pMe->UB.len = uNewLen;
+}
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index 2cb2642..4938a4e 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -346,6 +346,9 @@
     
     /** Trying to get an item by label when a map has not been entered. */
     QCBOR_ERR_NOT_ENTERED = 31,
+
+    /** A callback indicates processing should not continue for some non-CBOR reason */
+    QCBOR_ERR_CALLBACK_FAIL = 32,
     
     /* This is stored in uint8_t in places; never add values > 255 */
 } QCBORError;
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 87b0fb6..515ec54 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -1287,6 +1287,17 @@
 
 
 
+void QCBORDecode_EnterBstrWrapped(QCBORDecodeContext *pCtx, UsefulBufC *pBstr);
+
+void QCBORDecode_EnterBstrWrappedFromMapN(QCBORDecodeContext *pCtx, int64_t uLabel, UsefulBufC *pBstr);
+
+void QCBORDecode_EnterBstrWrappedFromMapSZ(QCBORDecodeContext *pCtx, const char  *szLabel, UsefulBufC *pBstr);
+
+void QCBORDecode_ExitBstrWrapped(QCBORDecodeContext *pCtx);
+
+
+
+
 /*
  Restarts fetching of items in a map to the start of the
  map. This is for GetNext. It has no effect on
@@ -1353,11 +1364,19 @@
  */
 QCBORError QCBORDecode_GetItemsInMap(QCBORDecodeContext *pCtx, QCBORItem *pItemList);
 
+/*
 
-typedef int (*pfItemCallback)(void *pCallbackCtx, const QCBORItem *pItem);
+ The return value is intended for QCBOR errors, not general protocol decoding
+ errors. If this returns other than QCBOR_SUCCESS, the search will stop and
+ the value it returns will be return by QCBORDecode_GetItemsInMapWithCallback().
+ Protocol and other non-CBOR errors can be put in the call back context.
+
+ TODO: make QCBOR_ERR_CB_FAIL?
+ */
+typedef QCBORError (*QCBORItemCallback)(void *pCallbackCtx, const QCBORItem *pItem);
 
 
-QCBORError QCBORDecode_GetItemsInMapWithCallback(QCBORDecodeContext *pCtx, QCBORItem *pItemList, void *pCallbackCtx, pfItemCallback pfCB);
+QCBORError QCBORDecode_GetItemsInMapWithCallback(QCBORDecodeContext *pCtx, QCBORItem *pItemList, void *pCallbackCtx, QCBORItemCallback pfCB);
 
 
 
@@ -1602,16 +1621,16 @@
 
 
 // Semi-private
-void QCBORDecode_EnterMapMode(QCBORDecodeContext *pMe, uint8_t uType);
+void QCBORDecode_EnterBoundedMode(QCBORDecodeContext *pMe, uint8_t uType);
 
 
 inline static void QCBORDecode_EnterMap(QCBORDecodeContext *pMe) {
-   QCBORDecode_EnterMapMode(pMe, QCBOR_TYPE_MAP);
+   QCBORDecode_EnterBoundedMode(pMe, QCBOR_TYPE_MAP);
 }
 
 
 inline static void QCBORDecode_EnterArray(QCBORDecodeContext *pMe) {
-   QCBORDecode_EnterMapMode(pMe, QCBOR_TYPE_ARRAY);
+   QCBORDecode_EnterBoundedMode(pMe, QCBOR_TYPE_ARRAY);
 }
 
 // Semi-private
diff --git a/inc/qcbor/qcbor_private.h b/inc/qcbor/qcbor_private.h
index 594ce14..02cbf86 100644
--- a/inc/qcbor/qcbor_private.h
+++ b/inc/qcbor/qcbor_private.h
@@ -116,6 +116,23 @@
 };
 
 
+
+#define QCBOR_NEST_TYPE_SEQUENCE 0x01
+#define QCBOR_NEST_TYPE_ARRAY 0x02
+#define QCBOR_NEST_TYPE_MAP 0x03
+#define QCBOR_NEST_TYPE_IS_INDEFINITE 0x40
+#define QCBOR_NEST_TYPE_IS_BOUND 0x80
+
+/*
+#define QCBOR_NEST_TYPE_BSTR 0x00
+#define QCBOR_NEST_TYPE_DEFINITE_ARRAY
+#define QCBOR_NEST_TYPE_INDEFINITE_ARRAY
+#define QCBOR_NEST_TYPE_DEFINITE_MAP
+#define QCBOR_NEST_TYPE_INDEFINITE_MAP
+#define QCBOR_NEST_TYPE_
+*/
+
+
 /*
  PRIVATE DATA STRUCTURE
 
@@ -130,6 +147,19 @@
 typedef struct __QCBORDecodeNesting  {
   // PRIVATE DATA STRUCTURE
    struct nesting_decode_level {
+      union {
+         struct {
+            uint16_t uCountTotal;
+            uint16_t uCountCursor;
+            uint32_t uStartOffset;
+         } mm;
+         struct {
+            uint16_t uCountCursor;
+            uint32_t uEndOffset;
+         } bs;
+      } u;
+      uint32_t uEndOffset;
+      uint8_t uType;
       uint32_t uOffset;
       uint16_t uCount; // Cursor
       uint8_t  uMajorType; // TODO: one bit?
@@ -138,6 +168,7 @@
    } pMapsAndArrays[QCBOR_MAX_ARRAY_NESTING1+1],
    *pCurrent,
    *pCurrentMap;
+   uint8_t uNestType[QCBOR_MAX_ARRAY_NESTING1+1];
 } QCBORDecodeNesting;