Getting a lot more types works
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 1d6a37a..ca69756 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -235,6 +235,8 @@
#define QCBOR_TYPE_BREAK 31 // Used internally; never returned
+#define QCBOR_TYPE_UUID 32 // TODO: implement this
+
#define QCBOR_TYPE_OPTTAG 254 // Used internally; never returned
@@ -1001,13 +1003,17 @@
The CBOR data item to decode must be a positive or negative integer. If not
\ref QCBOR_ERR_UNEXPECTED_TYPE is set.
- CBOR can represent negative integers smaller than can be represetned in
- an int64_t. \ref QCBOR_ERR_INT_OVERFLOW is returned in this case.
+ CBOR can represent negative integers further from zero than can be represetned in
+ an int64_t. \ref QCBOR_ERR_INT_OVERFLOW is set if such input is encountered.
See also QCBORDecode_GetInt64Convert() and QCBORDecode_GetInt64ConvertAll().
*/
static void QCBORDecode_GetInt64(QCBORDecodeContext *pCtx, int64_t *pnValue);
+static void QCBORDecode_GetInt64InMapN(QCBORDecodeContext *pCtx, int64_t nLabel, int64_t *pnValue);
+
+static void QCBORDecode_GetInt64InMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, int64_t *pnValue);
+
/**
@brief Decode next item as a signed 64-bit integer with basic conversions
@@ -1036,6 +1042,10 @@
*/
static void QCBORDecode_GetInt64Convert(QCBORDecodeContext *pCtx, uint32_t uOptions, int64_t *pnValue);
+static void QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, uint32_t uOptions, int64_t *pnValue);
+
+static void QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, uint32_t uOptions, int64_t *pnValue);
+
/**
@brief Decode next item as a signed 64-bit integer with conversions
@@ -1059,6 +1069,11 @@
*/
void QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pCtx, uint32_t uOptions, int64_t *pnValue);
+void QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, uint32_t uOptions, int64_t *pnValue);
+
+void QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, uint32_t uOptions, int64_t *pnValue);
+
+
/**
@brief Decode next item as an unsigned 64-bit integer.
@@ -1164,20 +1179,58 @@
-void QCBORDecode_GetBytes(QCBORDecodeContext *pCtx, UsefulBufC *pValue);
+static void QCBORDecode_GetBytes(QCBORDecodeContext *pCtx, UsefulBufC *pBytes);
-void QCBORDecode_GetText(QCBORDecodeContext *pCtx, UsefulBufC *pValue);
+static void QCBORDecode_GetBytesInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, UsefulBufC *pBytes);
-void QCBORDecode_GetPosBignum(QCBORDecodeContext *pCtx, UsefulBufC *pValue);
+static void QCBORDecode_GetBytesInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, UsefulBufC *pBytes);
-void QCBORDecode_GetNegBignum(QCBORDecodeContext *pCtx, UsefulBufC *pValue);
+
+
+static void QCBORDecode_GetText(QCBORDecodeContext *pCtx, UsefulBufC *pText);
+
+static void QCBORDecode_GetTextInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, UsefulBufC *pText);
+
+static void QCBORDecode_GetTextInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, UsefulBufC *pText);
+
+
+void QCBORDecode_GetBool(QCBORDecodeContext *pCtx, bool *pbBool);
+
+void QCBORDecode_GetBoolInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, bool *pbBool);
+
+void QCBORDecode_GetBoolInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, bool *pbBool);
-/* Next item must be map or this generates an error.
-
-
+
+
+
+void QCBORDecode_GetBignum(QCBORDecodeContext *pCtx, bool bMustBeTagged, UsefulBufC *pValue, bool *pbIsNegative);
+
+void QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pCtx, int64_t nLabel, bool bMustBeTagged, UsefulBufC *pValue, bool *pbIsNegative);
+
+void QCBORDecode_GetBignumInMapSz(QCBORDecodeContext *pCtx, const char *szLabel, bool bMustBeTagged, UsefulBufC *pValue, bool *pbIsNegative);
+
+
+
+
+static void QCBORDecode_GetDateString(QCBORDecodeContext *pCtx, uint8_t uTagRequired, UsefulBufC *pValue);
+
+static void QCBORDecode_GetDateStringInMapN(QCBORDecodeContext *pCtx, uint8_t uTagRequired, int64_t nLabel, UsefulBufC *pValue);
+
+void QCBORDecode_GetDateStringInMapSZXX(QCBORDecodeContext *pCtx, uint8_t uTagRequired, const char *szLabel, UsefulBufC *pValue);
+
+
+
+
+/**
+ @brief Enter a map for decoding and searching.
+
+ @param[in] pCtx The decode context
+
+ Next item must be map or this generates an error.
+
This puts the decoder in map mode which narrows
decoding to the map entered and enables use of
getting items by label.
@@ -1219,7 +1272,7 @@
Seek to to the beginning of the map.
Consume items looking for nLabel
*/
-void QCBORDecode_EnterMapFromMap(QCBORDecodeContext *pCtx, int64_t nLabel);
+void QCBORDecode_EnterMapInMapN(QCBORDecodeContext *pCtx, int64_t nLabel);
void QCBORDecode_EnterMapFromMapSZ(QCBORDecodeContext *pCtx, const char *szLabel);
@@ -1269,16 +1322,16 @@
*/
-QCBORError QCBORDecode_GetItemInMap(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t qcbor_type,
- QCBORItem *pItem);
+void QCBORDecode_GetItemInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t qcbor_type,
+ QCBORItem *pItem);
QCBORError QCBORDecode_GetItemInMapSZ(QCBORDecodeContext *pCtx,
-const char *szLabel,
-uint8_t qcbor_type,
-QCBORItem *pItem);
+ const char *szLabel,
+ uint8_t qcbor_type,
+ QCBORItem *pItem);
/*
This gets several labeled items out of a map.
@@ -1306,15 +1359,6 @@
-QCBORError QCBORDecode_GetIntInMap(QCBORDecodeContext *pCtx, int64_t nLabel, int64_t *pInt);
-
-void QCBORDecode_GetIntInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, int64_t *pInt);
-
-
-void QCBORDecode_GetBstrInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, UsefulBufC *pBstr);
-
-void QCBORDecode_GetTextInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, UsefulBufC *pBstr);
-
@@ -1525,6 +1569,11 @@
// Semi-private
void QCBORDecode_GetInt64ConvertInternal(QCBORDecodeContext *pMe, uint32_t uOptions, int64_t *pnValue, QCBORItem *pItem);
+void QCBORDecode_GetInt64ConvertInternalInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, int64_t *pnValue, QCBORItem *pItem);
+
+void QCBORDecode_GetInt64ConvertInternalInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, int64_t *pnValue, QCBORItem *pItem);
+
+
inline static void QCBORDecode_GetInt64Convert(QCBORDecodeContext *pMe, uint32_t uOptions, int64_t *pnValue)
{
@@ -1532,12 +1581,35 @@
QCBORDecode_GetInt64ConvertInternal(pMe, uOptions, pnValue, &Item);
}
+inline static void QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_GetInt64ConvertInternalInMapN(pMe, nLabel, uOptions, pnValue, &Item);
+}
+
+inline static void QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_GetInt64ConvertInternalInMapSZ(pMe, szLabel, uOptions, pnValue, &Item);
+}
+
inline static void QCBORDecode_GetInt64(QCBORDecodeContext *pMe, int64_t *pnValue)
{
QCBORDecode_GetInt64Convert(pMe, QCBOR_CONVERT_TYPE_INT64, pnValue);
}
+inline static void QCBORDecode_GetInt64InMapN(QCBORDecodeContext *pMe, int64_t nLabel, int64_t *pnValue)
+{
+ QCBORDecode_GetInt64ConvertInMapN(pMe, nLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
+}
+
+inline static void QCBORDecode_GetInt64InMapSZ(QCBORDecodeContext *pMe, const char *szLabel, int64_t *pnValue)
+{
+ QCBORDecode_GetInt64ConvertInMapSZ(pMe, szLabel, QCBOR_CONVERT_TYPE_INT64, pnValue);
+}
+
+
// Semi-private
void QCBORDecode_GetUInt64ConvertInternal(QCBORDecodeContext *pMe, uint32_t uOptions, uint64_t *puValue, QCBORItem *pItem);
@@ -1568,6 +1640,151 @@
QCBORDecode_GetDoubleConvert(pMe, QCBOR_CONVERT_TYPE_FLOAT, pValue);
}
+
+// Semi private
+
+
+typedef struct {
+ uint8_t uTagRequirement;
+ uint8_t uTaggedType;
+ uint8_t uAllowedContentTypes[6];
+} TagSpecification;
+
+// Semi private
+
+void QCBORDecode_GetTaggedStringInternal(QCBORDecodeContext *pMe, TagSpecification TagSpec, UsefulBufC *pBstr);
+
+
+
+// Semi private
+
+void QCBORDecode_GetTaggedItemInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ TagSpecification TagSpec,
+ QCBORItem *pItem);
+
+void QCBORDecode_GetTaggedItemInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel,
+ TagSpecification TagSpec,
+ QCBORItem *pItem);
+
+void QCBORDecode_GetTaggedStringInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ TagSpecification TagSpec,
+ UsefulBufC *pString);
+
+void QCBORDecode_GetTaggedStringInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel,
+ TagSpecification TagSpec,
+ UsefulBufC *pString);
+
+
+static inline void QCBORDecode_GetBytes(QCBORDecodeContext *pMe, UsefulBufC *pValue)
+{
+ // Complier should make this just 64-bit integer parameter
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_BYTE_STRING, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInternal(pMe, TagSpec, pValue);
+}
+
+inline static void QCBORDecode_GetBytesInMapN(QCBORDecodeContext *pMe, int64_t nLabel, UsefulBufC *pBstr)
+{
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_BYTE_STRING, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInMapN(pMe, nLabel, TagSpec, pBstr);
+}
+
+inline static void QCBORDecode_GetBytesInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, UsefulBufC *pBstr)
+{
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_BYTE_STRING, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInMapSZ(pMe, szLabel, TagSpec, pBstr);
+}
+
+
+/*inline static void QCBORDecode_GetTextOld(QCBORDecodeContext *pMe, UsefulBufC *pValue)
+{
+ QCBORDecode_GetTaggedStringInternal(pMe, 0, QCBOR_TYPE_TEXT_STRING, QCBOR_TYPE_TEXT_STRING, pValue);
+} */
+
+static inline void QCBORDecode_GetText(QCBORDecodeContext *pMe, UsefulBufC *pValue)
+{
+ // Complier should make this just 64-bit integer parameter
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_TEXT_STRING, {QCBOR_TYPE_TEXT_STRING, QCBOR_TYPE_NONE,QCBOR_TYPE_NONE,QCBOR_TYPE_NONE,QCBOR_TYPE_NONE,QCBOR_TYPE_NONE}};
+
+ QCBORDecode_GetTaggedStringInternal(pMe, TagSpec, pValue);
+}
+
+inline static void QCBORDecode_GetTextInMapN(QCBORDecodeContext *pMe, int64_t nLabel, UsefulBufC *pText)
+{
+ // This TagSpec only matches text strings; it also should optimize down to passing a 64-bit integer
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_TEXT_STRING, {QCBOR_TYPE_TEXT_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInMapN(pMe, nLabel, TagSpec, pText);
+}
+
+
+inline static void QCBORDecode_GetTextInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, UsefulBufC *pText)
+{
+ const TagSpecification TagSpec = {0, QCBOR_TYPE_TEXT_STRING, {QCBOR_TYPE_TEXT_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInMapSZ(pMe, szLabel, TagSpec, pText);
+}
+
+
+static inline void QCBORDecode_GetDateString(QCBORDecodeContext *pMe, uint8_t uTagRequirement, UsefulBufC *pValue)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_DATE_STRING, {QCBOR_TYPE_TEXT_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInternal(pMe, TagSpec, pValue);
+}
+
+
+inline static void QCBORDecode_GetDateStringInMapN(QCBORDecodeContext *pMe, uint8_t uTagRequirement, int64_t nLabel, UsefulBufC *pText)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_DATE_STRING, {QCBOR_TYPE_TEXT_STRING, 0,0,0,0,0}};
+ QCBORItem Item;
+
+ QCBORDecode_GetTaggedItemInMapN(pMe, nLabel, TagSpec, &Item);
+ *pText = Item.val.string;
+}
+
+inline static void QCBORDecode_GetDateStringInMapSZ(QCBORDecodeContext *pMe, uint8_t uTagRequirement, const char *szLabel, UsefulBufC *pText)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_DATE_STRING, {QCBOR_TYPE_TEXT_STRING, 0,0,0,0,0}};
+ QCBORItem Item;
+
+ QCBORDecode_GetTaggedItemInMapSZ(pMe, szLabel, TagSpec, &Item);
+ *pText = Item.val.string;
+}
+
+static inline void QCBORDecode_GetBinaryUUID(QCBORDecodeContext *pMe, uint8_t uTagRequirement, UsefulBufC *pUUID)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_UUID, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+
+ QCBORDecode_GetTaggedStringInternal(pMe, TagSpec, pUUID);
+}
+
+
+inline static void QCBORDecode_GetBinaryUUIDInMapN(QCBORDecodeContext *pMe, uint8_t uTagRequirement, int64_t nLabel, UsefulBufC *pUUID)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_UUID, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+ QCBORItem Item;
+
+ QCBORDecode_GetTaggedItemInMapN(pMe, nLabel, TagSpec, &Item);
+ *pUUID = Item.val.string;
+}
+
+inline static void QCBORDecode_GetBinaryUUIDInMapSZ(QCBORDecodeContext *pMe, uint8_t uTagRequirement, const char *szLabel, UsefulBufC *pUUID)
+{
+ const TagSpecification TagSpec = {uTagRequirement, QCBOR_TYPE_UUID, {QCBOR_TYPE_BYTE_STRING, 0,0,0,0,0}};
+ QCBORItem Item;
+
+ QCBORDecode_GetTaggedItemInMapSZ(pMe, szLabel, TagSpec, &Item);
+ *pUUID = Item.val.string;
+}
+
+
#ifdef __cplusplus
}
#endif
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index d9117e5..10904fb 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -2010,9 +2010,9 @@
{
if(Item1.uDataType == Item2.uDataType) {
return true;
- } else if(Item1.uLabelType == QCBOR_TYPE_ANY) {
+ } else if(Item1.uDataType == QCBOR_TYPE_ANY) {
return true;
- } else if(Item2.uLabelType == QCBOR_TYPE_ANY) {
+ } else if(Item2.uDataType == QCBOR_TYPE_ANY) {
return true;
}
return false;
@@ -2159,30 +2159,31 @@
}
-QCBORError QCBORDecode_GetItemInMap(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uQcborType,
- QCBORItem *pItem)
+void QCBORDecode_GetItemInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uQcborType,
+ QCBORItem *pItem)
{
- QCBORItem One[2];
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
- One[0].uLabelType = QCBOR_TYPE_INT64;
- One[0].label.int64 = nLabel;
- One[0].uDataType = uQcborType;
- One[1].uLabelType = QCBOR_TYPE_NONE; // Indicates end of array
+ QCBORItem OneItemSeach[2];
+ OneItemSeach[0].uLabelType = QCBOR_TYPE_INT64;
+ OneItemSeach[0].label.int64 = nLabel;
+ OneItemSeach[0].uDataType = uQcborType;
+ OneItemSeach[1].uLabelType = QCBOR_TYPE_NONE; // Indicates end of array
- QCBORError nReturn = MapSearch(pMe, One, NULL, NULL);
+ QCBORError nReturn = MapSearch(pMe, OneItemSeach, NULL, NULL);
if(nReturn) {
- return nReturn;
+ pMe->uLastError = (uint8_t)nReturn;
}
- if(One[0].uDataType == QCBOR_TYPE_NONE) {
- return QCBOR_ERR_NOT_FOUND;
+ if(OneItemSeach[0].uDataType == QCBOR_TYPE_NONE) {
+ pMe->uLastError = QCBOR_ERR_NOT_FOUND;
}
- *pItem = One[0];
-
- return QCBOR_SUCCESS;
+ *pItem = OneItemSeach[0];
}
@@ -2213,6 +2214,73 @@
}
+static QCBORError CheckTagRequirement(TagSpecification TagSpec, uint8_t uDataType)
+{
+ // This gets called a lot, so it needs to be fast, especially for simple cases.
+ // TODO: this isn't working right yet
+ if((TagSpec.uTagRequirement == 1 || TagSpec.uTagRequirement == 2) && uDataType == TagSpec.uTaggedType) {
+ return QCBOR_SUCCESS;
+ } else {
+ for(int i = 0; i < 6; i++) {
+ if(uDataType == TagSpec.uAllowedContentTypes[i]) {
+ return QCBOR_SUCCESS;
+ }
+ }
+ }
+
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+
+}
+
+void QCBORDecode_GetTaggedItemInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ TagSpecification TagSpec,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = CheckTagRequirement(TagSpec, pItem->uDataType);
+}
+
+void QCBORDecode_GetTaggedItemInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ TagSpecification TagSpec,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = CheckTagRequirement(TagSpec, pItem->uDataType);
+}
+
+void QCBORDecode_GetTaggedStringInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ TagSpecification TagSpec,
+ UsefulBufC *pString)
+{
+ QCBORItem Item;
+ QCBORDecode_GetTaggedItemInMapN(pMe, nLabel, TagSpec, &Item);
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ *pString = Item.val.string;
+ }
+}
+
+void QCBORDecode_GetTaggedStringInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel,
+ TagSpecification TagSpec,
+ UsefulBufC *pString)
+{
+ QCBORItem Item;
+ QCBORDecode_GetTaggedItemInMapSZ(pMe, szLabel, TagSpec, &Item);
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ *pString = Item.val.string;
+ }
+}
static void SearchAndEnter(QCBORDecodeContext *pMe, QCBORItem pSearch[])
@@ -2351,46 +2419,29 @@
-void QCBORDecode_GetIntInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, int64_t *pInt)
-{
- // TODO: error handling
- QCBORItem Item;
- QCBORDecode_GetItemInMapSZ(pMe,szLabel, QCBOR_TYPE_INT64, &Item);
- *pInt = Item.val.int64;
-}
-void QCBORDecode_GetBstrInMapN(QCBORDecodeContext *pMe, int64_t nLabel, UsefulBufC *pBstr)
-{
- // TODO: error handling
- QCBORItem Item;
- QCBORDecode_GetItemInMap(pMe, nLabel, QCBOR_TYPE_BYTE_STRING, &Item);
- *pBstr = Item.val.string;
-}
-void QCBORDecode_GetBstrInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, UsefulBufC *pBstr)
-{
- // TODO: error handling
- QCBORItem Item;
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_BYTE_STRING, &Item);
- *pBstr = Item.val.string;
-}
-void QCBORDecode_GetDateStringInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, UsefulBufC *pBstr)
-{
- // TODO: error handling
- QCBORItem Item;
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_DATE_STRING, &Item);
- *pBstr = Item.val.string;
-}
-void QCBORDecode_GetTextInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, UsefulBufC *pBstr)
-{
- // TODO: error handling
- QCBORItem Item;
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_TEXT_STRING, &Item);
- *pBstr = Item.val.string;
-}
+static QCBORError InterpretBool(const QCBORItem *pItem, bool *pBool)
+{
+ switch(pItem->uDataType) {
+ case QCBOR_TYPE_TRUE:
+ *pBool = true;
+ return QCBOR_SUCCESS;
+ break;
+
+ case QCBOR_TYPE_FALSE:
+ *pBool = false;
+ return QCBOR_SUCCESS;
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ break;
+ }
+}
void QCBORDecode_GetBool(QCBORDecodeContext *pMe, bool *pValue)
{
@@ -2407,69 +2458,29 @@
pMe->uLastError = (uint8_t)nError;
return;
}
-
- switch(Item.uDataType) {
- case QCBOR_TYPE_TRUE:
- *pValue = true;
- break;
-
- case QCBOR_TYPE_FALSE:
- *pValue = false;
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- break;
- }
+ pMe->uLastError = (uint8_t)InterpretBool(&Item, pValue);
}
-#if 0
-// TODO: fix this
-/* Types of text strings
- * Plain, b64, b64url, URI, regex, MIME Text
- * One function for each with options to expect plain?
- * One function for all so you can say what you want?
- *
- * A label is expected if pLabel is not NULL.
- */
-void QCBORDecode_GetTextFoo(QCBORDecodeContext *pMe, QCBORLabel *pLabel, UsefulBufC *pValue)
+void QCBORDecode_GetBoolInMapN(QCBORDecodeContext *pMe, int64_t nLabel, bool *pValue)
{
QCBORItem Item;
- QCBORError nError;
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
- nError = QCBORDecode_GetNext(pMe, &Item);
- if(nError) {
- pMe->uLastError = nError;
- return;
- }
-
- if(pLabel != NULL) {
- if(Item.uLabelType == QCBOR_TYPE_NONE) {
- pMe->uLastError = 9; // TODO: error code
- return;
- } else {
- // TODO: what about label allocation?
- pLabel->uLabelType = Item.uLabelType;
- pLabel->label.xx = Item.label.int64; // TOOD: figure out assignment
- }
- }
-
- switch(Item.uDataType) {
- case QCBOR_TYPE_TEXT_STRING:
- *pValue = Item.val.string;
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- }
+ pMe->uLastError = (uint8_t)InterpretBool(&Item, pValue);
}
-#endif
-/*
- Options for MIME data, CBOR, positive big num, negative big num ??
- */
-void QCBORDecode_GetStringInternal(QCBORDecodeContext *pMe, UsefulBufC *pValue, uint8_t uType)
+void QCBORDecode_GetBoolInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, bool *pValue)
+{
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
+
+ pMe->uLastError = (uint8_t)InterpretBool(&Item, pValue);
+}
+
+
+
+void QCBORDecode_GetTaggedStringInternal(QCBORDecodeContext *pMe, TagSpecification TagSpec, UsefulBufC *pBstr)
{
if(pMe->uLastError != QCBOR_SUCCESS) {
// Already in error state, do nothing
@@ -2485,22 +2496,48 @@
return;
}
- if(Item.uDataType == uType) {
- *pValue = Item.val.string;
- } else {
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
+ pMe->uLastError = (uint8_t)CheckTagRequirement(TagSpec, Item.uDataType);
+
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ *pBstr = Item.val.string;
}
}
-void QCBORDecode_GetBytes(QCBORDecodeContext *pMe, UsefulBufC *pValue)
-{
- QCBORDecode_GetStringInternal(pMe, pValue, QCBOR_TYPE_BYTE_STRING);
-}
-void QCBORDecode_GetText(QCBORDecodeContext *pMe, UsefulBufC *pValue)
+
+static QCBORError ConvertBigNum(const QCBORItem *pItem, UsefulBufC *pValue, bool *pbIsNegative)
{
- QCBORDecode_GetStringInternal(pMe, pValue, QCBOR_TYPE_TEXT_STRING);
+ *pbIsNegative = false;
+
+ bool bMustBeTagged = true; // TODO: fix this
+
+ switch(pItem->uDataType) {
+ case QCBOR_TYPE_BYTE_STRING:
+ // TODO: check that there is no tag here?
+ if(bMustBeTagged) {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ } else {
+ *pValue = pItem->val.string;
+ return QCBOR_SUCCESS;
+ }
+ break;
+
+ case QCBOR_TYPE_POSBIGNUM:
+ *pValue = pItem->val.string;
+ return QCBOR_SUCCESS;
+ break;
+
+ case QCBOR_TYPE_NEGBIGNUM:
+ *pbIsNegative = true;
+ *pValue = pItem->val.string;
+ return QCBOR_SUCCESS;
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ break;
+ }
}
@@ -2523,71 +2560,24 @@
return;
}
- QCBORError nError;
QCBORItem Item;
-
- nError = QCBORDecode_GetNext(pMe, &Item);
- if(nError != QCBOR_SUCCESS) {
- pMe->uLastError = (uint8_t)nError;
+ QCBORError uError = QCBORDecode_GetNext(pMe, &Item);
+ if(uError != QCBOR_SUCCESS) {
+ pMe->uLastError = (uint8_t)uError;
return;
}
- *pbIsNegative = false;
-
- switch(Item.uDataType) {
- case QCBOR_TYPE_BYTE_STRING:
- // TODO: check that there is no tag here?
- if(bMustBeTagged) {
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- } else {
- *pValue = Item.val.string;
- }
- break;
-
- case QCBOR_TYPE_POSBIGNUM:
- *pValue = Item.val.string;
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- *pbIsNegative = true;
- *pValue = Item.val.string;
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- break;
- }
+ pMe->uLastError = (uint8_t)ConvertBigNum(&Item, pValue, pbIsNegative);
}
-void QCBORDecode_GetPosBignum(QCBORDecodeContext *pMe, UsefulBufC *pValue)
+void QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pMe, int64_t nLabel, bool bMustBeTagged, UsefulBufC *pValue, bool *pbIsNegative)
{
- // Has to be either a positive big num or a byte string
- /*
- an array of bytestrings and bignums. Tagging is necessary
- to tell them apart
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
- A labeled item where the label tells you it is a big
- num and there be no tagging
-
- An array where you expect a big num is the next thing
- and it must be tagged so.
-
-
- Some protocols will require it to be tagged because
- it will be ambigous if not.
-
-
-
- */
- // TODO: do these have to be tagged?
- // Probably should allow tagged or untagged, but not wrong-tagged
- QCBORDecode_GetStringInternal(pMe, pValue, QCBOR_TYPE_POSBIGNUM);
+ pMe->uLastError = ConvertBigNum(&Item, pValue, pbIsNegative);
}
-void QCBORDecode_GetNegBignum(QCBORDecodeContext *pMe, UsefulBufC *pValue)
-{
- QCBORDecode_GetStringInternal(pMe, pValue, QCBOR_TYPE_NEGBIGNUM);
-}
@@ -2769,14 +2759,57 @@
return QCBOR_SUCCESS;
}
-
-
#include "fenv.h"
+static QCBORError ConvertInt64(const QCBORItem *pItem, uint32_t uOptions, int64_t *pnValue)
+{
+ switch(pItem->uDataType) {
+ // TODO: float when ifdefs are set
+ case QCBOR_TYPE_DOUBLE:
+ if(uOptions & QCBOR_CONVERT_TYPE_FLOAT) {
+ // TODO: what about under/overflow here?
+ // Invokes the floating-point HW and/or compiler-added libraries
+ feclearexcept(FE_ALL_EXCEPT);
+ *pnValue = llround(pItem->val.dfnum);
+ if(fetestexcept(FE_INVALID)) {
+ // TODO: better error code
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_INT64:
+ if(uOptions & QCBOR_CONVERT_TYPE_INT64) {
+ *pnValue = pItem->val.int64;
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_UINT64:
+ if(uOptions & QCBOR_CONVERT_TYPE_UINT64) {
+ if(pItem->val.uint64 < INT64_MAX) {
+ *pnValue = pItem->val.int64;
+ } else {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ return QCBOR_SUCCESS;
+}
+
void QCBORDecode_GetInt64ConvertInternal(QCBORDecodeContext *pMe,
uint32_t uOptions,
- int64_t *pValue,
+ int64_t *pnValue,
QCBORItem *pItem)
{
if(pMe->uLastError != QCBOR_SUCCESS) {
@@ -2784,7 +2817,6 @@
}
QCBORItem Item;
-
QCBORError uError = QCBORDecode_GetNext(pMe, &Item);
if(uError) {
pMe->uLastError = (uint8_t)uError;
@@ -2795,57 +2827,163 @@
*pItem = Item;
}
- switch(Item.uDataType) {
- // TODO: float when ifdefs are set
- case QCBOR_TYPE_DOUBLE:
- if(uOptions & QCBOR_CONVERT_TYPE_FLOAT) {
- // TODO: what about under/overflow here?
- // Invokes the floating-point HW and/or compiler-added libraries
- feclearexcept(FE_ALL_EXCEPT);
- *pValue = llround(Item.val.dfnum);
- if(fetestexcept(FE_INVALID)) {
- // TODO: better error code
- pMe->uLastError = QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
+ pMe->uLastError = ConvertInt64(&Item, uOptions, pnValue);
+}
+
+void QCBORDecode_GetInt64ConvertInternalInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint32_t uOptions,
+ int64_t *pnValue,
+ QCBORItem *pItem)
+{
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, &Item);
+
+ pMe->uLastError = ConvertInt64(&Item, uOptions, pnValue);
+}
+
+void QCBORDecode_GetInt64ConvertInternalInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel,
+ uint32_t uOptions,
+ int64_t *pnValue,
+ QCBORItem *pItem)
+{
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ QCBORItem Item;
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item);
+
+ pMe->uLastError = ConvertInt64(&Item, uOptions, pnValue);
+}
+
+
+
+
+static QCBORError Int64ConvertAll(const QCBORItem *pItem, uint32_t uOptions, int64_t *pnValue)
+{
+ QCBORError uErr;
+
+ switch(pItem->uDataType) {
+
+ case QCBOR_TYPE_POSBIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return ConvertPositiveBigNumToSigned(pItem->val.bigNum, pnValue);
} else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
}
break;
- case QCBOR_TYPE_INT64:
- if(uOptions & QCBOR_CONVERT_TYPE_INT64) {
- *pValue = Item.val.int64;
+ case QCBOR_TYPE_NEGBIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return ConvertNegativeBigNumToSigned(pItem->val.bigNum, pnValue);
} else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
}
break;
- case QCBOR_TYPE_UINT64:
- if(uOptions & QCBOR_CONVERT_TYPE_UINT64) {
- if(Item.val.uint64 < INT64_MAX) {
- *pValue = Item.val.int64;
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
+#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ return ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ &Exponentitate10);
} else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT:
+ if(uOptions & QCBOR_CONVERT_TYPE_BIGFLOAT) {
+ return ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ Exponentitate2);
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ uErr = ConvertPositiveBigNumToSigned(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ Exponentitate10);
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ uErr = ConvertNegativeBigNumToSigned(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ Exponentitate10);
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ uErr = ConvertPositiveBigNumToSigned(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ Exponentitate2);
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ uErr = ConvertNegativeBigNumToSigned(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ Exponentitate2);
+ } else {
+ return QCBOR_ERR_CONVERSION_NOT_REQUESTED;
}
break;
default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+#endif
}
}
-
-
/*
Public function, see header qcbor/qcbor_decode.h file
-*/
-void QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pMe, uint32_t uOptions, int64_t *pValue)
+ */
+void QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pMe, uint32_t uOptions, int64_t *pnValue)
{
QCBORItem Item;
- QCBORDecode_GetInt64ConvertInternal(pMe, uOptions, pValue, &Item);
+ QCBORDecode_GetInt64ConvertInternal(pMe, uOptions, pnValue, &Item);
if(pMe->uLastError == QCBOR_SUCCESS) {
// The above conversion succeeded
@@ -2857,114 +2995,51 @@
return;
}
- switch(Item.uDataType) {
-
- case QCBOR_TYPE_POSBIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_BIG_NUM) {
- pMe->uLastError = (uint8_t)ConvertPositiveBigNumToSigned(Item.val.bigNum, pValue);
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_BIG_NUM) {
- pMe->uLastError = (uint8_t)ConvertNegativeBigNumToSigned(Item.val.bigNum, pValue);
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
-#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
- case QCBOR_TYPE_DECIMAL_FRACTION:
- if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- pMe->uLastError = (uint8_t)ExponentiateNN(Item.val.expAndMantissa.Mantissa.nInt,
- Item.val.expAndMantissa.nExponent,
- pValue,
- &Exponentitate10);
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT:
- if(uOptions & QCBOR_CONVERT_TYPE_BIGFLOAT) {
- pMe->uLastError = (uint8_t)ExponentiateNN(Item.val.expAndMantissa.Mantissa.nInt,
- Item.val.expAndMantissa.nExponent,
- pValue,
- Exponentitate2);
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
-
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- pMe->uLastError = (uint8_t)ConvertPositiveBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentiateNN(nMantissa,
- Item.val.expAndMantissa.nExponent,
- pValue,
- Exponentitate10);
- }
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- pMe->uLastError = (uint8_t)ConvertNegativeBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentiateNN(nMantissa,
- Item.val.expAndMantissa.nExponent,
- pValue,
- Exponentitate10);
- }
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- pMe->uLastError = (uint8_t)ConvertPositiveBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentiateNN(nMantissa,
- Item.val.expAndMantissa.nExponent,
- pValue,
- Exponentitate2);
- }
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- if(uOptions & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- pMe->uLastError = (uint8_t)ConvertNegativeBigNumToSigned(Item.val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(!pMe->uLastError) {
- pMe->uLastError = (uint8_t)ExponentiateNN(nMantissa,
- Item.val.expAndMantissa.nExponent,
- pValue,
- Exponentitate2);
- }
- } else {
- pMe->uLastError = QCBOR_ERR_CONVERSION_NOT_REQUESTED;
- }
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
-#endif
- }
+ pMe->uLastError = (uint8_t)Int64ConvertAll(&Item, uOptions, pnValue);
}
+void QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pMe, int64_t nLabel, uint32_t uOptions, int64_t *pnValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_GetInt64ConvertInternalInMapN(pMe, nLabel, uOptions, pnValue, &Item);
+
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ // The above conversion succeeded
+ return;
+ }
+
+ if(pMe->uLastError != QCBOR_ERR_UNEXPECTED_TYPE) {
+ // The above conversion failed in a way that code below can't correct
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)Int64ConvertAll(&Item, uOptions, pnValue);
+}
+
+
+
+void QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pMe, const char *szLabel, uint32_t uOptions, int64_t *pnValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_GetInt64ConvertInternalInMapSZ(pMe, szLabel, uOptions, pnValue, &Item);
+
+ if(pMe->uLastError == QCBOR_SUCCESS) {
+ // The above conversion succeeded
+ return;
+ }
+
+ if(pMe->uLastError != QCBOR_ERR_UNEXPECTED_TYPE) {
+ // The above conversion failed in a way that code below can't correct
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)Int64ConvertAll(&Item, uOptions, pnValue);
+}
+
+
+
void QCBORDecode_GetUInt64ConvertInternal(QCBORDecodeContext *pMe,
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index cd56325..3b0615d 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -3868,12 +3868,12 @@
QCBORDecode_EnterMap(&DCtx);
- QCBORDecode_GetIntInMapSZ(&DCtx, "first integer", &nDecodedInt1);
+ QCBORDecode_GetInt64InMapSZ(&DCtx, "first integer", &nDecodedInt1);
QCBORDecode_EnterMapFromMapSZ(&DCtx, "map in a map");
- QCBORDecode_GetIntInMapSZ(&DCtx, "another int", &nDecodedInt2);
- QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 1", &B1);
- QCBORDecode_GetBstrInMapSZ(&DCtx, "bytes 2", &B2);
+ QCBORDecode_GetInt64InMapSZ(&DCtx, "another int", &nDecodedInt2);
+ QCBORDecode_GetBytesInMapSZ(&DCtx, "bytes 1", &B1);
+ QCBORDecode_GetBytesInMapSZ(&DCtx, "bytes 2", &B2);
QCBORDecode_GetTextInMapSZ(&DCtx, "text 2", &S1);
QCBORDecode_ExitMap(&DCtx);