35 #ifndef qcbor_decode_h
36 #define qcbor_decode_h
40 #include "qcbor/qcbor_private.h"
204 #define QCBOR_MAX_DECODE_INPUT_SIZE (UINT32_MAX - 2)
210 #define QCBOR_MAX_TAGS_PER_ITEM QCBOR_MAX_TAGS_PER_ITEM1
216 #define QCBOR_TYPE_NONE 0
219 #define QCBOR_TYPE_ANY 1
224 #define QCBOR_TYPE_INT64 2
228 #define QCBOR_TYPE_UINT64 3
231 #define QCBOR_TYPE_ARRAY 4
234 #define QCBOR_TYPE_MAP 5
237 #define QCBOR_TYPE_BYTE_STRING 6
242 #define QCBOR_TYPE_TEXT_STRING 7
246 #define QCBOR_TYPE_POSBIGNUM 9
250 #define QCBOR_TYPE_NEGBIGNUM 10
257 #define QCBOR_TYPE_DATE_STRING 11
261 #define QCBOR_TYPE_DATE_EPOCH 12
270 #define QCBOR_TYPE_UKNOWN_SIMPLE 13
274 #define QCBOR_TYPE_DECIMAL_FRACTION 14
279 #define QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM 15
284 #define QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM 16
289 #define QCBOR_TYPE_BIGFLOAT 17
294 #define QCBOR_TYPE_BIGFLOAT_POS_BIGNUM 18
299 #define QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM 19
302 #define QCBOR_TYPE_FALSE 20
305 #define QCBOR_TYPE_TRUE 21
308 #define QCBOR_TYPE_NULL 22
311 #define QCBOR_TYPE_UNDEF 23
314 #define QCBOR_TYPE_FLOAT 26
317 #define QCBOR_TYPE_DOUBLE 27
319 #define QCBOR_TYPE_BREAK 31
323 #define QCBOR_TYPE_MAP_AS_ARRAY 32
328 #define QBCOR_TYPE_WRAPPED_CBOR 36
331 #define QCBOR_TYPE_URI 44
335 #define QCBOR_TYPE_BASE64URL 45
339 #define QCBOR_TYPE_BASE64 46
342 #define QCBOR_TYPE_REGEX 47
346 #define QCBOR_TYPE_MIME 48
349 #define QCBOR_TYPE_UUID 49
353 #define QBCOR_TYPE_WRAPPED_CBOR_SEQUENCE 75
357 #define QCBOR_TYPE_BINARY_MIME 76
362 #define QCBOR_TYPE_DAYS_STRING 77
367 #define QCBOR_TYPE_DAYS_EPOCH 78
369 #define QCBOR_TYPE_TAG 254
371 #define QCBOR_TYPE_OPTTAG QCBOR_TYPE_TAG
379 #define QCBOR_LAST_UNMAPPED_TAG (CBOR_TAG_INVALID16 - QCBOR_NUM_MAPPED_TAGS - 1)
483 #ifndef USEFULBUF_DISABLE_ALL_FLOAT
505 #ifndef USEFULBUF_DISABLE_ALL_FLOAT
506 double fSecondsFraction;
521 #ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
532 #ifndef QCBOR_DISABLE_NON_INTEGER_LABELS
541 #ifndef QCBOR_DISABLE_TAGS
570 #define QCBOR_COUNT_INDICATES_INDEFINITE_LENGTH UINT16_MAX
648 #define QCBOR_DECODE_MIN_MEM_POOL_SIZE 8
791 void *pAllocateContext,
1418 if(src > INT32_MAX || src < INT32_MIN) {
1421 *dest = (int32_t) src;
1427 QCBOR_Int64ToInt16(int64_t src, int16_t *dest)
1429 if(src > INT16_MAX || src < INT16_MIN) {
1432 *dest = (int16_t) src;
1438 QCBOR_Int64ToInt8(int64_t src, int8_t *dest)
1440 if(src > INT8_MAX || src < INT8_MIN) {
1443 *dest = (int8_t) src;
1449 QCBOR_Int64ToUInt32(int64_t src, uint32_t *dest)
1451 if(src > UINT32_MAX || src < 0) {
1454 *dest = (uint32_t) src;
1463 #define QCBOR_Int64UToInt16 QCBOR_Int64ToUInt16
1466 QCBOR_Int64ToUInt16(int64_t src, uint16_t *dest)
1468 if(src > UINT16_MAX || src < 0) {
1471 *dest = (uint16_t) src;
1477 QCBOR_Int64ToUInt8(int64_t src, uint8_t *dest)
1479 if(src > UINT8_MAX || src < 0) {
1482 *dest = (uint8_t) src;
1488 QCBOR_Int64ToUInt64(int64_t src, uint64_t *dest)
1493 *dest = (uint64_t) src;
1514 const uint64_t *puTags;
1533 uint8_t uNumAllocated;
1634 static inline uint32_t
1637 if(pMe->uLastError) {
1668 if(uErr >= QCBOR_START_OF_NOT_WELL_FORMED_ERRORS &&
1669 uErr <= QCBOR_END_OF_NOT_WELL_FORMED_ERRORS) {
1679 if(uErr >= QCBOR_START_OF_UNRECOVERABLE_DECODE_ERRORS &&
1680 uErr <= QCBOR_END_OF_UNRECOVERABLE_DECODE_ERRORS) {
1691 pMe->uLastError = (uint8_t)uError;
1700 #if QCBOR_MAP_OFFSET_CACHE_INVALID < QCBOR_MAX_DECODE_INPUT_SIZE
1701 #error QCBOR_MAP_OFFSET_CACHE_INVALID is too large
1704 #if QCBOR_NON_BOUNDED_OFFSET < QCBOR_MAX_DECODE_INPUT_SIZE
1705 #error QCBOR_NON_BOUNDED_OFFSET is too large
struct q_useful_buf UsefulBuf
static UsefulBufC UsefulInputBuf_RetrieveUndecodedInput(UsefulInputBuf *pUInBuf)
Retrieve the undecoded input buffer.
Definition: UsefulBuf.h:2548
static size_t UsefulInputBuf_Tell(UsefulInputBuf *pUInBuf)
Returns current position in input buffer.
Definition: UsefulBuf.h:2290
QCBORError
Definition: qcbor_common.h:265
@ QCBOR_SUCCESS
Definition: qcbor_common.h:267
void QCBORDecode_SetCallerConfiguredTagList(QCBORDecodeContext *pCtx, const QCBORTagListIn *pTagList)
Deprecated – Configure list of caller-selected tags to be recognized.
QCBORError QCBORDecode_PartialFinish(QCBORDecodeContext *pCtx, size_t *puConsumed)
Return number of bytes consumed so far.
void QCBORDecode_VGetNext(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem)
Get the next item (integer, byte string, array...) in the preorder traversal of the CBOR tree.
#define QCBOR_MAX_TAGS_PER_ITEM
Definition: qcbor_decode.h:210
uint64_t QCBORDecode_GetNthTagOfLast(const QCBORDecodeContext *pCtx, uint32_t uIndex)
Returns the tag numbers for last-decoded item.
QCBORError QCBORDecode_GetNextWithTags(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem, QCBORTagListOut *pTagList)
Deprecated – Gets the next item including full list of tags for item.
static void QCBORDecode_SetError(QCBORDecodeContext *pCtx, QCBORError uError)
Manually set error condition, or set user-defined error.
Definition: qcbor_decode.h:1689
QCBORError QCBORDecode_EndCheck(QCBORDecodeContext *pCtx)
Tell whether cursor is at end of the input.
QCBORError QCBORDecode_GetNext(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem)
Preorder traversal like QCBORDecode_VGetNext() without use of internal error state.
static QCBORError QCBORDecode_GetAndResetError(QCBORDecodeContext *pCtx)
Get and reset the decoding error.
Definition: qcbor_decode.h:1658
static bool QCBORDecode_IsUnrecoverableError(QCBORError uErr)
Whether a decoding error is recoverable.
Definition: qcbor_decode.h:1677
void QCBORDecode_VPeekNext(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem)
Get the next data item without consuming it.
QCBORError QCBORDecode_Finish(QCBORDecodeContext *pCtx)
Check that a decode completed successfully.
static UsefulBufC QCBORDecode_RetrieveUndecodedInput(QCBORDecodeContext *pCtx)
Retrieve the undecoded input buffer.
Definition: qcbor_decode.h:1646
uint64_t QCBORDecode_GetNthTag(QCBORDecodeContext *pCtx, const QCBORItem *pItem, uint32_t uIndex)
Returns the tag numbers for an item.
void QCBORDecode_VGetNextConsume(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem)
Get the next item, fully consuming it if it is a map or array.
bool QCBORDecode_IsTagged(QCBORDecodeContext *pCtx, const QCBORItem *pItem, uint64_t uTag)
Deprecated – Determine if a CBOR item is a particular tag.
void QCBORDecode_Init(QCBORDecodeContext *pCtx, UsefulBufC EncodedCBOR, QCBORDecodeMode nMode)
void QCBORDecode_SetUpAllocator(QCBORDecodeContext *pCtx, QCBORStringAllocate pfAllocateFunction, void *pAllocateContext, bool bAllStrings)
Sets up a custom string allocator for indefinite-length strings.
UsefulBuf(* QCBORStringAllocate)(void *pAllocateCxt, void *pOldMem, size_t uNewSize)
Prototype for the implementation of a string allocator.
Definition: qcbor_decode.h:633
static bool QCBORDecode_IsNotWellFormedError(QCBORError uErr)
Whether an error indicates non-well-formed CBOR.
Definition: qcbor_decode.h:1666
static int QCBOR_Int64ToInt32(int64_t src, int32_t *dest)
Convert int64_t to smaller integers safely.
Definition: qcbor_decode.h:1416
QCBORError QCBORDecode_PeekNext(QCBORDecodeContext *pCtx, QCBORItem *pDecodedItem)
Get the next data item without consuming it without use of internal error state.
static QCBORError QCBORDecode_GetError(QCBORDecodeContext *pCtx)
Get the decoding error.
Definition: qcbor_decode.h:1652
QCBORError QCBORDecode_SetMemPool(QCBORDecodeContext *pCtx, UsefulBuf MemPool, bool bAllStrings)
Set up the MemPool string allocator for indefinite-length strings.
static uint32_t QCBORDecode_Tell(QCBORDecodeContext *pCtx)
Get the current traversal cursort offset in the input CBOR.
Definition: qcbor_decode.h:1635
struct _QCBORItem QCBORItem
QCBORDecodeMode
Definition: qcbor_decode.h:190
@ QCBOR_DECODE_MODE_NORMAL
Definition: qcbor_decode.h:192
@ QCBOR_DECODE_MODE_MAP_STRINGS_ONLY
Definition: qcbor_decode.h:194
@ QCBOR_DECODE_MODE_MAP_AS_ARRAY
Definition: qcbor_decode.h:196
Definition: qcbor_private.h:342
Definition: qcbor_decode.h:434
union _QCBORItem::@2 label
UsefulBufC bigNum
Definition: qcbor_decode.h:518
uint8_t uSimple
Definition: qcbor_decode.h:520
UsefulBufC string
Definition: qcbor_decode.h:475
uint8_t uLabelAlloc
Definition: qcbor_decode.h:462
double dfnum
Definition: qcbor_decode.h:489
int64_t epochDays
Definition: qcbor_decode.h:512
float fnum
Definition: qcbor_decode.h:491
int64_t int64
Definition: qcbor_decode.h:468
uint64_t uint64
Definition: qcbor_decode.h:470
uint8_t uDataAlloc
Definition: qcbor_decode.h:456
UsefulBufC dateString
Definition: qcbor_decode.h:515
uint8_t uDataType
Definition: qcbor_decode.h:437
uint8_t uNestingLevel
Definition: qcbor_decode.h:445
uint8_t uLabelType
Definition: qcbor_decode.h:441
uint8_t uNextNestLevel
Definition: qcbor_decode.h:450
struct _QCBORItem::@1::@3 epochDate
uint16_t uTags[QCBOR_MAX_TAGS_PER_ITEM]
Definition: qcbor_decode.h:562
uint16_t uCount
Definition: qcbor_decode.h:482
Definition: qcbor_decode.h:416
Definition: qcbor_decode.h:1512
Definition: qcbor_decode.h:1531
Definition: UsefulBuf.h:273
Definition: UsefulBuf.h:284