Split number decoding into a separate file (#276)
* Split number decoding into a separate file
* stragglers
* split out numbers header file too
* Big re ordering of functions
* Fix ifdef fan out
---------
Co-authored-by: Laurence Lundblade <lgl@securitytheory.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f3bedd2..c37cb38 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,6 +41,7 @@
src/ieee754.c
src/qcbor_decode.c
src/qcbor_tag_decode.c
+ src/qcbor_number_decode.c
src/qcbor_encode.c
src/qcbor_err_to_str.c
src/UsefulBuf.c
diff --git a/Makefile b/Makefile
index d2ec8bf..5f6d993 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@
CFLAGS=$(CMD_LINE) -I inc -I test -Os -fPIC
-QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/qcbor_tag_decode.o src/ieee754.o src/qcbor_err_to_str.o
+QCBOR_OBJ=src/UsefulBuf.o src/qcbor_encode.o src/qcbor_decode.o src/qcbor_number_decode.o src/qcbor_tag_decode.o src/ieee754.o src/qcbor_err_to_str.o
TEST_OBJ=test/UsefulBuf_Tests.o test/qcbor_encode_tests.o \
test/qcbor_decode_tests.o test/run_tests.o \
@@ -57,9 +57,10 @@
PUBLIC_INTERFACE=inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_encode.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_spiffy_decode.h
src/UsefulBuf.o: inc/qcbor/UsefulBuf.h
-src/qcbor_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_spiffy_decode.h src/ieee754.h
-src/qcbor_tag_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_tag_decode.h
src/qcbor_encode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_encode.h src/ieee754.h
+src/qcbor_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_spiffy_decode.h src/ieee754.h
+src/tag_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_tag_decode.h
+src/number_decode.o: inc/qcbor/UsefulBuf.h inc/qcbor/qcbor_private.h inc/qcbor/qcbor_common.h inc/qcbor/qcbor_decode.h inc/qcbor/qcbor_tag_decode.h src/ieee754.h src/decode_private.h
src/iee754.o: src/ieee754.h
src/qcbor_err_to_str.o: inc/qcbor/qcbor_common.h
diff --git a/QCBOR.xcodeproj/project.pbxproj b/QCBOR.xcodeproj/project.pbxproj
index fbe0228..f9456a6 100644
--- a/QCBOR.xcodeproj/project.pbxproj
+++ b/QCBOR.xcodeproj/project.pbxproj
@@ -10,6 +10,7 @@
0FA9BEB7216CE6CA00BA646B /* qcbor_decode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB5216CE6CA00BA646B /* qcbor_decode_tests.c */; };
0FA9BEBA216DC7AD00BA646B /* qcbor_encode_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEB8216DC7AD00BA646B /* qcbor_encode_tests.c */; };
0FA9BEBD216DE31700BA646B /* UsefulBuf_Tests.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */; };
+ E7180F232CF1657B00513186 /* qcbor_number_decode.c in Sources */ = {isa = PBXBuildFile; fileRef = E7180F222CF1657A00513186 /* qcbor_number_decode.c */; };
E73B57592161CA690080D658 /* ieee754.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B57582161CA690080D658 /* ieee754.c */; };
E73B575E2161CA7C0080D658 /* float_tests.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575A2161CA7C0080D658 /* float_tests.c */; };
E73B575F2161CA7C0080D658 /* half_to_double_from_rfc7049.c in Sources */ = {isa = PBXBuildFile; fileRef = E73B575D2161CA7C0080D658 /* half_to_double_from_rfc7049.c */; };
@@ -157,6 +158,9 @@
0FA9BEB9216DC7AD00BA646B /* qcbor_encode_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = qcbor_encode_tests.h; path = test/qcbor_encode_tests.h; sourceTree = "<group>"; };
0FA9BEBB216DE31700BA646B /* UsefulBuf_Tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UsefulBuf_Tests.h; path = test/UsefulBuf_Tests.h; sourceTree = "<group>"; };
0FA9BEBC216DE31700BA646B /* UsefulBuf_Tests.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = UsefulBuf_Tests.c; path = test/UsefulBuf_Tests.c; sourceTree = "<group>"; tabWidth = 3; };
+ E7180F212CF1638F00513186 /* decode_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = decode_private.h; path = src/decode_private.h; sourceTree = "<group>"; };
+ E7180F222CF1657A00513186 /* qcbor_number_decode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = qcbor_number_decode.c; path = src/qcbor_number_decode.c; sourceTree = "<group>"; };
+ E7180F242CF2390100513186 /* qcbor_number_decode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = qcbor_number_decode.h; path = inc/qcbor/qcbor_number_decode.h; sourceTree = "<group>"; };
E73B57572161CA680080D658 /* ieee754.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.h; name = ieee754.h; path = src/ieee754.h; sourceTree = "<group>"; tabWidth = 3; };
E73B57582161CA690080D658 /* ieee754.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = ieee754.c; path = src/ieee754.c; sourceTree = "<group>"; tabWidth = 3; };
E73B575A2161CA7C0080D658 /* float_tests.c */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 3; lastKnownFileType = sourcecode.c.c; name = float_tests.c; path = test/float_tests.c; sourceTree = "<group>"; tabWidth = 3; };
@@ -288,10 +292,12 @@
E776E08B214AE06600E67947 /* src */ = {
isa = PBXGroup;
children = (
- E776E08C214AE07400E67947 /* qcbor_encode.c */,
- E776E08E214AE07500E67947 /* qcbor_decode.c */,
- E7CA1F1D2C8C337E0008F454 /* qcbor_tag_decode.c */,
E776E08D214AE07500E67947 /* UsefulBuf.c */,
+ E776E08C214AE07400E67947 /* qcbor_encode.c */,
+ E7180F212CF1638F00513186 /* decode_private.h */,
+ E776E08E214AE07500E67947 /* qcbor_decode.c */,
+ E7180F222CF1657A00513186 /* qcbor_number_decode.c */,
+ E7CA1F1D2C8C337E0008F454 /* qcbor_tag_decode.c */,
E73B57572161CA680080D658 /* ieee754.h */,
E73B57582161CA690080D658 /* ieee754.c */,
E7864765252CE63100A0C11B /* qcbor_err_to_str.c */,
@@ -302,12 +308,13 @@
E776E092214AE07C00E67947 /* inc */ = {
isa = PBXGroup;
children = (
- E743D10824CEDE2D0017899F /* qcbor_spiffy_decode.h */,
E74BF411245D6713002CE8E8 /* UsefulBuf.h */,
E78C91DF240C90C100F4CECE /* qcbor_common.h */,
- E78C91DE240C90C100F4CECE /* qcbor_decode.h */,
- E7CA1F152C8ACCAE0008F454 /* qcbor_tag_decode.h */,
E78C91E1240C90C100F4CECE /* qcbor_encode.h */,
+ E78C91DE240C90C100F4CECE /* qcbor_decode.h */,
+ E743D10824CEDE2D0017899F /* qcbor_spiffy_decode.h */,
+ E7180F242CF2390100513186 /* qcbor_number_decode.h */,
+ E7CA1F152C8ACCAE0008F454 /* qcbor_tag_decode.h */,
E78C91E0240C90C100F4CECE /* qcbor_private.h */,
E776E094214AE09700E67947 /* UsefulBuf.h */,
);
@@ -557,6 +564,7 @@
E7C960B92800A09E00FB537C /* ub-example.c in Sources */,
E743D0F324AD08020017899F /* example.c in Sources */,
0FA9BEBD216DE31700BA646B /* UsefulBuf_Tests.c in Sources */,
+ E7180F232CF1657B00513186 /* qcbor_number_decode.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff --git a/README.md b/README.md
index 0be7770..d40430d 100644
--- a/README.md
+++ b/README.md
@@ -348,7 +348,7 @@
This saves about 1KB of object code, though much of this can be saved
by not calling any functions to encode doubles or floats or
-QCBORDecode_GetNumberConvertPrecisely
+QCBORDecode_GetNumberConvertPrecisely()
With this defined, single and double-precision floating-point numbers
can still be encoded and decoded. Some conversion of floating-point to
@@ -360,7 +360,7 @@
This eliminates floating point support completely (along with related function
headers). This is useful if the compiler options deny the usage of floating
-point operations completely, and the usage soft floating point ABI is not
+point operations completely, and the usage of a soft floating point ABI is not
possible.
#### Compiler options
diff --git a/example.c b/example.c
index c489ad6..473e989 100644
--- a/example.c
+++ b/example.c
@@ -16,6 +16,7 @@
#include "qcbor/qcbor_encode.h"
#include "qcbor/qcbor_decode.h"
#include "qcbor/qcbor_spiffy_decode.h"
+#include "qcbor/qcbor_number_decode.h"
/**
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index 1305b51..0f31e26 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -1278,7 +1278,6 @@
QCBORDecode_GetNextTagNumber(QCBORDecodeContext *pCtx, uint64_t *puTagNumber);
-
/**
* @brief Returns the tag numbers for a decoded item.
*
@@ -1344,9 +1343,9 @@
uint64_t
QCBORDecode_GetNthTagNumberOfLast(QCBORDecodeContext *pCtx, uint8_t uIndex);
-
#endif /* ! QCBOR_DISABLE_TAGS */
+
/**
* @brief Check that a decode completed successfully.
*
@@ -1532,209 +1531,6 @@
QCBORDecode_SetError(QCBORDecodeContext *pCtx, QCBORError uError);
-/**
- * @brief Decode a preferred serialization big number.
- *
- * @param[in] Item The number to process.
- * @param[in] BigNumberBuf The buffer to output to.
- * @param[out] pBigNumber The resulting big number.
- * @param[in,out] pbIsNegative The sign of the resulting big number.
- *
- * This exists to process a @ref QCBORItem that is expected to be a
- * big number encoded with preferred serialization. This will turn the
- * types listed in the table below into a big number. In particular it
- * will apply the offset of one needed to get the actual value for
- * @ref QCBOR_TYPE_NEGBIGNUM. Leading zeros are removed. The value 0
- * is always returned as a one-byte big number with the value 0x00.
- *
- *| Type |
- * | ---- |
- * | @ref QCBOR_TYPE_INT64 |
- * | @ref QCBOR_TYPE_UINT64 |
- * | @ref QCBOR_TYPE_65BIT_NEG_INT |
- * | @ref QCBOR_TYPE_POSBIGNUM |
- * | @ref QCBOR_TYPE_NEGBIGNUM |
- * | @ref QCBOR_TYPE_BYTE_STRING |
- * | ---- |
- *
- * For the type @ref QCBOR_TYPE_BYTES, @c pIsNegative becomes an in
- * parameter indicating the sign.
- *
- * If @c BigNumberBuf is too small, @c pBigNum.ptr will be @c NULL and
- * @c pBigNum.len reports the required length. Note that the size of
- * the output buffer, @c *pBigNumberBuf, should be 1 byte larger than
- * the size of the @c Item.val.bignum when the input @c Item is @ref
- * QCBOR_TYPE_NEGBIGNUM because the application of the offset of one
- * for negative numbers may have an arithmetic carry. A way to size
- * the output buffer is MIN(9, Item.val.bignum.len + 1). 9 comes from
- * the length of they type @ref QCBOR_TYPE_65BIT_NEG plus the
- * possibility of an arithmetic carry.
- *
- * The object code for this is surprisingly large at about 1KB. This
- * is to apply the offset of one for the negative values and to
- * operate all the data types used by big number specific preferred
- * serialization.
- *
- * See @ref BigNumbers for a useful overview of CBOR big numbers and
- * QCBOR's support for them. See also
- * QCBORDecode_ProcessBigNumberNoPreferred(),
- * QCBORDecode_GetTBigNumber() and QCBOREncode_AddTBigNumber().
- */
-QCBORError
-QCBORDecode_ProcessBigNumber(const QCBORItem Item,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-
-/**
- * @brief Decode a big number.
- *
- * @param[in] Item The number to process.
- * @param[in] BigNumberBuf The buffer to output to.
- * @param[out] pBigNumber The resulting big number.
- * @param[out] pbIsNegative The sign of the resulting big number.
- *
- * This is the same as QCBORDecode_ProcessBigNumber(), but doesn't
- * allow @ref QCBOR_TYPE_INT64, @ref QCBOR_TYPE_UINT64 and @ref
- * QCBOR_TYPE_65BIT_NEG_INT.
- */
-QCBORError
-QCBORDecode_ProcessBigNumberNoPreferred(const QCBORItem Item,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-
-
-/**
- * @brief Convert int64_t to smaller integers safely.
- *
- * @param [in] src An @c int64_t.
- * @param [out] dest A smaller sized integer to convert to.
- *
- * @return 0 on success -1 if not
- *
- * When decoding an integer, the CBOR decoder will return the value as
- * an int64_t unless the integer is in the range of @c INT64_MAX and
- * @c UINT64_MAX. That is, unless the value is so large that it can only be
- * represented as a @c uint64_t, it will be an @c int64_t.
- *
- * CBOR itself doesn't size the individual integers it carries at
- * all. The only limits it puts on the major integer types is that they
- * are 8 bytes or less in length. Then encoders like this one use the
- * smallest number of 1, 2, 4 or 8 bytes to represent the integer based
- * on its value. There is thus no notion that one data item in CBOR is
- * a 1-byte integer and another is a 4-byte integer.
- *
- * The interface to this CBOR encoder only uses 64-bit integers. Some
- * CBOR protocols or implementations of CBOR protocols may not want to
- * work with something smaller than a 64-bit integer. Perhaps an array
- * of 1,000 integers needs to be sent and none has a value larger than
- * 50,000 and are represented as @c uint16_t.
- *
- * The sending / encoding side is easy. Integers are temporarily widened
- * to 64-bits as a parameter passing through QCBOREncode_AddInt64() and
- * encoded in the smallest way possible for their value, possibly in
- * less than an @c uint16_t.
- *
- * On the decoding side the integers will be returned at @c int64_t even if
- * they are small and were represented by only 1 or 2 bytes in the
- * encoded CBOR. The functions here will convert integers to a small
- * representation with an overflow check.
- *
- * (The decoder could have support 8 different integer types and
- * represented the integer with the smallest type automatically, but
- * this would have made the decoder more complex and code calling the
- * decoder more complex in most use cases. In most use cases on 64-bit
- * machines it is no burden to carry around even small integers as
- * 64-bit values).
- */
-static inline int
-QCBOR_Int64ToInt32(int64_t src, int32_t *dest)
-{
- if(src > INT32_MAX || src < INT32_MIN) {
- return -1;
- } else {
- *dest = (int32_t) src;
- }
- return 0;
-}
-
-static inline int
-QCBOR_Int64ToInt16(int64_t src, int16_t *dest)
-{
- if(src > INT16_MAX || src < INT16_MIN) {
- return -1;
- } else {
- *dest = (int16_t) src;
- }
- return 0;
-}
-
-static inline int
-QCBOR_Int64ToInt8(int64_t src, int8_t *dest)
-{
- if(src > INT8_MAX || src < INT8_MIN) {
- return -1;
- } else {
- *dest = (int8_t) src;
- }
- return 0;
-}
-
-static inline int
-QCBOR_Int64ToUInt32(int64_t src, uint32_t *dest)
-{
- if(src > UINT32_MAX || src < 0) {
- return -1;
- } else {
- *dest = (uint32_t) src;
- }
- return 0;
-}
-
-/**
- * https://github.com/laurencelundblade/QCBOR/pull/243
- * For backwards compatibility
- */
-#define QCBOR_Int64UToInt16 QCBOR_Int64ToUInt16
-
-static inline int
-QCBOR_Int64ToUInt16(int64_t src, uint16_t *dest)
-{
- if(src > UINT16_MAX || src < 0) {
- return -1;
- } else {
- *dest = (uint16_t) src;
- }
- return 0;
-}
-
-static inline int
-QCBOR_Int64ToUInt8(int64_t src, uint8_t *dest)
-{
- if(src > UINT8_MAX || src < 0) {
- return -1;
- } else {
- *dest = (uint8_t) src;
- }
- return 0;
-}
-
-static inline int
-QCBOR_Int64ToUInt64(int64_t src, uint64_t *dest)
-{
- if(src < 0) {
- return -1;
- } else {
- *dest = (uint64_t) src;
- }
- return 0;
-}
-
-
-
/* ========================================================================= *
diff --git a/inc/qcbor/qcbor_number_decode.h b/inc/qcbor/qcbor_number_decode.h
new file mode 100644
index 0000000..a995447
--- /dev/null
+++ b/inc/qcbor/qcbor_number_decode.h
@@ -0,0 +1,1916 @@
+/* ==========================================================================
+ * qcbor_number_decode.h -- CBOR number decoding.
+ *
+ * Copyright (c) 2020-2024, Laurence Lundblade. All rights reserved.
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * See BSD-3-Clause license in file named "LICENSE"
+ *
+ * Forked from qcbor_decode.h on 11/23/2024
+ * ========================================================================== */
+#ifndef qcbor_number_decode_h
+#define qcbor_number_decode_h
+
+
+#include "qcbor/qcbor_decode.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#if 0
+} // Keep editor indention formatting happy
+#endif
+#endif
+
+
+
+/**
+ * @file qcbor_number
+ */
+
+/** Conversion will proceed if the CBOR item to be decoded is an
+ * integer or either type 0 (unsigned) or type 1 (negative). */
+#define QCBOR_CONVERT_TYPE_XINT64 0x01
+/** Conversion will proceed if the CBOR item to be decoded is either
+ * double, single or half-precision floating-point (major type 7). */
+#define QCBOR_CONVERT_TYPE_FLOAT 0x02
+/** Conversion will proceed if the CBOR item to be decoded is a big
+ * number, positive or negative (tag 2 or tag 3). */
+#define QCBOR_CONVERT_TYPE_BIG_NUM 0x04
+/** Conversion will proceed if the CBOR item to be decoded is a
+ * decimal fraction (tag 4). */
+#define QCBOR_CONVERT_TYPE_DECIMAL_FRACTION 0x08
+/** Conversion will proceed if the CBOR item to be decoded is a big
+ * float (tag 5). */
+#define QCBOR_CONVERT_TYPE_BIGFLOAT 0x10
+
+
+
+
+/**
+ * @brief Decode next item into a signed 64-bit integer.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[out] pnValue The returned 64-bit signed integer.
+ *
+ * The CBOR data item to decode must be a positive or negative integer
+ * (CBOR major type 0 or 1). If not @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
+ *
+ * If the CBOR integer is either too large or too small to fit in an
+ * int64_t, the error @ref QCBOR_ERR_INT_OVERFLOW or
+ * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW is set. Note that type 0
+ * unsigned integers can be larger than will fit in an int64_t and
+ * type 1 negative integers can be smaller than will fit in an
+ * int64_t.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See also QCBORDecode_GetUInt64(), QCBORDecode_GetInt64Convert(),
+ * QCBORDecode_GetInt64ConvertAll() and QCBORDecode_GetDoubleConvert()
+ */
+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 into a signed 64-bit integer with basic conversions.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] pnValue The returned 64-bit signed integer.
+ *
+ * @c uConvertTypes controls what conversions this will perform and
+ * thus what CBOR types will be decoded. @c uConvertType is a bit map
+ * listing the conversions to be allowed. This function supports
+ * @ref QCBOR_CONVERT_TYPE_XINT64 and @ref QCBOR_CONVERT_TYPE_FLOAT
+ * conversions.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * If the CBOR data type can never be convered by this function or the
+ * conversion was not selected in @c uConversionTypes
+ * @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
+ *
+ * When converting floating-point values, the integer is rounded to
+ * the nearest integer using llround(). By default, floating-point
+ * suport is enabled for QCBOR.
+ *
+ * If floating-point HW use is disabled this will set
+ * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
+ * encountered. If half-precision support is disabled, this will set
+ * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
+ * is encountered.
+ *
+ * If floating-point usage is disabled this will set
+ * @ref QCBOR_ERR_ALL_FLOAT_DISABLED if a floating point value is
+ * encountered.
+ *
+ * See also QCBORDecode_GetInt64ConvertAll() which will perform the
+ * same conversions as this and a lot more at the cost of adding more
+ * object code to your executable.
+ */
+static void
+QCBORDecode_GetInt64Convert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+static void
+QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+static void
+QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+
+
+
+/**
+ * @brief Decode next item into a signed 64-bit integer with conversions.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] pnValue The returned 64-bit signed integer.
+ *
+ * This is the same as QCBORDecode_GetInt64Convert() but additionally
+ * supports conversion from positive and negative bignums, decimal
+ * fractions and big floats, including decimal fractions and big floats
+ * that use bignums. The conversion types supported are
+ * @ref QCBOR_CONVERT_TYPE_XINT64, @ref QCBOR_CONVERT_TYPE_FLOAT,
+ * @ref QCBOR_CONVERT_TYPE_BIG_NUM,
+ * @ref QCBOR_CONVERT_TYPE_DECIMAL_FRACTION and
+ * @ref QCBOR_CONVERT_TYPE_BIGFLOAT.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * Note that most these types can support numbers much larger that can
+ * be represented by in a 64-bit integer, so
+ * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW may often be encountered.
+ *
+ * When converting bignums and decimal fractions,
+ * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be set if the result
+ * is below 1, unless the mantissa is zero, in which case the
+ * coversion is successful and the value of 0 is returned.
+ *
+ * See also QCBORDecode_GetInt64ConvertAll() which does some of these
+ * conversions, but links in much less object code. See also
+ * QCBORDecode_GetUInt64ConvertAll().
+ *
+ * This relies on CBOR tags to identify big numbers, decimal fractions
+ * and big floats. It will not attempt to decode non-tag CBOR that might
+ * be one of these. (If QCBOR_DISABLE_TAGS is set, this is effectively
+ * the same as QCBORDecode_GetInt64Convert() because all the additional
+ * number types this decodes are tags).
+ */
+void
+QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+void
+QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+void
+QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue);
+
+
+/**
+ * @brief Decode next item into an unsigned 64-bit integer.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[out] puValue The returned 64-bit unsigned integer.
+ *
+ * This is the same as QCBORDecode_GetInt64(), but returns an unsigned integer
+ * and thus can only decode CBOR positive integers.
+ * @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION is set if the input is a negative
+ * integer.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See also QCBORDecode_GetUInt64Convert() and QCBORDecode_GetUInt64ConvertAll().
+ */
+static void
+QCBORDecode_GetUInt64(QCBORDecodeContext *pCtx,
+ uint64_t *puValue);
+
+static void
+QCBORDecode_GetUInt64InMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint64_t *puValue);
+
+static void
+QCBORDecode_GetUInt64InMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint64_t *puValue);
+
+
+/**
+ * @brief Decode next item as an unsigned 64-bit integer with basic conversions.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] puValue The returned 64-bit unsigned integer.
+ *
+ * This is the same as QCBORDecode_GetInt64Convert(), but returns an
+ * unsigned integer and thus sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
+ * if the value to be decoded is negatve.
+ *
+ * If floating-point HW use is disabled this will set
+ * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
+ * encountered. If half-precision support is disabled, this will set
+ * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
+ * is encountered.
+ *
+ * If floating-point usage is disabled this will set
+ * @ref QCBOR_ERR_ALL_FLOAT_DISABLED if a floating point value is
+ * encountered.
+ *
+ * See also QCBORDecode_GetUInt64Convert() and
+ * QCBORDecode_GetUInt64ConvertAll().
+ */
+static void
+QCBORDecode_GetUInt64Convert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+static void
+QCBORDecode_GetUInt64ConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+static void
+QCBORDecode_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+
+/**
+ * @brief Decode next item into an unsigned 64-bit integer with conversions
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] puValue The returned 64-bit unsigned integer.
+ *
+ * This is the same as QCBORDecode_GetInt64ConvertAll(), but returns
+ * an unsigned integer and thus sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
+ * if the value to be decoded is negatve.
+ *
+ * See also QCBORDecode_GetUInt64() and QCBORDecode_GetUInt64Convert().
+ */
+void
+QCBORDecode_GetUInt64ConvertAll(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+void
+QCBORDecode_GetUInt64ConvertAllInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+void
+QCBORDecode_GetUInt64ConvertAllInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue);
+
+
+
+
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+/**
+ * @brief Decode next item into a double floating-point value.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[out] pValue The returned floating-point value.
+ *
+ * The CBOR data item to decode must be a half-precision,
+ * single-precision or double-precision floating-point value. If not
+ * @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
+ *
+ * If floating-point HW use is disabled this will set
+ * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
+ * encountered. If half-precision support is disabled, this will set
+ * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
+ * is encountered.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See also QCBORDecode_GetDoubleConvert() and
+ * QCBORDecode_GetDoubleConvertAll().
+ */
+static void
+QCBORDecode_GetDouble(QCBORDecodeContext *pCtx,
+ double *pValue);
+
+static void
+QCBORDecode_GetDoubleInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ double *pdValue);
+
+static void
+QCBORDecode_GetDoubleInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ double *pdValue);
+
+
+/**
+ * @brief Decode next item into a double floating-point with basic conversion.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] pdValue The returned floating-point value.
+ *
+ * This will decode CBOR integer and floating-point numbers, returning
+ * them as a double floating-point number. This function supports
+
+ * @ref QCBOR_CONVERT_TYPE_XINT64 and @ref QCBOR_CONVERT_TYPE_FLOAT
+ * conversions. If the encoded CBOR is not one of the requested types
+ * or a type not supported by this function, @ref QCBOR_ERR_UNEXPECTED_TYPE
+ * is set.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * If floating-point HW use is disabled this will set
+ * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
+ * encountered. If half-precision support is disabled, this will set
+ * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number is
+ * encountered.
+ *
+ * Positive and negative integers can always be converted to
+ * floating-point, so this will never error on CBOR major type 0 or 1.
+ *
+ * Note that a large 64-bit integer can have more precision (64 bits)
+ * than even a double floating-point (52 bits) value, so there is loss
+ * of precision in some conversions.
+ *
+ * See also QCBORDecode_GetDouble() and QCBORDecode_GetDoubleConvertAll().
+ */
+static void
+QCBORDecode_GetDoubleConvert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+static void
+QCBORDecode_GetDoubleConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+static void
+QCBORDecode_GetDoubleConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+
+/**
+ * @brief Decode next item as a double floating-point value with conversion.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uConvertTypes The integer conversion options.
+ * @param[out] pdValue The returned floating-point value.
+ *
+ * This is the same as QCBORDecode_GetDoubleConvert() but supports
+ * many more conversions at the cost of linking in more object
+ * code. The conversion types supported are @ref QCBOR_CONVERT_TYPE_XINT64,
+ * @ref QCBOR_CONVERT_TYPE_FLOAT, @ref QCBOR_CONVERT_TYPE_BIG_NUM,
+ * @ref QCBOR_CONVERT_TYPE_DECIMAL_FRACTION and
+ * @ref QCBOR_CONVERT_TYPE_BIGFLOAT.
+ *
+ * Big numbers, decimal fractions and big floats that are too small or
+ * too large to be reprented as a double floating-point number will be
+ * returned as plus or minus zero or infinity rather than setting an
+ * under or overflow error.
+ *
+ * There is often loss of precision in the conversion.
+ *
+ * See also QCBORDecode_GetDoubleConvert() and QCBORDecode_GetDoubleConvert().
+ */
+void
+QCBORDecode_GetDoubleConvertAll(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+void
+QCBORDecode_GetDoubleConvertAllInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+void
+QCBORDecode_GetDoubleConvertAllInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ double *pdValue);
+
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
+/**
+ * @brief dCBOR Decode next as a number with precision-preserving conversions.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[out] pNumber The returned number.
+ *
+ * This gets the next item as a number and returns it as a C data type
+ * such that no precision is lost.
+ *
+ * This is primarily works with integers and floats for both the
+ * to-be-decoded CBOR and the decoded types.
+ *
+ * The CBOR input can be integers (major type 0 or 1) or floats (major
+ * type 7). If not these, \ref QCBOR_ERR_UNEXPECTED_TYPE will be set.
+ *
+ * The conversion is as follows.
+ *
+ * Whole numbers from \c INT64_MIN to \c INT64_MAX will be returned as
+ * int64_t indicated as \ref QCBOR_TYPE_INT64. This includes
+ * conversion of floating-point values that are whole numbers.
+ *
+ * Whole numbers from \c INT64_MAX +1 to \c UINT64_MAX will be
+ * returned as uint64_t indicated as \ref QCBOR_TYPE_UINT64, again
+ * including conversion of floating-point values that are whole
+ * numbers.
+ *
+ * Most other numbers are returned as a double as indicated by
+ * \ref QCBOR_TYPE_DOUBLE floating point with one set of exceptions.
+ *
+ * The exception is negative whole numbers in the range of -(2^63 + 1)
+ * to -(2^64) that have too much precision to be represented as a
+ * double. Doubles have only 52 bits of precision, so they can't
+ * precisely represent every whole integer in this range. CBOR can
+ * represent these values with 64-bits of precision and when this
+ * function encounters them they are returned as \ref
+ * QCBOR_TYPE_65BIT_NEG_INT. See the description of this type for
+ * instructions to gets its value. Also see
+ * QCBORDecode_ProcessBigNumber().
+ *
+ * To give an example, the value -18446744073709551616 can't be
+ * represented by an int64_t or uint64_t, but can be represented by a
+ * double so it is returned by this function as a double. The value
+ * -18446744073709551617 however can't be represented by a double
+ * because it has too much precision, so it is returned as \ref
+ * QCBOR_TYPE_65BIT_NEG_INT.
+ *
+ * This is useful for DCBOR which essentially combines floats and
+ * integers into one number space.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See also QCBORDecode_GetNumberConvertPreciselyBig().
+ */
+void
+QCBORDecode_GetNumberConvertPrecisely(QCBORDecodeContext *pCtx,
+ QCBORItem *pNumber);
+
+#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT */
+#endif /* ! QCBOR_DISABLE_PREFERRED_FLOAT */
+
+
+/**
+ * @brief Decode a preferred serialization big number.
+ *
+ * @param[in] Item The number to process.
+ * @param[in] BigNumberBuf The buffer to output to.
+ * @param[out] pBigNumber The resulting big number.
+ * @param[in,out] pbIsNegative The sign of the resulting big number.
+ *
+ * This exists to process a @ref QCBORItem that is expected to be a
+ * big number encoded with preferred serialization. This will turn the
+ * types listed in the table below into a big number. In particular it
+ * will apply the offset of one needed to get the actual value for
+ * @ref QCBOR_TYPE_NEGBIGNUM. Leading zeros are removed. The value 0
+ * is always returned as a one-byte big number with the value 0x00.
+ *
+ *| Type |
+ * | ---- |
+ * | @ref QCBOR_TYPE_INT64 |
+ * | @ref QCBOR_TYPE_UINT64 |
+ * | @ref QCBOR_TYPE_65BIT_NEG_INT |
+ * | @ref QCBOR_TYPE_POSBIGNUM |
+ * | @ref QCBOR_TYPE_NEGBIGNUM |
+ * | @ref QCBOR_TYPE_BYTE_STRING |
+ * | ---- |
+ *
+ * For the type @ref QCBOR_TYPE_BYTES, @c pIsNegative becomes an in
+ * parameter indicating the sign.
+ *
+ * If @c BigNumberBuf is too small, @c pBigNum.ptr will be @c NULL and
+ * @c pBigNum.len reports the required length. Note that the size of
+ * the output buffer, @c *pBigNumberBuf, should be 1 byte larger than
+ * the size of the @c Item.val.bignum when the input @c Item is @ref
+ * QCBOR_TYPE_NEGBIGNUM because the application of the offset of one
+ * for negative numbers may have an arithmetic carry. A way to size
+ * the output buffer is MIN(9, Item.val.bignum.len + 1). 9 comes from
+ * the length of they type @ref QCBOR_TYPE_65BIT_NEG plus the
+ * possibility of an arithmetic carry.
+ *
+ * The object code for this is surprisingly large at about 1KB. This
+ * is to apply the offset of one for the negative values and to
+ * operate all the data types used by big number specific preferred
+ * serialization.
+ *
+ * See @ref BigNumbers for a useful overview of CBOR big numbers and
+ * QCBOR's support for them. See also
+ * QCBORDecode_ProcessBigNumberNoPreferred(),
+ * QCBORDecode_GetTBigNumber() and QCBOREncode_AddTBigNumber().
+ */
+QCBORError
+QCBORDecode_ProcessBigNumber(const QCBORItem Item,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+
+/**
+ * @brief Decode a big number.
+ *
+ * @param[in] Item The number to process.
+ * @param[in] BigNumberBuf The buffer to output to.
+ * @param[out] pBigNumber The resulting big number.
+ * @param[out] pbIsNegative The sign of the resulting big number.
+ *
+ * This is the same as QCBORDecode_ProcessBigNumber(), but doesn't
+ * allow @ref QCBOR_TYPE_INT64, @ref QCBOR_TYPE_UINT64 and @ref
+ * QCBOR_TYPE_65BIT_NEG_INT.
+ */
+QCBORError
+QCBORDecode_ProcessBigNumberNoPreferred(const QCBORItem Item,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+
+
+
+
+/**
+ * @brief Decode next item as a big number encoded using preferred serialization.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
+ * @param[in] BigNumberBuf The buffer to write the result into.
+ * @param[out] pBigNumber The decoded big number, most significant
+ * byte first (network byte order).
+ * @param[in,out] pbIsNegative Set to true if the resulting big number is negative.
+ *
+ * This decodes CBOR tag numbers 2 and 3, positive and negative big
+ * numbers, as defined in [RFC 8949 section 3.4.3]
+ * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3). This
+ * decodes preferred serialization described specifically for big
+ * numbers.
+ *
+ * See QCBORDecode_PreferedBigNumber() which performs the bulk of this.
+ *
+ * The type processing rules are as follows.
+ *
+ * This always succeeds on type 0 and 1 integers (@ref QCBOR_TYPE_INT64,
+ * @ref QCBOR_TYPE_UINT64 and @ref QCBOR_TYPE_65BIT_NEG_INT) no matter what
+ * @c uTagRequirement is. The rest of the rules pertain to what happens
+ * if the CBOR is not type 0 or type 1.
+ *
+ * If @c uTagRequirement is @ref QCBOR_TAG_REQUIREMENT_TAG, this
+ * expects a full tag 2 or tag 3 big number.
+ *
+ * If @c uTagRequreiement is @ref QCBOR_TAG_REQUIREMENT_NOT_A_TAG then
+ * this expects a byte string.
+ *
+ * If @ref QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG, then this will succeed on
+ * either a byte string or a tag 2 or 3.
+ *
+ * If the item is a bare byte string, not a tag 2 or 3, then
+ * @c pbIsNegative is an input parameter that determines the sign of the
+ * big number. The sign must be known because the decoding of a
+ * positive big number is different than a negative.
+ *
+ * This works whether or not QCBORDecode_StringsTagCB() is installed
+ * to process tags 2 and 3.
+ *
+ * See @ref BigNumbers for a useful overview of CBOR big numbers and
+ * QCBOR's support for them. See QCBOREncode_AddTBigNumber(), the
+ * encode counter part for this. See also
+ * QCBORDecode_GetTBigNumberNoPreferred() and
+ * QCBORDecode_GetTBigNumberRaw().
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See @ref Tag-Usage for discussion on tag requirements.
+ */
+void
+QCBORDecode_GetTBigNumber(QCBORDecodeContext *pCtx,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+
+/**
+ * @brief Decode next item as a big number without preferred serialization.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
+ * @param[in] BigNumberBuf The buffer to write the result into.
+ * @param[out] pBigNumber The decoded big number, most significant
+ * byte first (network byte order).
+ * @param[in,out] pbIsNegative Set to true if the returned big number is negative.
+ *
+ * This is the same as QCBORDecode_GetTBigNumber(), but will error out
+ * on type 0 and 1 integers as it doesn't support the preferred
+ * serialization specific for big numbers.
+ *
+ * See @ref BigNumbers for a useful overview of CBOR big numbers and
+ * QCBOR's support for them. See QCBOREncode_AddTBigNumberNoPreferred(),
+ * the encode counter part for this. See also QCBORDecode_GetTBigNumber()
+ * and QCBORDecode_GetTBigNumberRaw().
+ */
+void
+QCBORDecode_GetTBigNumberNoPreferred(QCBORDecodeContext *pCtx,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberNoPreferredInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberNoPreferredInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+
+ /**
+ * @brief Decode the next item as a big number with no processing
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
+ * @param[out] pBigNumber The decoded big number, most significant
+ * byte first (network byte order).
+ * @param[out] pbIsNegative Is @c true if the big number is negative. This
+ * is only valid when @c uTagRequirement is
+ * @ref QCBOR_TAG_REQUIREMENT_TAG.
+ *
+ * This decodes CBOR tag numbers 2 and 3, positive and negative big
+ * numbers, as defined in [RFC 8949 section 3.4.3]
+ * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3).
+ *
+ * This returns the byte string representing the big number
+ * directly. It does not apply the required the offset of one for
+ * negative big numbers. It will error out big numbers that have been
+ * encoded as type 0 and 1 integer because of big number preferred
+ * serialization.
+ *
+ * This is most useful when a big number library has been linked, and
+ * it can be (trivially) used to perform the offset of one for
+ * negative numbers.
+ *
+ * This links in much less object code than QCBORDecode_GetTBigNumber() and
+ * QCBORDecode_GetTBigNumberNoPreferred().
+ *
+ * This does the same minimal processing as installing QCBORDecode_StringsTagCB()
+ * installed to handle @ref CBOR_TAG_POS_BIGNUM and @ref CBOR_TAG_NEG_BIGNUM
+ * so QCBORDecode_VGetNext() returns a @ref QCBORItem of type
+ * @ref QCBOR_TYPE_POSBIGNUM or @ref QCBOR_TYPE_POSBIGNUM
+ *
+ * See @ref BigNumbers for a useful overview of CBOR big numbers and
+ * QCBOR's support for them. See QCBOREncode_AddTBigNumberRaw() for
+ * the encoding counter part. See QCBORDecode_GetTBigNumber() which
+ * does perform the offset for negative numbers and handles preferred
+ * serialization big numbers.
+ *
+ * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See @ref Tag-Usage for discussion on tag requirements.
+ */
+void
+QCBORDecode_GetTBigNumberRaw(QCBORDecodeContext *pCtx,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberRawInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+void
+QCBORDecode_GetTBigNumberRawInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative);
+
+
+
+
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+/**
+ * @brief Decode the next item as a decimal fraction.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[out] pnMantissa The mantissa.
+ * @param[out] pnExponent The base 10 exponent.
+ *
+ * The input to decode must be a decimal fraction as defined in
+ * [RFC 8949 section 3.4.4]
+ * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.4). That
+ * is, an array of two numbers, the first of which is the exponent and
+ * the second is the mantissa.
+ *
+ * Depending on @c uTagRequirement, the tag number
+ * @ref CBOR_TAG_DECIMAL_FRACTION (4) may or may not need to be
+ * present before the array. See @ref Tag-Usage.
+ *
+ * The exponent must always be an integer (CBOR type 0 or 1). The
+ * mantissa may be an integer or a big number. If it is a big number,
+ * the tag number 2 or 3 must be present.
+ *
+ * The exponent is limited to between @c INT64_MIN and
+ * @c INT64_MAX while CBOR allows the range of @c -UINT64_MAX to @c UINT64_MAX.
+ *
+ * The mantissa is always returned as an @c int64_t. If the value
+ * won't fit, @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be
+ * set. Use QCBORDecode_GetTDecimalFractionBigMantissa() to avoid the
+ * limit to @c int64_t.
+ *
+ * The value of this is computed by:
+ *
+ * mantissa * ( 10 ** exponent )
+ *
+ * Various format and type issues will result in @ref QCBOR_ERR_BAD_EXP_AND_MANTISSA
+ * being set. See @ref Decode-Errors-Overview "Decode Errors
+ * Overview".
+ *
+ * See also QCBORDecode_GetInt64ConvertAll(),
+ * QCBORDecode_GetUInt64ConvertAll() and
+ * QCBORDecode_GetDoubleConvertAll() which can also decode decimal
+ * fractions.
+ *
+ * See also @ref CBOR_TAG_DECIMAL_FRACTION,
+ * QCBOREncode_AddTDecimalFraction(), @ref QCBOR_TYPE_DECIMAL_FRACTION.
+ *
+ * If QCBOR_DISABLE_TAGS is set, the only input this will decode is an
+ * array of two integers. It will set an error if the the array is
+ * preceded by by a tag number or if the mantissa is a big number.
+ */
+void
+QCBORDecode_GetTDecimalFraction(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/**
+ * @brief Decode the next item as a decimal fraction with a big number mantissa.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[in] MantissaBuffer The buffer in which to put the mantissa.
+ * @param[out] pMantissa The big num mantissa.
+ * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
+ * @param[out] pnExponent The base 10 exponent.
+ *
+ * This is the same as QCBORDecode_GetTDecimalFraction() except the
+ * mantissa is returned as a big number.
+ *
+ * In the encoded CBOR, the mantissa may be a type 0 (positive
+ * integer), type 1 (negative integer), type 2 tag 2 (positive big
+ * number) or type 2 tag 3 (negative big number). This implementation
+ * will convert all these to a big number. The limit to this
+ * conversion is the size of @c MantissaBuffer.
+ *
+ * See also QCBORDecode_GetInt64ConvertAll(),
+ * QCBORDecode_GetUInt64ConvertAll() and
+ * QCBORDecode_GetDoubleConvertAll() which can convert decimal
+ * fractions.
+ *
+ * See also @ref CBOR_TAG_DECIMAL_FRACTION,
+ * QCBOREncode_AddTDecimalFractionBigMantissa(), @ref QCBOR_TYPE_DECIMAL_FRACTION
+ * and QCBORDecode_GetTDecimalFraction().
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissa(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionBigMantissaInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pbMantissaIsNegative,
+ bool *pbIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionBigMantissaInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+/**
+ * @brief Decode the next item as a decimal fraction with a big number mantissa raw.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[in] MantissaBuffer The buffer in which to put the mantissa.
+ * @param[out] pMantissa The big num mantissa.
+ * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
+ * @param[out] pnExponent The base 10 exponent.
+ *
+ * This is the same as QCBORDecode_GetTDecimalFractionBigMantissa() except the
+ * negative mantissas are NOT offset by one and this links in less object code.
+ *
+ * In the encoded CBOR, the mantissa may be a type 0 (positive
+ * integer), type 1 (negative integer), type 2 tag 2 (positive big
+ * number) or type 2 tag 3 (negative big number). This implementation
+ * will convert all these to a big number. The limit to this
+ * conversion is the size of @c MantissaBuffer.
+ *
+ * See also QCBORDecode_GetInt64ConvertAll(),
+ * QCBORDecode_GetUInt64ConvertAll() and
+ * QCBORDecode_GetDoubleConvertAll() which can convert decimal
+ * fractions.
+ *
+ * See also @ref CBOR_TAG_DECIMAL_FRACTION,
+ * QCBOREncode_AddTDecimalFractionBigMantissaRaw(), @ref QCBOR_TYPE_DECIMAL_FRACTION
+ * and QCBORDecode_GetTDecimalFractionBigMantissa().
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRaw(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pbMantissaIsNegative,
+ bool *pbIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+/**
+ * @brief Decode the next item as a big float.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[out] pnMantissa The mantissa.
+ * @param[out] pnExponent The base 2 exponent.
+ *
+ * The input to decode must be a big float defined in [RFC 8949 section 3.4.4]
+ * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.4). That
+ * is, an array of two numbers, the first of which is the exponent and
+ * the second is the mantissa.
+ *
+ * Depending on @c uTagRequirement, the tag number
+ * @ref CBOR_TAG_BIG_FLOAT (5) may or may not need to be present
+ * before the array. See @ref Tag-Usage.
+ *
+ * The exponent must always be an integer (CBOR type 0 or 1). The
+ * mantissa may be an integer or a big number. If it is a big number,
+ * the tag number 2 or 3 must be present.
+ *
+ * This implementation limits the exponent to between @c INT64_MIN and
+ * @c INT64_MAX while CBOR allows the range of @c -UINT64_MAX to @c UINT64_MAX.
+ *
+ * The mantissa is always returned as an @c int64_t. If the value
+ * won't fit, @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be
+ * set. Use QCBORDecode_GetBigFloastBigNumber() to avoid the
+ * limit to @c int64_t.
+ *
+ * mantissa * ( 2 ** exponent )
+ *
+ * Various format and type issues will result in
+ * @ref QCBOR_ERR_BAD_EXP_AND_MANTISSA being set. See
+ * @ref Decode-Errors-Overview "Decode Errors Overview".
+ *
+ * See also QCBORDecode_GetInt64ConvertAll(),
+ * QCBORDecode_GetUInt64ConvertAll() and
+ * QCBORDecode_GetDoubleConvertAll() which can convert big floats.
+ *
+ * See also @ref CBOR_TAG_BIGFLOAT, QCBOREncode_AddTBigFloat(),
+ * @ref QCBOR_TYPE_BIGFLOAT and QCBORDecode_GetTBigFloatBigMantissa().
+ *
+ * If QCBOR_DISABLE_TAGS is set, the only input this will decode is an
+ * array of two integers. It will set an error if the the array is
+ * preceded by by a tag number or if the mantissa is a big number.
+ */
+void
+QCBORDecode_GetTBigFloat(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTBigFloatInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTBigFloatInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+
+/**
+ * @brief Decode the next item as a big float with a big number mantissa.
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[in] MantissaBuffer The buffer in which to put the mantissa.
+ * @param[out] pMantissa The big num mantissa.
+ * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
+ * @param[out] pnExponent The base 2 exponent.
+ *
+ * This is the same as QCBORDecode_GetTBigFloat() except the mantissa
+ * is returned as a big number. The only limit to precision is the
+ * size of @c MantissaBuffer.
+ *
+ * The encoded mantissa may be an integer or a big number. The
+ * standard CBOR offset of 1 for negative is applied, so the mantissa can be used as
+ * returned.
+ *
+ * See also @ref CBOR_TAG_BIGFLOAT,
+ * QCBOREncode_AddTBigFloatBigNumber(), @ref QCBOR_TYPE_BIGFLOAT and
+ * QCBORDecode_GetTBigFloat().
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissa(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+void
+QCBORDecode_GetTBigFloatBigMantissaInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTBigFloatBigMantissaInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+/**
+ * @brief Decode the next item as a big float with a big number mantissa with out offsetting the mantissa
+ *
+ * @param[in] pCtx The decode context.
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[in] MantissaBuffer The buffer in which to put the mantissa.
+ * @param[out] pMantissa The big num mantissa.
+ * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
+ * @param[out] pnExponent The base 2 exponent.
+ *
+ * This is the same as QCBORDecode_GetBigFloat() except the mantissa
+ * is returned as a big number. The only limit to precision is the
+ * size of @c MantissaBuffer.
+ *
+ * The encoded mantissa may be an integer or a big number. The
+ * standard CBOR offset of 1 for negative is NOT applied. If the ma
+ * mantissa is negative, one must be added to get it's actual value.
+ *
+ * Because this doesn't offset the negative big numbers, this links in
+ * a lot less object code. It is suitable for uses where a big number
+ * library is already linked in for other purposes as it can trivially
+ * do the increment by one.
+ *
+ * See also @ref CBOR_TAG_BIGFLOAT,
+ * QCBOREncode_AddTBigFloatBigNumber(), @ref QCBOR_TYPE_BIGFLOAT and
+ * QCBORDecode_GetTBigFloat().
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaRaw(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+
+void
+QCBORDecode_GetTBigFloatBigMantissaRawInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+void
+QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+
+/**
+ * @brief Convert int64_t to smaller integers safely.
+ *
+ * @param [in] src An @c int64_t.
+ * @param [out] dest A smaller sized integer to convert to.
+ *
+ * @return 0 on success -1 if not
+ *
+ * When decoding an integer, the CBOR decoder will return the value as
+ * an int64_t unless the integer is in the range of @c INT64_MAX and
+ * @c UINT64_MAX. That is, unless the value is so large that it can only be
+ * represented as a @c uint64_t, it will be an @c int64_t.
+ *
+ * CBOR itself doesn't size the individual integers it carries at
+ * all. The only limits it puts on the major integer types is that they
+ * are 8 bytes or less in length. Then encoders like this one use the
+ * smallest number of 1, 2, 4 or 8 bytes to represent the integer based
+ * on its value. There is thus no notion that one data item in CBOR is
+ * a 1-byte integer and another is a 4-byte integer.
+ *
+ * The interface to this CBOR encoder only uses 64-bit integers. Some
+ * CBOR protocols or implementations of CBOR protocols may not want to
+ * work with something smaller than a 64-bit integer. Perhaps an array
+ * of 1,000 integers needs to be sent and none has a value larger than
+ * 50,000 and are represented as @c uint16_t.
+ *
+ * The sending / encoding side is easy. Integers are temporarily widened
+ * to 64-bits as a parameter passing through QCBOREncode_AddInt64() and
+ * encoded in the smallest way possible for their value, possibly in
+ * less than an @c uint16_t.
+ *
+ * On the decoding side the integers will be returned at @c int64_t even if
+ * they are small and were represented by only 1 or 2 bytes in the
+ * encoded CBOR. The functions here will convert integers to a small
+ * representation with an overflow check.
+ *
+ * (The decoder could have support 8 different integer types and
+ * represented the integer with the smallest type automatically, but
+ * this would have made the decoder more complex and code calling the
+ * decoder more complex in most use cases. In most use cases on 64-bit
+ * machines it is no burden to carry around even small integers as
+ * 64-bit values).
+ */
+static inline int
+QCBOR_Int64ToInt32(int64_t src, int32_t *dest)
+{
+ if(src > INT32_MAX || src < INT32_MIN) {
+ return -1;
+ } else {
+ *dest = (int32_t) src;
+ }
+ return 0;
+}
+
+static inline int
+QCBOR_Int64ToInt16(int64_t src, int16_t *dest)
+{
+ if(src > INT16_MAX || src < INT16_MIN) {
+ return -1;
+ } else {
+ *dest = (int16_t) src;
+ }
+ return 0;
+}
+
+static inline int
+QCBOR_Int64ToInt8(int64_t src, int8_t *dest)
+{
+ if(src > INT8_MAX || src < INT8_MIN) {
+ return -1;
+ } else {
+ *dest = (int8_t) src;
+ }
+ return 0;
+}
+
+static inline int
+QCBOR_Int64ToUInt32(int64_t src, uint32_t *dest)
+{
+ if(src > UINT32_MAX || src < 0) {
+ return -1;
+ } else {
+ *dest = (uint32_t) src;
+ }
+ return 0;
+}
+
+/**
+ * https://github.com/laurencelundblade/QCBOR/pull/243
+ * For backwards compatibility
+ */
+#define QCBOR_Int64UToInt16 QCBOR_Int64ToUInt16
+
+static inline int
+QCBOR_Int64ToUInt16(int64_t src, uint16_t *dest)
+{
+ if(src > UINT16_MAX || src < 0) {
+ return -1;
+ } else {
+ *dest = (uint16_t) src;
+ }
+ return 0;
+}
+
+static inline int
+QCBOR_Int64ToUInt8(int64_t src, uint8_t *dest)
+{
+ if(src > UINT8_MAX || src < 0) {
+ return -1;
+ } else {
+ *dest = (uint8_t) src;
+ }
+ return 0;
+}
+
+static inline int
+QCBOR_Int64ToUInt64(int64_t src, uint64_t *dest)
+{
+ if(src < 0) {
+ return -1;
+ } else {
+ *dest = (uint64_t) src;
+ }
+ return 0;
+}
+
+
+
+
+
+
+/* ========================================================================= *
+ * BEGINNING OF DEPRECATED FUNCTION DECLARATIONS *
+ * *
+ * There is no plan to remove these in future versions. *
+ * They just have been replaced by something better. *
+ * ========================================================================= */
+
+
+/* Deprecated. Use QCBORDecode_GetTBigNumberRaw() instead. */
+static void
+QCBORDecode_GetBignum(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBufC *pValue,
+ bool *pbIsNegative);
+
+/* Deprecated. Use QCBORDecode_GetTBigNumberRawInMapN() instead. */
+static void
+QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pValue,
+ bool *pbIsNegative);
+
+/* Deprecated. Use QCBORDecode_GetTBigNumberRawInMapSZ() instead. */
+static void
+QCBORDecode_GetBignumInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pValue,
+ bool *pbIsNegative);
+
+#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
+/* Deprecated. Use QCBORDecode_GetTDecimalFraction() instead. */
+static void
+QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTDecimalFractionInMapN() instead. */
+static void
+QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTDecimalFractionInMapSZ() instead. */
+static void
+QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRaw() instead. */
+/*
+ TODO: integrate this comment better
+* For QCBOR before v1.5, this function had a bug where
+* by the negative mantissa sometimes had the offset of
+* one applied, making this function somewhat usless for
+* negative mantissas. Specifically if the to-be-decode CBOR
+* was a type 1 integer the offset was applied and when it
+* was a tag 3, the offset was not applied. It is possible
+* that a tag 3 could contain a value in the range of a type 1
+* integer. @ref QCBORExpAndMantissa is
+* correct and can be used instead of this. */
+static void
+QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN() instead */
+static void
+QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pbMantissaIsNegative,
+ bool *pbIsNegative,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ() instead. */
+static void
+QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloat() instead. */
+static void
+QCBORDecode_GetBigFloat(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloatInMapN() instead. */
+static void
+QCBORDecode_GetBigFloatInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloatInMapSZ() instead. */
+static void
+QCBORDecode_GetBigFloatInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRaw() instead. */
+static void
+QCBORDecode_GetBigFloatBig(QCBORDecodeContext *pCtx,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRawInMapN() instead. */
+static void
+QCBORDecode_GetBigFloatBigInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+
+/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ() instead. */
+static void
+QCBORDecode_GetBigFloatBigInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent);
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+
+/* ========================================================================= *
+ * END OF DEPRECATED FUNCTION DECLARATIONS *
+ * ========================================================================= */
+
+
+
+
+/* ========================================================================= *
+ * BEGINNING OF PRIVATE INLINE IMPLEMENTATION *
+ * ========================================================================= */
+
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetUInt64Convert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem);
+
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetUInt64ConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem);
+
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem);
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetInt64Convert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem);
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetInt64ConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem);
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem);
+
+
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetDoubleConvert(QCBORDecodeContext *pCtx,
+ uint32_t uConvertTypes,
+ double *pValue,
+ QCBORItem *pItem);
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetDoubleConvertInMapN(QCBORDecodeContext *pCtx,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ double *pdValue,
+ QCBORItem *pItem);
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetDoubleConvertInMapSZ(QCBORDecodeContext *pCtx,
+ const char *szLabel,
+ uint32_t uConvertTypes,
+ double *pdValue,
+ QCBORItem *pItem);
+#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT */
+
+
+/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
+void
+QCBORDecode_Private_GetTaggedString(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ uint8_t uQCBOR_Type,
+ uint64_t uTagNumber,
+ UsefulBufC *pBstr);
+
+void
+QCBORDecode_Private_GetTaggedStringInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ const uint8_t uQCBOR_Type,
+ const uint64_t uTagNumber,
+ UsefulBufC *pString);
+
+
+
+
+
+
+
+void
+QCBORDecode_Private_GetTaggedStringInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ uint8_t uQCBOR_Type,
+ uint64_t uTagNumber,
+ UsefulBufC *pString);
+
+
+
+
+static inline void
+QCBORDecode_GetUInt64Convert(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetUInt64Convert(pMe, uConvertTypes, puValue, &Item);
+}
+
+static inline void
+QCBORDecode_GetUInt64ConvertInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetUInt64ConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ puValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetUInt64ConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ puValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetUInt64(QCBORDecodeContext *pMe, uint64_t *puValue)
+{
+ QCBORDecode_GetUInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, puValue);
+}
+
+static inline void
+QCBORDecode_GetUInt64InMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ uint64_t *puValue)
+{
+ QCBORDecode_GetUInt64ConvertInMapN(pMe,
+ nLabel,
+ QCBOR_CONVERT_TYPE_XINT64,
+ puValue);
+}
+
+static inline void
+QCBORDecode_GetUInt64InMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint64_t *puValue)
+{
+ QCBORDecode_GetUInt64ConvertInMapSZ(pMe,
+ szLabel,
+ QCBOR_CONVERT_TYPE_XINT64,
+ puValue);
+}
+
+
+
+static inline void
+QCBORDecode_GetInt64Convert(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetInt64Convert(pMe, uConvertTypes, pnValue, &Item);
+}
+
+static inline void
+QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetInt64ConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ pnValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetInt64ConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ pnValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetInt64(QCBORDecodeContext *pMe, int64_t *pnValue)
+{
+ QCBORDecode_GetInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, pnValue);
+}
+
+static inline void
+QCBORDecode_GetInt64InMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ int64_t *pnValue)
+{
+ QCBORDecode_GetInt64ConvertInMapN(pMe,
+ nLabel,
+ QCBOR_CONVERT_TYPE_XINT64,
+ pnValue);
+}
+
+static inline void
+QCBORDecode_GetInt64InMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ int64_t *pnValue)
+{
+ QCBORDecode_GetInt64ConvertInMapSZ(pMe,
+ szLabel,
+ QCBOR_CONVERT_TYPE_XINT64,
+ pnValue);
+}
+
+
+
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+static inline void
+QCBORDecode_GetDoubleConvert(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetDoubleConvert(pMe, uConvertTypes, pdValue, &Item);
+}
+
+static inline void
+QCBORDecode_GetDoubleConvertInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ uint32_t uConvertTypes,
+ double *pdValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetDoubleConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ pdValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetDoubleConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetDoubleConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ pdValue,
+ &Item);
+}
+
+static inline void
+QCBORDecode_GetDouble(QCBORDecodeContext *pMe, double *pValue)
+{
+ QCBORDecode_GetDoubleConvert(pMe, QCBOR_CONVERT_TYPE_FLOAT, pValue);
+}
+
+static inline void
+QCBORDecode_GetDoubleInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ double *pdValue)
+{
+ QCBORDecode_GetDoubleConvertInMapN(pMe,
+ nLabel,
+ QCBOR_CONVERT_TYPE_FLOAT,
+ pdValue);
+}
+
+static inline void
+QCBORDecode_GetDoubleInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ double *pdValue)
+{
+ QCBORDecode_GetDoubleConvertInMapSZ(pMe,
+ szLabel,
+ QCBOR_CONVERT_TYPE_FLOAT,
+ pdValue);
+}
+#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
+
+
+
+
+/* ======================================================================== *
+ * END OF PRIVATE INLINE IMPLEMENTATION *
+ * ======================================================================== */
+
+
+
+
+/* ========================================================================= *
+ * BEGINNING OF INLINES FOR DEPRECATED FUNCTIONS *
+ * ========================================================================= */
+
+
+static inline void /* Deprecated */
+QCBORDecode_GetBignum(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORDecode_GetTBigNumberRaw(pMe, uTagRequirement, pBigNumber, pbIsNegative);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORDecode_GetTBigNumberRawInMapN(pMe, nLabel, uTagRequirement, pBigNumber, pbIsNegative);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBignumInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORDecode_GetTBigNumberRawInMapSZ(pMe, szLabel, uTagRequirement, pBigNumber, pbIsNegative);
+}
+
+#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFraction(pMe, uTagRequirement, pnMantissa, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFractionInMapN(pMe, nLabel, uTagRequirement, pnMantissa, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFractionInMapSZ(pMe, szLabel, uTagRequirement, pnMantissa, pnExponent);
+}
+
+
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFractionBigMantissaRaw(pMe, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(pMe, nLabel, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(pMe, szLabel, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
+
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloat(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloat(pMe, uTagRequirement, pnMantissa, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloatInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloatInMapN(pMe, nLabel, uTagRequirement, pnMantissa, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloatInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloatInMapSZ(pMe, szLabel, uTagRequirement, pnMantissa, pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloatBig(QCBORDecodeContext *pMe,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloatBigMantissaRaw(pMe,
+ uTagRequirement,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloatBigInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloatBigMantissaRawInMapN(pMe,
+ nLabel,
+ uTagRequirement,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+static inline void /* Deprecated */
+QCBORDecode_GetBigFloatBigInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ uint8_t uTagRequirement,
+ UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(pMe,
+ szLabel,
+ uTagRequirement,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+
+/* ========================================================================= *
+ * END OF INLINES FOR DEPRECATED FUNCTIONS *
+ * ========================================================================= */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* qcbor_number_decode_h */
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index 5747869..155df7c 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -188,337 +188,6 @@
-/** Conversion will proceed if the CBOR item to be decoded is an
- * integer or either type 0 (unsigned) or type 1 (negative). */
-#define QCBOR_CONVERT_TYPE_XINT64 0x01
-/** Conversion will proceed if the CBOR item to be decoded is either
- * double, single or half-precision floating-point (major type 7). */
-#define QCBOR_CONVERT_TYPE_FLOAT 0x02
-/** Conversion will proceed if the CBOR item to be decoded is a big
- * number, positive or negative (tag 2 or tag 3). */
-#define QCBOR_CONVERT_TYPE_BIG_NUM 0x04
-/** Conversion will proceed if the CBOR item to be decoded is a
- * decimal fraction (tag 4). */
-#define QCBOR_CONVERT_TYPE_DECIMAL_FRACTION 0x08
-/** Conversion will proceed if the CBOR item to be decoded is a big
- * float (tag 5). */
-#define QCBOR_CONVERT_TYPE_BIGFLOAT 0x10
-
-
-
-
-/**
- * @brief Decode next item into a signed 64-bit integer.
- *
- * @param[in] pCtx The decode context.
- * @param[out] pnValue The returned 64-bit signed integer.
- *
- * The CBOR data item to decode must be a positive or negative integer
- * (CBOR major type 0 or 1). If not @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
- *
- * If the CBOR integer is either too large or too small to fit in an
- * int64_t, the error @ref QCBOR_ERR_INT_OVERFLOW or
- * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW is set. Note that type 0
- * unsigned integers can be larger than will fit in an int64_t and
- * type 1 negative integers can be smaller than will fit in an
- * int64_t.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See also QCBORDecode_GetUInt64(), QCBORDecode_GetInt64Convert(),
- * QCBORDecode_GetInt64ConvertAll() and QCBORDecode_GetDoubleConvert()
- */
-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 into a signed 64-bit integer with basic conversions.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] pnValue The returned 64-bit signed integer.
- *
- * @c uConvertTypes controls what conversions this will perform and
- * thus what CBOR types will be decoded. @c uConvertType is a bit map
- * listing the conversions to be allowed. This function supports
- * @ref QCBOR_CONVERT_TYPE_XINT64 and @ref QCBOR_CONVERT_TYPE_FLOAT
- * conversions.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * If the CBOR data type can never be convered by this function or the
- * conversion was not selected in @c uConversionTypes
- * @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
- *
- * When converting floating-point values, the integer is rounded to
- * the nearest integer using llround(). By default, floating-point
- * suport is enabled for QCBOR.
- *
- * If floating-point HW use is disabled this will set
- * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
- * encountered. If half-precision support is disabled, this will set
- * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
- * is encountered.
- *
- * If floating-point usage is disabled this will set
- * @ref QCBOR_ERR_ALL_FLOAT_DISABLED if a floating point value is
- * encountered.
- *
- * See also QCBORDecode_GetInt64ConvertAll() which will perform the
- * same conversions as this and a lot more at the cost of adding more
- * object code to your executable.
- */
-static void
-QCBORDecode_GetInt64Convert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-static void
-QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-static void
-QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-
-#if !defined(USEFULBUF_DISABLE_ALL_FLOAT) && !defined(QCBOR_DISABLE_PREFERRED_FLOAT)
-/**
- * @brief dCBOR Decode next as a number with precision-preserving conversions.
- *
- * @param[in] pCtx The decode context.
- * @param[out] pNumber The returned number.
- *
- * This gets the next item as a number and returns it as a C data type
- * such that no precision is lost.
- *
- * This is primarily works with integers and floats for both the
- * to-be-decoded CBOR and the decoded types.
- *
- * The CBOR input can be integers (major type 0 or 1) or floats (major
- * type 7). If not these, \ref QCBOR_ERR_UNEXPECTED_TYPE will be set.
- *
- * The conversion is as follows.
- *
- * Whole numbers from \c INT64_MIN to \c INT64_MAX will be returned as
- * int64_t indicated as \ref QCBOR_TYPE_INT64. This includes
- * conversion of floating-point values that are whole numbers.
- *
- * Whole numbers from \c INT64_MAX +1 to \c UINT64_MAX will be
- * returned as uint64_t indicated as \ref QCBOR_TYPE_UINT64, again
- * including conversion of floating-point values that are whole
- * numbers.
- *
- * Most other numbers are returned as a double as indicated by
- * \ref QCBOR_TYPE_DOUBLE floating point with one set of exceptions.
- *
- * The exception is negative whole numbers in the range of -(2^63 + 1)
- * to -(2^64) that have too much precision to be represented as a
- * double. Doubles have only 52 bits of precision, so they can't
- * precisely represent every whole integer in this range. CBOR can
- * represent these values with 64-bits of precision and when this
- * function encounters them they are returned as \ref
- * QCBOR_TYPE_65BIT_NEG_INT. See the description of this type for
- * instructions to gets its value. Also see
- * QCBORDecode_ProcessBigNumber().
- *
- * To give an example, the value -18446744073709551616 can't be
- * represented by an int64_t or uint64_t, but can be represented by a
- * double so it is returned by this function as a double. The value
- * -18446744073709551617 however can't be represented by a double
- * because it has too much precision, so it is returned as \ref
- * QCBOR_TYPE_65BIT_NEG_INT.
- *
- * This is useful for DCBOR which essentially combines floats and
- * integers into one number space.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See also QCBORDecode_GetNumberConvertPreciselyBig().
- */
-void
-QCBORDecode_GetNumberConvertPrecisely(QCBORDecodeContext *pCtx,
- QCBORItem *pNumber);
-
-#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT && ! QCBOR_DISABLE_PREFERRED_FLOAT */
-
-
-/**
- * @brief Decode next item into a signed 64-bit integer with conversions.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] pnValue The returned 64-bit signed integer.
- *
- * This is the same as QCBORDecode_GetInt64Convert() but additionally
- * supports conversion from positive and negative bignums, decimal
- * fractions and big floats, including decimal fractions and big floats
- * that use bignums. The conversion types supported are
- * @ref QCBOR_CONVERT_TYPE_XINT64, @ref QCBOR_CONVERT_TYPE_FLOAT,
- * @ref QCBOR_CONVERT_TYPE_BIG_NUM,
- * @ref QCBOR_CONVERT_TYPE_DECIMAL_FRACTION and
- * @ref QCBOR_CONVERT_TYPE_BIGFLOAT.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * Note that most these types can support numbers much larger that can
- * be represented by in a 64-bit integer, so
- * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW may often be encountered.
- *
- * When converting bignums and decimal fractions,
- * @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be set if the result
- * is below 1, unless the mantissa is zero, in which case the
- * coversion is successful and the value of 0 is returned.
- *
- * See also QCBORDecode_GetInt64ConvertAll() which does some of these
- * conversions, but links in much less object code. See also
- * QCBORDecode_GetUInt64ConvertAll().
- *
- * This relies on CBOR tags to identify big numbers, decimal fractions
- * and big floats. It will not attempt to decode non-tag CBOR that might
- * be one of these. (If QCBOR_DISABLE_TAGS is set, this is effectively
- * the same as QCBORDecode_GetInt64Convert() because all the additional
- * number types this decodes are tags).
- */
-void
-QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-void
-QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-void
-QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue);
-
-
-/**
- * @brief Decode next item into an unsigned 64-bit integer.
- *
- * @param[in] pCtx The decode context.
- * @param[out] puValue The returned 64-bit unsigned integer.
- *
- * This is the same as QCBORDecode_GetInt64(), but returns an unsigned integer
- * and thus can only decode CBOR positive integers.
- * @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION is set if the input is a negative
- * integer.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See also QCBORDecode_GetUInt64Convert() and QCBORDecode_GetUInt64ConvertAll().
- */
-static void
-QCBORDecode_GetUInt64(QCBORDecodeContext *pCtx,
- uint64_t *puValue);
-
-static void
-QCBORDecode_GetUInt64InMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint64_t *puValue);
-
-static void
-QCBORDecode_GetUInt64InMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint64_t *puValue);
-
-
-/**
- * @brief Decode next item as an unsigned 64-bit integer with basic conversions.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] puValue The returned 64-bit unsigned integer.
- *
- * This is the same as QCBORDecode_GetInt64Convert(), but returns an
- * unsigned integer and thus sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
- * if the value to be decoded is negatve.
- *
- * If floating-point HW use is disabled this will set
- * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
- * encountered. If half-precision support is disabled, this will set
- * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
- * is encountered.
- *
- * If floating-point usage is disabled this will set
- * @ref QCBOR_ERR_ALL_FLOAT_DISABLED if a floating point value is
- * encountered.
- *
- * See also QCBORDecode_GetUInt64Convert() and
- * QCBORDecode_GetUInt64ConvertAll().
- */
-static void
-QCBORDecode_GetUInt64Convert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-static void
-QCBORDecode_GetUInt64ConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-static void
-QCBORDecode_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-
-/**
- * @brief Decode next item into an unsigned 64-bit integer with conversions
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] puValue The returned 64-bit unsigned integer.
- *
- * This is the same as QCBORDecode_GetInt64ConvertAll(), but returns
- * an unsigned integer and thus sets @ref QCBOR_ERR_NUMBER_SIGN_CONVERSION
- * if the value to be decoded is negatve.
- *
- * See also QCBORDecode_GetUInt64() and QCBORDecode_GetUInt64Convert().
- */
-void
-QCBORDecode_GetUInt64ConvertAll(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-void
-QCBORDecode_GetUInt64ConvertAllInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-void
-QCBORDecode_GetUInt64ConvertAllInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue);
-
-
-
-
/**
* @brief Decode the next item as a byte string
*
@@ -579,137 +248,6 @@
-#ifndef USEFULBUF_DISABLE_ALL_FLOAT
-/**
- * @brief Decode next item into a double floating-point value.
- *
- * @param[in] pCtx The decode context.
- * @param[out] pValue The returned floating-point value.
- *
- * The CBOR data item to decode must be a half-precision,
- * single-precision or double-precision floating-point value. If not
- * @ref QCBOR_ERR_UNEXPECTED_TYPE is set.
- *
- * If floating-point HW use is disabled this will set
- * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
- * encountered. If half-precision support is disabled, this will set
- * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number
- * is encountered.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See also QCBORDecode_GetDoubleConvert() and
- * QCBORDecode_GetDoubleConvertAll().
- */
-static void
-QCBORDecode_GetDouble(QCBORDecodeContext *pCtx,
- double *pValue);
-
-static void
-QCBORDecode_GetDoubleInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- double *pdValue);
-
-static void
-QCBORDecode_GetDoubleInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- double *pdValue);
-
-
-/**
- * @brief Decode next item into a double floating-point with basic conversion.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] pdValue The returned floating-point value.
- *
- * This will decode CBOR integer and floating-point numbers, returning
- * them as a double floating-point number. This function supports
-
- * @ref QCBOR_CONVERT_TYPE_XINT64 and @ref QCBOR_CONVERT_TYPE_FLOAT
- * conversions. If the encoded CBOR is not one of the requested types
- * or a type not supported by this function, @ref QCBOR_ERR_UNEXPECTED_TYPE
- * is set.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * If floating-point HW use is disabled this will set
- * @ref QCBOR_ERR_HW_FLOAT_DISABLED if a single-precision number is
- * encountered. If half-precision support is disabled, this will set
- * @ref QCBOR_ERR_HALF_PRECISION_DISABLED if a half-precision number is
- * encountered.
- *
- * Positive and negative integers can always be converted to
- * floating-point, so this will never error on CBOR major type 0 or 1.
- *
- * Note that a large 64-bit integer can have more precision (64 bits)
- * than even a double floating-point (52 bits) value, so there is loss
- * of precision in some conversions.
- *
- * See also QCBORDecode_GetDouble() and QCBORDecode_GetDoubleConvertAll().
- */
-static void
-QCBORDecode_GetDoubleConvert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- double *pdValue);
-
-static void
-QCBORDecode_GetDoubleConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- double *pdValue);
-
-static void
-QCBORDecode_GetDoubleConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- double *pdValue);
-
-
-/**
- * @brief Decode next item as a double floating-point value with conversion.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uConvertTypes The integer conversion options.
- * @param[out] pdValue The returned floating-point value.
- *
- * This is the same as QCBORDecode_GetDoubleConvert() but supports
- * many more conversions at the cost of linking in more object
- * code. The conversion types supported are @ref QCBOR_CONVERT_TYPE_XINT64,
- * @ref QCBOR_CONVERT_TYPE_FLOAT, @ref QCBOR_CONVERT_TYPE_BIG_NUM,
- * @ref QCBOR_CONVERT_TYPE_DECIMAL_FRACTION and
- * @ref QCBOR_CONVERT_TYPE_BIGFLOAT.
- *
- * Big numbers, decimal fractions and big floats that are too small or
- * too large to be reprented as a double floating-point number will be
- * returned as plus or minus zero or infinity rather than setting an
- * under or overflow error.
- *
- * There is often loss of precision in the conversion.
- *
- * See also QCBORDecode_GetDoubleConvert() and QCBORDecode_GetDoubleConvert().
- */
-void
-QCBORDecode_GetDoubleConvertAll(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- double *pdValue);
-
-void
-QCBORDecode_GetDoubleConvertAllInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- double *pdValue);
-
-void
-QCBORDecode_GetDoubleConvertAllInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- double *pdValue);
-#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
-
-
-
-
/**
* @brief Enter an array for decoding in bounded mode.
*
@@ -1491,547 +1029,6 @@
/**
- * @brief Decode next item as a big number encoded using preferred serialization.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
- * @param[in] BigNumberBuf The buffer to write the result into.
- * @param[out] pBigNumber The decoded big number, most significant
- * byte first (network byte order).
- * @param[in,out] pbIsNegative Set to true if the resulting big number is negative.
- *
- * This decodes CBOR tag numbers 2 and 3, positive and negative big
- * numbers, as defined in [RFC 8949 section 3.4.3]
- * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3). This
- * decodes preferred serialization described specifically for big
- * numbers.
- *
- * See QCBORDecode_PreferedBigNumber() which performs the bulk of this.
- *
- * The type processing rules are as follows.
- *
- * This always succeeds on type 0 and 1 integers (@ref QCBOR_TYPE_INT64,
- * @ref QCBOR_TYPE_UINT64 and @ref QCBOR_TYPE_65BIT_NEG_INT) no matter what
- * @c uTagRequirement is. The rest of the rules pertain to what happens
- * if the CBOR is not type 0 or type 1.
- *
- * If @c uTagRequirement is @ref QCBOR_TAG_REQUIREMENT_TAG, this
- * expects a full tag 2 or tag 3 big number.
- *
- * If @c uTagRequreiement is @ref QCBOR_TAG_REQUIREMENT_NOT_A_TAG then
- * this expects a byte string.
- *
- * If @ref QCBOR_TAG_REQUIREMENT_OPTIONAL_TAG, then this will succeed on
- * either a byte string or a tag 2 or 3.
- *
- * If the item is a bare byte string, not a tag 2 or 3, then
- * @c pbIsNegative is an input parameter that determines the sign of the
- * big number. The sign must be known because the decoding of a
- * positive big number is different than a negative.
- *
- * This works whether or not QCBORDecode_StringsTagCB() is installed
- * to process tags 2 and 3.
- *
- * See @ref BigNumbers for a useful overview of CBOR big numbers and
- * QCBOR's support for them. See QCBOREncode_AddTBigNumber(), the
- * encode counter part for this. See also
- * QCBORDecode_GetTBigNumberNoPreferred() and
- * QCBORDecode_GetTBigNumberRaw().
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See @ref Tag-Usage for discussion on tag requirements.
- */
-void
-QCBORDecode_GetTBigNumber(QCBORDecodeContext *pCtx,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-
-/**
- * @brief Decode next item as a big number without preferred serialization.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
- * @param[in] BigNumberBuf The buffer to write the result into.
- * @param[out] pBigNumber The decoded big number, most significant
- * byte first (network byte order).
- * @param[in,out] pbIsNegative Set to true if the returned big number is negative.
- *
- * This is the same as QCBORDecode_GetTBigNumber(), but will error out
- * on type 0 and 1 integers as it doesn't support the preferred
- * serialization specific for big numbers.
- *
- * See @ref BigNumbers for a useful overview of CBOR big numbers and
- * QCBOR's support for them. See QCBOREncode_AddTBigNumberNoPreferred(),
- * the encode counter part for this. See also QCBORDecode_GetTBigNumber()
- * and QCBORDecode_GetTBigNumberRaw().
- */
-void
-QCBORDecode_GetTBigNumberNoPreferred(QCBORDecodeContext *pCtx,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberNoPreferredInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberNoPreferredInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-
- /**
- * @brief Decode the next item as a big number with no processing
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement @ref QCBOR_TAG_REQUIREMENT_TAG or related.
- * @param[out] pBigNumber The decoded big number, most significant
- * byte first (network byte order).
- * @param[out] pbIsNegative Is @c true if the big number is negative. This
- * is only valid when @c uTagRequirement is
- * @ref QCBOR_TAG_REQUIREMENT_TAG.
- *
- * This decodes CBOR tag numbers 2 and 3, positive and negative big
- * numbers, as defined in [RFC 8949 section 3.4.3]
- * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.3).
- *
- * This returns the byte string representing the big number
- * directly. It does not apply the required the offset of one for
- * negative big numbers. It will error out big numbers that have been
- * encoded as type 0 and 1 integer because of big number preferred
- * serialization.
- *
- * This is most useful when a big number library has been linked, and
- * it can be (trivially) used to perform the offset of one for
- * negative numbers.
- *
- * This links in much less object code than QCBORDecode_GetTBigNumber() and
- * QCBORDecode_GetTBigNumberNoPreferred().
- *
- * This does the same minimal processing as installing QCBORDecode_StringsTagCB()
- * installed to handle @ref CBOR_TAG_POS_BIGNUM and @ref CBOR_TAG_NEG_BIGNUM
- * so QCBORDecode_VGetNext() returns a @ref QCBORItem of type
- * @ref QCBOR_TYPE_POSBIGNUM or @ref QCBOR_TYPE_POSBIGNUM
- *
- * See @ref BigNumbers for a useful overview of CBOR big numbers and
- * QCBOR's support for them. See QCBOREncode_AddTBigNumberRaw() for
- * the encoding counter part. See QCBORDecode_GetTBigNumber() which
- * does perform the offset for negative numbers and handles preferred
- * serialization big numbers.
- *
- * Please see @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See @ref Tag-Usage for discussion on tag requirements.
- */
-void
-QCBORDecode_GetTBigNumberRaw(QCBORDecodeContext *pCtx,
- const uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberRawInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-void
-QCBORDecode_GetTBigNumberRawInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative);
-
-
-
-
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-/**
- * @brief Decode the next item as a decimal fraction.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[out] pnMantissa The mantissa.
- * @param[out] pnExponent The base 10 exponent.
- *
- * The input to decode must be a decimal fraction as defined in
- * [RFC 8949 section 3.4.4]
- * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.4). That
- * is, an array of two numbers, the first of which is the exponent and
- * the second is the mantissa.
- *
- * Depending on @c uTagRequirement, the tag number
- * @ref CBOR_TAG_DECIMAL_FRACTION (4) may or may not need to be
- * present before the array. See @ref Tag-Usage.
- *
- * The exponent must always be an integer (CBOR type 0 or 1). The
- * mantissa may be an integer or a big number. If it is a big number,
- * the tag number 2 or 3 must be present.
- *
- * The exponent is limited to between @c INT64_MIN and
- * @c INT64_MAX while CBOR allows the range of @c -UINT64_MAX to @c UINT64_MAX.
- *
- * The mantissa is always returned as an @c int64_t. If the value
- * won't fit, @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be
- * set. Use QCBORDecode_GetTDecimalFractionBigMantissa() to avoid the
- * limit to @c int64_t.
- *
- * The value of this is computed by:
- *
- * mantissa * ( 10 ** exponent )
- *
- * Various format and type issues will result in @ref QCBOR_ERR_BAD_EXP_AND_MANTISSA
- * being set. See @ref Decode-Errors-Overview "Decode Errors
- * Overview".
- *
- * See also QCBORDecode_GetInt64ConvertAll(),
- * QCBORDecode_GetUInt64ConvertAll() and
- * QCBORDecode_GetDoubleConvertAll() which can also decode decimal
- * fractions.
- *
- * See also @ref CBOR_TAG_DECIMAL_FRACTION,
- * QCBOREncode_AddTDecimalFraction(), @ref QCBOR_TYPE_DECIMAL_FRACTION.
- *
- * If QCBOR_DISABLE_TAGS is set, the only input this will decode is an
- * array of two integers. It will set an error if the the array is
- * preceded by by a tag number or if the mantissa is a big number.
- */
-void
-QCBORDecode_GetTDecimalFraction(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/**
- * @brief Decode the next item as a decimal fraction with a big number mantissa.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[in] MantissaBuffer The buffer in which to put the mantissa.
- * @param[out] pMantissa The big num mantissa.
- * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
- * @param[out] pnExponent The base 10 exponent.
- *
- * This is the same as QCBORDecode_GetTDecimalFraction() except the
- * mantissa is returned as a big number.
- *
- * In the encoded CBOR, the mantissa may be a type 0 (positive
- * integer), type 1 (negative integer), type 2 tag 2 (positive big
- * number) or type 2 tag 3 (negative big number). This implementation
- * will convert all these to a big number. The limit to this
- * conversion is the size of @c MantissaBuffer.
- *
- * See also QCBORDecode_GetInt64ConvertAll(),
- * QCBORDecode_GetUInt64ConvertAll() and
- * QCBORDecode_GetDoubleConvertAll() which can convert decimal
- * fractions.
- *
- * See also @ref CBOR_TAG_DECIMAL_FRACTION,
- * QCBOREncode_AddTDecimalFractionBigMantissa(), @ref QCBOR_TYPE_DECIMAL_FRACTION
- * and QCBORDecode_GetTDecimalFraction().
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissa(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionBigMantissaInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pbMantissaIsNegative,
- bool *pbIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionBigMantissaInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-
-/**
- * @brief Decode the next item as a decimal fraction with a big number mantissa raw.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[in] MantissaBuffer The buffer in which to put the mantissa.
- * @param[out] pMantissa The big num mantissa.
- * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
- * @param[out] pnExponent The base 10 exponent.
- *
- * This is the same as QCBORDecode_GetTDecimalFractionBigMantissa() except the
- * negative mantissas are NOT offset by one and this links in less object code.
- *
- * In the encoded CBOR, the mantissa may be a type 0 (positive
- * integer), type 1 (negative integer), type 2 tag 2 (positive big
- * number) or type 2 tag 3 (negative big number). This implementation
- * will convert all these to a big number. The limit to this
- * conversion is the size of @c MantissaBuffer.
- *
- * See also QCBORDecode_GetInt64ConvertAll(),
- * QCBORDecode_GetUInt64ConvertAll() and
- * QCBORDecode_GetDoubleConvertAll() which can convert decimal
- * fractions.
- *
- * See also @ref CBOR_TAG_DECIMAL_FRACTION,
- * QCBOREncode_AddTDecimalFractionBigMantissaRaw(), @ref QCBOR_TYPE_DECIMAL_FRACTION
- * and QCBORDecode_GetTDecimalFractionBigMantissa().
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRaw(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pbMantissaIsNegative,
- bool *pbIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-
-/**
- * @brief Decode the next item as a big float.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[out] pnMantissa The mantissa.
- * @param[out] pnExponent The base 2 exponent.
- *
- * The input to decode must be a big float defined in [RFC 8949 section 3.4.4]
- * (https://www.rfc-editor.org/rfc/rfc8949.html#section-3.4.4). That
- * is, an array of two numbers, the first of which is the exponent and
- * the second is the mantissa.
- *
- * Depending on @c uTagRequirement, the tag number
- * @ref CBOR_TAG_BIG_FLOAT (5) may or may not need to be present
- * before the array. See @ref Tag-Usage.
- *
- * The exponent must always be an integer (CBOR type 0 or 1). The
- * mantissa may be an integer or a big number. If it is a big number,
- * the tag number 2 or 3 must be present.
- *
- * This implementation limits the exponent to between @c INT64_MIN and
- * @c INT64_MAX while CBOR allows the range of @c -UINT64_MAX to @c UINT64_MAX.
- *
- * The mantissa is always returned as an @c int64_t. If the value
- * won't fit, @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will be
- * set. Use QCBORDecode_GetBigFloastBigNumber() to avoid the
- * limit to @c int64_t.
- *
- * mantissa * ( 2 ** exponent )
- *
- * Various format and type issues will result in
- * @ref QCBOR_ERR_BAD_EXP_AND_MANTISSA being set. See
- * @ref Decode-Errors-Overview "Decode Errors Overview".
- *
- * See also QCBORDecode_GetInt64ConvertAll(),
- * QCBORDecode_GetUInt64ConvertAll() and
- * QCBORDecode_GetDoubleConvertAll() which can convert big floats.
- *
- * See also @ref CBOR_TAG_BIGFLOAT, QCBOREncode_AddTBigFloat(),
- * @ref QCBOR_TYPE_BIGFLOAT and QCBORDecode_GetTBigFloatBigMantissa().
- *
- * If QCBOR_DISABLE_TAGS is set, the only input this will decode is an
- * array of two integers. It will set an error if the the array is
- * preceded by by a tag number or if the mantissa is a big number.
- */
-void
-QCBORDecode_GetTBigFloat(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTBigFloatInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTBigFloatInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-
-/**
- * @brief Decode the next item as a big float with a big number mantissa.
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[in] MantissaBuffer The buffer in which to put the mantissa.
- * @param[out] pMantissa The big num mantissa.
- * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
- * @param[out] pnExponent The base 2 exponent.
- *
- * This is the same as QCBORDecode_GetTBigFloat() except the mantissa
- * is returned as a big number. The only limit to precision is the
- * size of @c MantissaBuffer.
- *
- * The encoded mantissa may be an integer or a big number. The
- * standard CBOR offset of 1 for negative is applied, so the mantissa can be used as
- * returned.
- *
- * See also @ref CBOR_TAG_BIGFLOAT,
- * QCBOREncode_AddTBigFloatBigNumber(), @ref QCBOR_TYPE_BIGFLOAT and
- * QCBORDecode_GetTBigFloat().
- */
-void
-QCBORDecode_GetTBigFloatBigMantissa(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-
-void
-QCBORDecode_GetTBigFloatBigMantissaInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTBigFloatBigMantissaInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-
-/**
- * @brief Decode the next item as a big float with a big number mantissa with out offsetting the mantissa
- *
- * @param[in] pCtx The decode context.
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[in] MantissaBuffer The buffer in which to put the mantissa.
- * @param[out] pMantissa The big num mantissa.
- * @param[out] pbMantissaIsNegative Is @c true if @c pMantissa is negative.
- * @param[out] pnExponent The base 2 exponent.
- *
- * This is the same as QCBORDecode_GetBigFloat() except the mantissa
- * is returned as a big number. The only limit to precision is the
- * size of @c MantissaBuffer.
- *
- * The encoded mantissa may be an integer or a big number. The
- * standard CBOR offset of 1 for negative is NOT applied. If the ma
- * mantissa is negative, one must be added to get it's actual value.
- *
- * Because this doesn't offset the negative big numbers, this links in
- * a lot less object code. It is suitable for uses where a big number
- * library is already linked in for other purposes as it can trivially
- * do the increment by one.
- *
- * See also @ref CBOR_TAG_BIGFLOAT,
- * QCBOREncode_AddTBigFloatBigNumber(), @ref QCBOR_TYPE_BIGFLOAT and
- * QCBORDecode_GetTBigFloat().
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaRaw(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-
-void
-QCBORDecode_GetTBigFloatBigMantissaRawInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-void
-QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
-/**
* @brief Decode the next item as a URI.
*
* @param[in] pCtx The decode context.
@@ -2353,160 +1350,6 @@
-/* ========================================================================= *
- * BEGINNING OF DEPRECATED FUNCTION DECLARATIONS *
- * *
- * There is no plan to remove these in future versions. *
- * They just have been replaced by something better. *
- * ========================================================================= */
-
-
-/* Deprecated. Use QCBORDecode_GetTBigNumberRaw() instead. */
-static void
-QCBORDecode_GetBignum(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBufC *pValue,
- bool *pbIsNegative);
-
-/* Deprecated. Use QCBORDecode_GetTBigNumberRawInMapN() instead. */
-static void
-QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pValue,
- bool *pbIsNegative);
-
-/* Deprecated. Use QCBORDecode_GetTBigNumberRawInMapSZ() instead. */
-static void
-QCBORDecode_GetBignumInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pValue,
- bool *pbIsNegative);
-
-#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
-/* Deprecated. Use QCBORDecode_GetTDecimalFraction() instead. */
-static void
-QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTDecimalFractionInMapN() instead. */
-static void
-QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTDecimalFractionInMapSZ() instead. */
-static void
-QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRaw() instead. */
-/*
- TODO: integrate this comment better
-* For QCBOR before v1.5, this function had a bug where
-* by the negative mantissa sometimes had the offset of
-* one applied, making this function somewhat usless for
-* negative mantissas. Specifically if the to-be-decode CBOR
-* was a type 1 integer the offset was applied and when it
-* was a tag 3, the offset was not applied. It is possible
-* that a tag 3 could contain a value in the range of a type 1
-* integer. @ref QCBORExpAndMantissa is
-* correct and can be used instead of this. */
-static void
-QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN() instead */
-static void
-QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pbMantissaIsNegative,
- bool *pbIsNegative,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ() instead. */
-static void
-QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloat() instead. */
-static void
-QCBORDecode_GetBigFloat(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloatInMapN() instead. */
-static void
-QCBORDecode_GetBigFloatInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloatInMapSZ() instead. */
-static void
-QCBORDecode_GetBigFloatInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRaw() instead. */
-static void
-QCBORDecode_GetBigFloatBig(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRawInMapN() instead. */
-static void
-QCBORDecode_GetBigFloatBigInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-
-/* Deprecated. Use QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ() instead. */
-static void
-QCBORDecode_GetBigFloatBigInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent);
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
-/* ========================================================================= *
- * END OF DEPRECATED FUNCTION DECLARATIONS *
- * ========================================================================= */
-
-
/* ========================================================================= *
@@ -2516,31 +1359,6 @@
/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
void
-QCBORDecode_Private_GetUInt64Convert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem);
-
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetUInt64ConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem);
-
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem);
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
QCBORDecode_Private_EnterBoundedMapOrArray(QCBORDecodeContext *pCtx,
uint8_t uType,
QCBORItem *pItem);
@@ -2553,56 +1371,6 @@
/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
void
-QCBORDecode_Private_GetInt64Convert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem);
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetInt64ConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem);
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetInt64ConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem);
-
-
-#ifndef USEFULBUF_DISABLE_ALL_FLOAT
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetDoubleConvert(QCBORDecodeContext *pCtx,
- uint32_t uConvertTypes,
- double *pValue,
- QCBORItem *pItem);
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetDoubleConvertInMapN(QCBORDecodeContext *pCtx,
- int64_t nLabel,
- uint32_t uConvertTypes,
- double *pdValue,
- QCBORItem *pItem);
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
-QCBORDecode_Private_GetDoubleConvertInMapSZ(QCBORDecodeContext *pCtx,
- const char *szLabel,
- uint32_t uConvertTypes,
- double *pdValue,
- QCBORItem *pItem);
-#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT */
-
-
-/* Semi-private funcion used by public inline functions. See qcbor_decode.c */
-void
QCBORDecode_Private_GetTaggedString(QCBORDecodeContext *pMe,
uint8_t uTagRequirement,
uint8_t uQCBOR_Type,
@@ -2633,73 +1401,6 @@
-
-static inline void
-QCBORDecode_GetUInt64Convert(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetUInt64Convert(pMe, uConvertTypes, puValue, &Item);
-}
-
-static inline void
-QCBORDecode_GetUInt64ConvertInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetUInt64ConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- puValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetUInt64ConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- puValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetUInt64(QCBORDecodeContext *pMe, uint64_t *puValue)
-{
- QCBORDecode_GetUInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, puValue);
-}
-
-static inline void
-QCBORDecode_GetUInt64InMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- uint64_t *puValue)
-{
- QCBORDecode_GetUInt64ConvertInMapN(pMe,
- nLabel,
- QCBOR_CONVERT_TYPE_XINT64,
- puValue);
-}
-
-static inline void
-QCBORDecode_GetUInt64InMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint64_t *puValue)
-{
- QCBORDecode_GetUInt64ConvertInMapSZ(pMe,
- szLabel,
- QCBOR_CONVERT_TYPE_XINT64,
- puValue);
-}
-
-
static inline void
QCBORDecode_EnterMap(QCBORDecodeContext *pMe, QCBORItem *pItem) {
QCBORDecode_Private_EnterBoundedMapOrArray(pMe, QCBOR_TYPE_MAP, pItem);
@@ -2836,142 +1537,6 @@
-static inline void
-QCBORDecode_GetInt64Convert(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetInt64Convert(pMe, uConvertTypes, pnValue, &Item);
-}
-
-static inline void
-QCBORDecode_GetInt64ConvertInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetInt64ConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- pnValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetInt64ConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- pnValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetInt64(QCBORDecodeContext *pMe, int64_t *pnValue)
-{
- QCBORDecode_GetInt64Convert(pMe, QCBOR_CONVERT_TYPE_XINT64, pnValue);
-}
-
-static inline void
-QCBORDecode_GetInt64InMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- int64_t *pnValue)
-{
- QCBORDecode_GetInt64ConvertInMapN(pMe,
- nLabel,
- QCBOR_CONVERT_TYPE_XINT64,
- pnValue);
-}
-
-static inline void
-QCBORDecode_GetInt64InMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- int64_t *pnValue)
-{
- QCBORDecode_GetInt64ConvertInMapSZ(pMe,
- szLabel,
- QCBOR_CONVERT_TYPE_XINT64,
- pnValue);
-}
-
-
-
-#ifndef USEFULBUF_DISABLE_ALL_FLOAT
-static inline void
-QCBORDecode_GetDoubleConvert(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetDoubleConvert(pMe, uConvertTypes, pdValue, &Item);
-}
-
-static inline void
-QCBORDecode_GetDoubleConvertInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- uint32_t uConvertTypes,
- double *pdValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetDoubleConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- pdValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetDoubleConvertInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetDoubleConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- pdValue,
- &Item);
-}
-
-static inline void
-QCBORDecode_GetDouble(QCBORDecodeContext *pMe, double *pValue)
-{
- QCBORDecode_GetDoubleConvert(pMe, QCBOR_CONVERT_TYPE_FLOAT, pValue);
-}
-
-static inline void
-QCBORDecode_GetDoubleInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- double *pdValue)
-{
- QCBORDecode_GetDoubleConvertInMapN(pMe,
- nLabel,
- QCBOR_CONVERT_TYPE_FLOAT,
- pdValue);
-}
-
-static inline void
-QCBORDecode_GetDoubleInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- double *pdValue)
-{
- QCBORDecode_GetDoubleConvertInMapSZ(pMe,
- szLabel,
- QCBOR_CONVERT_TYPE_FLOAT,
- pdValue);
-}
-#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
-
-
-
static inline void
QCBORDecode_GetByteString(QCBORDecodeContext *pMe, UsefulBufC *pBytes)
@@ -3418,196 +1983,6 @@
-
-/* ========================================================================= *
- * BEGINNING OF INLINES FOR DEPRECATED FUNCTIONS *
- * ========================================================================= */
-
-
-static inline void /* Deprecated */
-QCBORDecode_GetBignum(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORDecode_GetTBigNumberRaw(pMe, uTagRequirement, pBigNumber, pbIsNegative);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBignumInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORDecode_GetTBigNumberRawInMapN(pMe, nLabel, uTagRequirement, pBigNumber, pbIsNegative);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBignumInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORDecode_GetTBigNumberRawInMapSZ(pMe, szLabel, uTagRequirement, pBigNumber, pbIsNegative);
-}
-
-#ifndef QCBOR_CONFIG_DISABLE_EXP_AND_MANTISSA
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFraction(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFraction(pMe, uTagRequirement, pnMantissa, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFractionInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFractionInMapN(pMe, nLabel, uTagRequirement, pnMantissa, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFractionInMapSZ(pMe, szLabel, uTagRequirement, pnMantissa, pnExponent);
-}
-
-
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFractionBig(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFractionBigMantissaRaw(pMe, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFractionBigInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(pMe, nLabel, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetDecimalFractionBigInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(pMe, szLabel, uTagRequirement, MantissaBuffer, pMantissa, pbMantissaIsNegative, pnExponent);
-
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloat(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloat(pMe, uTagRequirement, pnMantissa, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloatInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloatInMapN(pMe, nLabel, uTagRequirement, pnMantissa, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloatInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloatInMapSZ(pMe, szLabel, uTagRequirement, pnMantissa, pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloatBig(QCBORDecodeContext *pMe,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloatBigMantissaRaw(pMe,
- uTagRequirement,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloatBigInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloatBigMantissaRawInMapN(pMe,
- nLabel,
- uTagRequirement,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-static inline void /* Deprecated */
-QCBORDecode_GetBigFloatBigInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- uint8_t uTagRequirement,
- UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(pMe,
- szLabel,
- uTagRequirement,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
-/* ========================================================================= *
- * END OF INLINES FOR DEPRECATED FUNCTIONS *
- * ========================================================================= */
-
-
#ifdef __cplusplus
}
#endif
diff --git a/src/decode_private.h b/src/decode_private.h
new file mode 100644
index 0000000..506c668
--- /dev/null
+++ b/src/decode_private.h
@@ -0,0 +1,95 @@
+/*==============================================================================
+ Copyright (c) 2016-2018, The Linux Foundation.
+ Copyright (c) 2018-2024, Laurence Lundblade.
+ Copyright (c) 2021, Arm Limited.
+ All rights reserved.
+
+ Created on 11/14/24 from qcbor_decode.c
+
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of The Linux Foundation nor the names of its
+ contributors, nor the name "Laurence Lundblade" may be used to
+ endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ =============================================================================*/
+
+#ifndef decode_private_h
+#define decode_private_h
+
+
+QCBORError
+QCBORDecode_Private_GetNextTagContent(QCBORDecodeContext *pMe,
+ QCBORItem *pDecodedItem);
+
+void
+QCBORDecode_Private_ProcessTagItemMulti(QCBORDecodeContext *pMe,
+ QCBORItem *pItem,
+ const uint8_t uTagRequirement,
+ const uint8_t uQCBORTypes[],
+ const uint64_t uTagNumbers[],
+ QCBORTagContentCallBack *pfCB,
+ size_t uOffset);
+
+
+void
+QCBORDecode_Private_ProcessTagItem(QCBORDecodeContext *pMe,
+ QCBORItem *pItem,
+ const uint8_t uTagRequirement,
+ const uint8_t uQCBORTypes[],
+ const uint64_t uTagNumber,
+ QCBORTagContentCallBack *pfCB,
+ size_t uOffset);
+
+void
+QCBORDecode_Private_GetItemInMapNoCheckSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uQcborType,
+ QCBORItem *pItem,
+ size_t *puOffset);
+
+void
+QCBORDecode_Private_GetItemInMapNoCheckN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uQcborType,
+ QCBORItem *pItem,
+ size_t *puOffset);
+
+static inline void
+QCBORDecode_Private_GetAndTell(QCBORDecodeContext *pMe, QCBORItem *Item, size_t *uOffset)
+{
+#ifndef QCBOR_DISABLE_TAGS
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ *uOffset = QCBORDecode_Tell(pMe);
+#else
+ *uOffset = SIZE_MAX;
+
+#endif /* ! QCBOR_DISABLE_TAGS */
+ pMe->uLastError = (uint8_t)QCBORDecode_Private_GetNextTagContent(pMe, Item);
+}
+
+
+#endif /* decode_private_h */
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index 1e272b7..7e2abad 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -37,15 +37,6 @@
#include "qcbor/qcbor_tag_decode.h"
#include "ieee754.h" /* Does not use math.h */
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
-
-#include <math.h> /* For isnan(), llround(), llroudf(), round(), roundf(),
- * pow(), exp2()
- */
-#include <fenv.h> /* feclearexcept(), fetestexcept() */
-
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-
#if (defined(__GNUC__) && !defined(__clang__))
/*
@@ -2388,7 +2379,7 @@
* and tag content) are decoded. This is a
* quick pass through for items that are not tags.
*/
-static QCBORError
+QCBORError
QCBORDecode_Private_GetNextTagContent(QCBORDecodeContext *pMe,
QCBORItem *pDecodedItem)
{
@@ -3614,8 +3605,8 @@
* map. This does not call QCBORDecode_Private_GetItemChecks()
* to check tag number consumption or decode conformance.
*/
-static void
-QCBORDecode_GetItemInMapNoCheckN(QCBORDecodeContext *pMe,
+void
+QCBORDecode_Private_GetItemInMapNoCheckN(QCBORDecodeContext *pMe,
const int64_t nLabel,
const uint8_t uQcborType,
QCBORItem *pItem,
@@ -3673,8 +3664,8 @@
* map. This does not call QCBORDecode_Private_GetItemChecks()
* to check tag number consumption or decode conformance.
*/
-static void
-QCBORDecode_GetItemInMapNoCheckSZ(QCBORDecodeContext *pMe,
+void
+QCBORDecode_Private_GetItemInMapNoCheckSZ(QCBORDecodeContext *pMe,
const char *szLabel,
const uint8_t uQcborType,
QCBORItem *pItem,
@@ -3888,7 +3879,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -3929,7 +3920,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -4553,7 +4544,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_BYTE_STRING, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_BYTE_STRING, &Item, &uOffset);
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
uTagRequirement,
@@ -4574,7 +4565,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_BYTE_STRING, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_BYTE_STRING, &Item, &uOffset);
pMe->uLastError = (uint8_t)QCBORDecode_Private_EnterBstrWrapped(pMe,
&Item,
uTagRequirement,
@@ -4897,7 +4888,7 @@
}
-static void
+void
QCBORDecode_Private_ProcessTagItemMulti(QCBORDecodeContext *pMe,
QCBORItem *pItem,
const uint8_t uTagRequirement,
@@ -4939,7 +4930,7 @@
/*
**/
-static void
+void
QCBORDecode_Private_ProcessTagItem(QCBORDecodeContext *pMe,
QCBORItem *pItem,
const uint8_t uTagRequirement,
@@ -5024,7 +5015,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -5048,7 +5039,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -5095,7 +5086,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -5119,7 +5110,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_ProcessTagOne(pMe,
&Item,
uTagRequirement,
@@ -5228,7 +5219,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_GetMIME(pMe,
uTagRequirement,
&Item,
@@ -5247,7 +5238,7 @@
QCBORItem Item;
size_t uOffset;
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
QCBORDecode_Private_GetMIME(pMe,
uTagRequirement,
&Item,
@@ -5261,3062 +5252,3 @@
// Improvement: add methods for wrapped CBOR, a simple alternate
// to EnterBstrWrapped
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-
-/**
- * @brief Prototype for conversion of exponent and mantissa to unsigned integer.
- *
- * @param[in] uMantissa The mantissa.
- * @param[in] nExponent The exponent.
- * @param[out] puResult The resulting integer.
- *
- * Concrete implementations of this are for exponent base 10 and 2 supporting
- * decimal fractions and big floats.
- */
-typedef QCBORError (*fExponentiator)(uint64_t uMantissa, int64_t nExponent, uint64_t *puResult);
-
-
-/**
- * @brief Base 10 exponentiate a mantissa and exponent into an unsigned 64-bit integer.
- *
- * @param[in] uMantissa The unsigned integer mantissa.
- * @param[in] nExponent The signed integer exponent.
- * @param[out] puResult Place to return the unsigned integer result.
- *
- * This computes: mantissa * 10 ^^ exponent as for a decimal fraction. The output is a 64-bit
- * unsigned integer.
- *
- * There are many inputs for which the result will not fit in the
- * 64-bit integer and @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will
- * be returned.
- */
-static QCBORError
-QCBOR_Private_Exponentitate10(const uint64_t uMantissa,
- int64_t nExponent,
- uint64_t *puResult)
-{
- uint64_t uResult = uMantissa;
-
- if(uResult != 0) {
- /* This loop will run a maximum of 19 times because
- * UINT64_MAX < 10 ^^ 19. More than that will cause
- * exit with the overflow error
- */
- for(; nExponent > 0; nExponent--) {
- if(uResult > UINT64_MAX / 10) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- uResult = uResult * 10;
- }
-
- for(; nExponent < 0; nExponent++) {
- uResult = uResult / 10;
- if(uResult == 0) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- }
- }
- /* else, mantissa is zero so this returns zero */
-
- *puResult = uResult;
-
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Base 2 exponentiate a mantissa and exponent into an unsigned 64-bit integer.
- *
- * @param[in] uMantissa The unsigned integer mantissa.
- * @param[in] nExponent The signed integer exponent.
- * @param[out] puResult Place to return the unsigned integer result.
- *
- * This computes: mantissa * 2 ^^ exponent as for a big float. The
- * output is a 64-bit unsigned integer.
- *
- * There are many inputs for which the result will not fit in the
- * 64-bit integer and @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will
- * be returned.
- */
-static QCBORError
-QCBOR_Private_Exponentitate2(const uint64_t uMantissa,
- int64_t nExponent,
- uint64_t *puResult)
-{
- uint64_t uResult;
-
- uResult = uMantissa;
-
- /* This loop will run a maximum of 64 times because INT64_MAX <
- * 2^31. More than that will cause exit with the overflow error
- */
- while(nExponent > 0) {
- if(uResult > UINT64_MAX >> 1) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- uResult = uResult << 1;
- nExponent--;
- }
-
- while(nExponent < 0 ) {
- if(uResult == 0) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- uResult = uResult >> 1;
- nExponent++;
- }
-
- *puResult = uResult;
-
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Exponentiate a signed mantissa and signed exponent to produce a signed result.
- *
- * @param[in] nMantissa Signed integer mantissa.
- * @param[in] nExponent Signed integer exponent.
- * @param[out] pnResult Place to put the signed integer result.
- * @param[in] pfExp Exponentiation function.
- *
- * @returns Error code
- *
- * @c pfExp performs exponentiation on and unsigned mantissa and
- * produces an unsigned result. This converts the mantissa from signed
- * and converts the result to signed. The exponentiation function is
- * either for base 2 or base 10 (and could be other if needed).
- */
-static QCBORError
-QCBOR_Private_ExponentiateNN(const int64_t nMantissa,
- const int64_t nExponent,
- int64_t *pnResult,
- fExponentiator pfExp)
-{
- uint64_t uResult;
- uint64_t uMantissa;
-
- /* Take the absolute value and put it into an unsigned. */
- if(nMantissa >= 0) {
- /* Positive case is straightforward */
- uMantissa = (uint64_t)nMantissa;
- } else if(nMantissa != INT64_MIN) {
- /* The common negative case. See next. */
- uMantissa = (uint64_t)-nMantissa;
- } else {
- /* int64_t and uint64_t are always two's complement per the
- * C standard (and since QCBOR uses these it only works with
- * two's complement, which is pretty much universal these
- * days). The range of a negative two's complement integer is
- * one more that than a positive, so the simple code above might
- * not work all the time because you can't simply negate the
- * value INT64_MIN because it can't be represented in an
- * int64_t. -INT64_MIN can however be represented in a
- * uint64_t. Some compilers seem to recognize this case for the
- * above code and put the correct value in uMantissa, however
- * they are not required to do this by the C standard. This next
- * line does however work for all compilers.
- *
- * This does assume two's complement where -INT64_MIN ==
- * INT64_MAX + 1 (which wouldn't be true for one's complement or
- * sign and magnitude (but we know we're using two's complement
- * because int64_t requires it)).
- *
- * See these, particularly the detailed commentary:
- * https://stackoverflow.com/questions/54915742/does-c99-mandate-a-int64-t-type-be-available-always
- * https://stackoverflow.com/questions/37301078/is-negating-int-min-undefined-behaviour
- */
- uMantissa = (uint64_t)INT64_MAX+1;
- }
-
- /* Call the exponentiator passed for either base 2 or base 10.
- * Here is where most of the overflow errors are caught. */
- QCBORError uReturn = (*pfExp)(uMantissa, nExponent, &uResult);
- if(uReturn) {
- return uReturn;
- }
-
- /* Convert back to the sign of the original mantissa */
- if(nMantissa >= 0) {
- if(uResult > INT64_MAX) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- *pnResult = (int64_t)uResult;
- } else {
- /* (uint64_t)INT64_MAX+1 is used to represent the absolute value
- * of INT64_MIN. This assumes two's compliment representation
- * where INT64_MIN is one increment farther from 0 than
- * INT64_MAX. Trying to write -INT64_MIN doesn't work to get
- * this because the compiler makes it an int64_t which can't
- * represent -INT64_MIN. Also see above.
- */
- if(uResult > (uint64_t)INT64_MAX+1) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- *pnResult = -(int64_t)uResult;
- }
-
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Exponentiate an unsigned mantissa and signed exponent to produce an unsigned result.
- *
- * @param[in] nMantissa Signed integer mantissa.
- * @param[in] nExponent Signed integer exponent.
- * @param[out] puResult Place to put the signed integer result.
- * @param[in] pfExp Exponentiation function.
- *
- * @returns Error code
- *
- * @c pfExp performs exponentiation on and unsigned mantissa and
- * produces an unsigned result. This errors out if the mantissa
- * is negative because the output is unsigned.
- */
-static QCBORError
-QCBOR_Private_ExponentitateNU(const int64_t nMantissa,
- const int64_t nExponent,
- uint64_t *puResult,
- fExponentiator pfExp)
-{
- if(nMantissa < 0) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- }
-
- /* Cast to unsigned is OK because of check for negative.
- * Cast to unsigned is OK because UINT64_MAX > INT64_MAX.
- * Exponentiation is straight forward
- */
- return (*pfExp)((uint64_t)nMantissa, nExponent, puResult);
-}
-
-
-/**
- * @brief Exponentiate an usnigned mantissa and unsigned exponent to produce an unsigned result.
- *
- * @param[in] uMantissa Unsigned integer mantissa.
- * @param[in] nExponent Unsigned integer exponent.
- * @param[out] puResult Place to put the unsigned integer result.
- * @param[in] pfExp Exponentiation function.
- *
- * @returns Error code
- *
- * @c pfExp performs exponentiation on and unsigned mantissa and
- * produces an unsigned result so this is just a wrapper that does
- * nothing (and is likely inlined).
- */
-static QCBORError
-QCBOR_Private_ExponentitateUU(const uint64_t uMantissa,
- const int64_t nExponent,
- uint64_t *puResult,
- fExponentiator pfExp)
-{
- return (*pfExp)(uMantissa, nExponent, puResult);
-}
-
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
-
-
-/**
- * @brief Convert a CBOR big number to a uint64_t.
- *
- * @param[in] BigNumber Bytes of the big number to convert.
- * @param[in] uMax Maximum value allowed for the result.
- * @param[out] pResult Place to put the unsigned integer result.
- *
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
- * too large to fit
- * @retval QCBOR_SUCCESS The conversion succeeded.
- *
- * Many values will overflow because a big number can represent a much
- * larger range than uint64_t.
- */
-static QCBORError
-QCBORDecode_Private_BigNumberToUInt(const UsefulBufC BigNumber,
- const uint64_t uMax,
- uint64_t *pResult)
-{
- uint64_t uResult;
- size_t uLen;
-
- const uint8_t *pByte = BigNumber.ptr;
-
- uResult = 0;
- for(uLen = BigNumber.len; uLen > 0; uLen--) {
- if(uResult > (uMax >> 8)) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- uResult = (uResult << 8) + *pByte++;
- }
-
- *pResult = uResult;
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Convert a CBOR postive big number to a uint64_t.
- *
- * @param[in] BigNumber Bytes of the big number to convert.
- * @param[out] pResult Place to put the unsigned integer result.
- *
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
- * too large to fit
- * @retval QCBOR_SUCCESS The conversion succeeded.
- *
- * Many values will overflow because a big num can represent a much
- * larger range than uint64_t.
- */
-static QCBORError
-QCBORDecode_Private_PositiveBigNumberToUInt(const UsefulBufC BigNumber,
- uint64_t *pResult)
-{
- return QCBORDecode_Private_BigNumberToUInt(BigNumber, UINT64_MAX, pResult);
-}
-
-
-/**
- * @brief Convert a CBOR positive big number to an int64_t.
- *
- * @param[in] BigNumber Bytes of the big number to convert.
- * @param[out] pResult Place to put the signed integer result.
- *
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
- * too large to fit
- * @retval QCBOR_SUCCESS The conversion succeeded.
- *
- * Many values will overflow because a big num can represent a much
- * larger range than int64_t.
- */
-static QCBORError
-QCBORDecode_Private_PositiveBigNumberToInt(const UsefulBufC BigNumber,
- int64_t *pResult)
-{
- uint64_t uResult;
- QCBORError uError;
-
- uError = QCBORDecode_Private_BigNumberToUInt(BigNumber, INT64_MAX, &uResult);
- if(uError != QCBOR_SUCCESS) {
- return uError;
- }
- /* Cast safe because QCBORDecode_Private_BigNumberToUInt() limits to INT64_MAX */
- *pResult = (int64_t)uResult;
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Convert a CBOR negative big number to an int64_t.
- *
- * @param[in] BigNumber Bytes of the big number to convert.
- * @param[out] pnResult Place to put the signed integer result.
- *
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
- * too large to fit
- * @retval QCBOR_SUCCESS The conversion succeeded.
- *
- * Many values will overflow because a big num can represent a much
- * larger range than int64_t.
- */
-static QCBORError
-QCBORDecode_Private_NegativeBigNumberToInt(const UsefulBufC BigNumber,
- int64_t *pnResult)
-{
- uint64_t uResult;
- QCBORError uError;
-
- /* The negative integer furthest from zero for a C int64_t is
- * INT64_MIN which is expressed as -INT64_MAX - 1. The value of a
- * negative number in CBOR is computed as -n - 1 where n is the
- * encoded integer, where n is what is in the variable BigNum. When
- * converting BigNum to a uint64_t, the maximum value is thus
- * INT64_MAX, so that when it -n - 1 is applied to it the result
- * will never be further from 0 than INT64_MIN.
- *
- * -n - 1 <= INT64_MIN.
- * -n - 1 <= -INT64_MAX - 1
- * n <= INT64_MAX.
- */
- uError = QCBORDecode_Private_BigNumberToUInt(BigNumber, INT64_MAX, &uResult);
- if(uError != QCBOR_SUCCESS) {
- return uError;
- }
-
- /* Now apply -n - 1. The cast is safe because
- * ConvertBigNumToUnsigned() is limited to INT64_MAX which does fit
- * is the largest positive integer that an int64_t can
- * represent. */
- *pnResult = -(int64_t)uResult - 1;
-
- return QCBOR_SUCCESS;
-}
-
-/**
- * @brief Convert an integer to a big number.
- *
- * @param[in] uNum The integer to convert.
- * @param[in] BigNumberBuf The buffer to output the big number to.
- *
- * @returns The big number or NULLUsefulBufC is the buffer is to small.
- *
- * This always succeeds unless the buffer is too small.
- */
-static UsefulBufC
-QCBORDecode_Private_UIntToBigNumber(uint64_t uNum, const UsefulBuf BigNumberBuf)
-{
- UsefulOutBuf UOB;
-
- /* With a UsefulOutBuf, there's no pointer math */
- UsefulOutBuf_Init(&UOB, BigNumberBuf);
-
- /* Must copy one byte even if zero. The loop, mask and shift
- * algorithm provides endian conversion.
- */
- do {
- UsefulOutBuf_InsertByte(&UOB, uNum & 0xff, 0);
- uNum >>= 8;
- } while(uNum);
-
- return UsefulOutBuf_OutUBuf(&UOB);
-}
-
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
-/**
- * @brief Convert a big number to double-precision float.
- *
- * @param[in] BigNumber The big number to convert.
- *
- * @returns The double value.
- *
- * This will always succeed. It will lose precision for larger
- * numbers. If the big number is too large to fit (more than
- * 1.7976931348623157E+308) infinity will be returned. NaN is never
- * returned.
- */
-static double
-QCBORDecode_Private_BigNumberToDouble(const UsefulBufC BigNumber)
-{
- double dResult;
- size_t uLen;
-
- const uint8_t *pByte = BigNumber.ptr;
-
- dResult = 0.0;
- /* This will overflow and become the float value INFINITY if the number
- * is too large to fit. */
- for(uLen = BigNumber.len; uLen > 0; uLen--){
- dResult = (dResult * 256.0) + (double)*pByte++;
- }
-
- return dResult;
-}
-#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
-
-
-/**
- * @brief Convert integers and floats to an int64_t.
- *
- * @param[in] pItem The item to convert.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pnValue The resulting converted value.
- *
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
- * in uConvertTypes.
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
- * or too small.
- */
-static QCBORError
-QCBOR_Private_ConvertInt64(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- switch(pItem->uDataType) {
- case QCBOR_TYPE_FLOAT:
- case QCBOR_TYPE_DOUBLE:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- /* https://pubs.opengroup.org/onlinepubs/009695399/functions/llround.html
- http://www.cplusplus.com/reference/cmath/llround/
- */
- // Not interested in FE_INEXACT
- feclearexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO);
- if(pItem->uDataType == QCBOR_TYPE_DOUBLE) {
- *pnValue = llround(pItem->val.dfnum);
- } else {
- *pnValue = lroundf(pItem->val.fnum);
- }
- if(fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO)) {
- // llround() shouldn't result in divide by zero, but catch
- // it here in case it unexpectedly does. Don't try to
- // distinguish between the various exceptions because it seems
- // they vary by CPU, compiler and OS.
- return QCBOR_ERR_FLOAT_EXCEPTION;
- }
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-#else
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
- break;
-
- case QCBOR_TYPE_INT64:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- *pnValue = pItem->val.int64;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_UINT64:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- if(pItem->val.uint64 < INT64_MAX) {
- *pnValue = pItem->val.int64;
- } else {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_65BIT_NEG_INT:
- /* This type occurs if the value won't fit into int64_t
- * so this is always an error. */
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- break;
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- return QCBOR_SUCCESS;
-}
-
-
-
-#if !defined(USEFULBUF_DISABLE_ALL_FLOAT) && !defined(QCBOR_DISABLE_PREFERRED_FLOAT)
-/*
- * Public function, see header qcbor/qcbor_spiffy_decode.h file
- */
-void
-QCBORDecode_GetNumberConvertPrecisely(QCBORDecodeContext *pMe,
- QCBORItem *pNumber)
-{
- QCBORItem Item;
- struct IEEE754_ToInt ToInt;
- double dNum;
- QCBORError uError;
-
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- // TODO:VGetNext?
- uError = QCBORDecode_GetNext(pMe, &Item);
- if(uError != QCBOR_SUCCESS) {
- *pNumber = Item;
- pMe->uLastError = (uint8_t)uError;
- return;
- }
-
- switch(Item.uDataType) {
- case QCBOR_TYPE_INT64:
- case QCBOR_TYPE_UINT64:
- *pNumber = Item;
- break;
-
- case QCBOR_TYPE_DOUBLE:
- ToInt = IEEE754_DoubleToInt(Item.val.dfnum);
- if(ToInt.type == IEEE754_ToInt_IS_INT) {
- pNumber->uDataType = QCBOR_TYPE_INT64;
- pNumber->val.int64 = ToInt.integer.is_signed;
- } else if(ToInt.type == IEEE754_ToInt_IS_UINT) {
- if(ToInt.integer.un_signed <= INT64_MAX) {
- /* Do the same as base QCBOR integer decoding */
- pNumber->uDataType = QCBOR_TYPE_INT64;
- pNumber->val.int64 = (int64_t)ToInt.integer.un_signed;
- } else {
- pNumber->uDataType = QCBOR_TYPE_UINT64;
- pNumber->val.uint64 = ToInt.integer.un_signed;
- }
- } else {
- *pNumber = Item;
- }
- break;
-
- case QCBOR_TYPE_FLOAT:
- ToInt = IEEE754_SingleToInt(Item.val.fnum);
- if(ToInt.type == IEEE754_ToInt_IS_INT) {
- pNumber->uDataType = QCBOR_TYPE_INT64;
- pNumber->val.int64 = ToInt.integer.is_signed;
- } else if(ToInt.type == IEEE754_ToInt_IS_UINT) {
- if(ToInt.integer.un_signed <= INT64_MAX) {
- /* Do the same as base QCBOR integer decoding */
- pNumber->uDataType = QCBOR_TYPE_INT64;
- pNumber->val.int64 = (int64_t)ToInt.integer.un_signed;
- } else {
- pNumber->uDataType = QCBOR_TYPE_UINT64;
- pNumber->val.uint64 = ToInt.integer.un_signed;
- }
- } else {
- *pNumber = Item;
- }
- break;
-
- case QCBOR_TYPE_65BIT_NEG_INT:
- if(Item.val.uint64 == UINT64_MAX) {
- /* The value -18446744073709551616 is encoded as an
- * unsigned 18446744073709551615. It's a whole number that
- * needs to be returned as a double. It can't be handled
- * by IEEE754_UintToDouble because 18446744073709551616
- * doesn't fit into a uint64_t. You can't get it by adding
- * 1 to 18446744073709551615.
- */
- pNumber->val.dfnum = -18446744073709551616.0;
- pNumber->uDataType = QCBOR_TYPE_DOUBLE;
- } else {
- dNum = IEEE754_UintToDouble(Item.val.uint64 + 1, 1);
- if(dNum == IEEE754_UINT_TO_DOUBLE_OOB) {
- *pNumber = Item;
- } else {
- pNumber->val.dfnum = dNum;
- pNumber->uDataType = QCBOR_TYPE_DOUBLE;
- }
- }
- break;
-
- default:
- pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
- pNumber->uDataType = QCBOR_TYPE_NONE;
- break;
- }
-}
-
-#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT && ! QCBOR_DISABLE_PREFERRED_FLOAT */
-
-
-/* Add one to the big number and put the result in a new UsefulBufC
- * from storage in UsefulBuf.
- *
- * Leading zeros must be removed before calling this.
- *
- * Code Reviewers: THIS FUNCTION DOES POINTER MATH
- */
-static UsefulBufC
-QCBORDecode_BigNumberCopyPlusOne(UsefulBufC BigNumber, UsefulBuf BigNumberBuf)
-{
- uint8_t uCarry;
- uint8_t uSourceValue;
- const uint8_t *pSource;
- uint8_t *pDest;
- ptrdiff_t uDestBytesLeft;
-
- /* Start adding at the LSB */
- pSource = &((const uint8_t *)BigNumber.ptr)[BigNumber.len-1];
- pDest = &((uint8_t *)BigNumberBuf.ptr)[BigNumberBuf.len-1];
-
- uCarry = 1; /* Gets set back to zero if add the next line doesn't wrap */
- *pDest = *pSource + 1;
- while(1) {
- /* Wrap around from 0xff to 0 is a defined operation for
- * unsigned addition in C.*/
- if(*pDest != 0) {
- /* The add operation didn't wrap so no more carry. This
- * funciton only adds one, so when there is no more carry,
- * carrying is over to the end.
- */
- uCarry = 0;
- }
-
- uDestBytesLeft = pDest - (uint8_t *)BigNumberBuf.ptr;
- if(pSource <= (const uint8_t *)BigNumber.ptr && uCarry == 0) {
- break; /* Successful exit */
- }
- if(pSource > (const uint8_t *)BigNumber.ptr) {
- uSourceValue = *--pSource;
- } else {
- /* All source bytes processed, but not the last carry */
- uSourceValue = 0;
- }
-
- pDest--;
- if(uDestBytesLeft < 0) {
- return NULLUsefulBufC; /* Not enough space in destination buffer */
- }
-
- *pDest = uSourceValue + uCarry;
- }
-
- return (UsefulBufC){pDest, BigNumberBuf.len - (size_t)uDestBytesLeft};
-}
-
-
-/* This returns 1 when uNum is 0 */
-static size_t
-QCBORDecode_Private_CountNonZeroBytes(uint64_t uNum)
-{
- size_t uCount = 0;
- do {
- uCount++;
- uNum >>= 8;
- } while(uNum);
-
- return uCount;
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-QCBORError
-QCBORDecode_ProcessBigNumberNoPreferred(const QCBORItem Item,
- const UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- size_t uLen;
- UsefulBufC BigNumber;
- int uType;
-
- uType = Item.uDataType;
- if(uType == QCBOR_TYPE_BYTE_STRING) {
- uType = *pbIsNegative ? QCBOR_TYPE_NEGBIGNUM : QCBOR_TYPE_POSBIGNUM;
- }
-
- static const uint8_t Zero[] = {0x00};
- BigNumber = UsefulBuf_SkipLeading(Item.val.bigNum, 0);
- if(BigNumber.len == 0) {
- BigNumber = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(Zero);
- }
-
- /* Compute required length so it can be returned if buffer is too small */
- switch(uType) {
-
- case QCBOR_TYPE_POSBIGNUM:
- uLen = BigNumber.len;
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- uLen = BigNumber.len;
- if(UsefulBuf_IsValue(UsefulBuf_SkipLeading(BigNumber, 0), 0xff) == SIZE_MAX) {
- uLen++;
- }
- break;
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- *pBigNumber = (UsefulBufC){NULL, uLen};
-
- if(BigNumberBuf.len < uLen || uLen == 0 || BigNumberBuf.ptr == NULL) {
- return BigNumberBuf.ptr == NULL ? QCBOR_SUCCESS : QCBOR_ERR_BUFFER_TOO_SMALL;
- /* Buffer is too short or type is wrong */
- }
-
-
- if(uType == QCBOR_TYPE_POSBIGNUM) {
- *pBigNumber = UsefulBuf_Copy(BigNumberBuf, BigNumber);
- *pbIsNegative = false;
- } else if(uType == QCBOR_TYPE_NEGBIGNUM) {
- /* The messy one. Take the stuff in the buffer and copy it to
- * the new buffer, adding one to it. This might be one byte
- * bigger than the original because of the carry from adding
- * one.*/
- *pbIsNegative = true;
- *pBigNumber = QCBORDecode_BigNumberCopyPlusOne(BigNumber, BigNumberBuf);
- }
-
- return QCBOR_SUCCESS;
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-QCBORError
-QCBORDecode_ProcessBigNumber(const QCBORItem Item,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORError uResult;
- size_t uLen;
- int uType;
-
- uType = Item.uDataType;
-
- switch(uType) {
- case QCBOR_TYPE_POSBIGNUM:
- case QCBOR_TYPE_NEGBIGNUM:
- case QCBOR_TYPE_BYTE_STRING:
- return QCBORDecode_ProcessBigNumberNoPreferred(Item, BigNumberBuf, pBigNumber, pbIsNegative);
- break;
-
- case QCBOR_TYPE_INT64:
- uLen = QCBORDecode_Private_CountNonZeroBytes((uint64_t)ABSOLUTE_VALUE(Item.val.int64));
- break;
-
- case QCBOR_TYPE_UINT64:
- uLen = QCBORDecode_Private_CountNonZeroBytes(Item.val.uint64);
- break;
-
- case QCBOR_TYPE_65BIT_NEG_INT:
- uLen = Item.val.uint64 == UINT64_MAX ? 9 : QCBORDecode_Private_CountNonZeroBytes(Item.val.uint64);
- break;
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
-
- *pBigNumber = (UsefulBufC){NULL, uLen};
-
- if(BigNumberBuf.len < uLen || uLen == 0 || BigNumberBuf.ptr == NULL) {
- return BigNumberBuf.ptr == NULL ? QCBOR_SUCCESS : QCBOR_ERR_BUFFER_TOO_SMALL;
- /* Buffer is too short or type is wrong */
- }
-
- uResult = QCBOR_SUCCESS;
-
- if(uType == QCBOR_TYPE_UINT64) {
- *pBigNumber = QCBORDecode_Private_UIntToBigNumber(Item.val.uint64, BigNumberBuf);
- *pbIsNegative = false;
- } else if(uType == QCBOR_TYPE_INT64) {
- /* Offset of 1 for negative numbers already performed */
- *pbIsNegative = Item.val.int64 < 0;
- *pBigNumber = QCBORDecode_Private_UIntToBigNumber((uint64_t)(*pbIsNegative ? -Item.val.int64 : Item.val.int64), BigNumberBuf);
- } else if(uType == QCBOR_TYPE_65BIT_NEG_INT) {
- /* Offset of 1 for negative numbers NOT already performed */
- *pbIsNegative = true;
- if(Item.val.uint64 == UINT64_MAX) {
- /* The one value that can't be done with a computation
- * because it would overflow a uint64_t */
- static const uint8_t TwoToThe64[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- *pBigNumber = UsefulBuf_Copy(BigNumberBuf, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(TwoToThe64));
- } else {
- /* +1 because negative big numbers are encoded one less than actual */
- *pBigNumber = QCBORDecode_Private_UIntToBigNumber(Item.val.uint64 + 1, BigNumberBuf);
- }
- }
-
- return uResult;
-}
-
-
-
-static const uint64_t QCBORDecode_Private_BigNumberTagNumbers[] = {
- CBOR_TAG_POS_BIGNUM,
- CBOR_TAG_NEG_BIGNUM,
- CBOR_TAG_INVALID64};
-
-static const uint8_t QCBORDecode_Private_BigNumberTypes[] = {
- QCBOR_TYPE_INT64,
- QCBOR_TYPE_UINT64,
- QCBOR_TYPE_65BIT_NEG_INT,
- QCBOR_TYPE_POSBIGNUM,
- QCBOR_TYPE_NEGBIGNUM,
- QCBOR_TYPE_NONE};
-
-#define QCBORDecode_Private_BigNumberTypesNoPreferred &QCBORDecode_Private_BigNumberTypes[3]
-
-/**
- * @brief Common processing for a big number tag.
- *
- * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
- * @param[in] pItem The item with the date.
- * @param[out] pBignumber The returned big number
- * @param[out] pbIsNegative The returned sign of the big number.
- *
- * Common processing for the big number tag. Mostly make sure
- * the tag content is correct and copy forward any further other tag
- * numbers.
- */
-static void
-QCBORDecode_Private_BigNumberRawMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- QCBORItem *pItem,
- UsefulBufC *pBignumber,
- bool *pbIsNegative,
- size_t uOffset)
-{
- QCBORDecode_Private_ProcessTagItemMulti(pMe,
- pItem,
- uTagRequirement,
- QCBORDecode_Private_BigNumberTypesNoPreferred,
- QCBORDecode_Private_BigNumberTagNumbers,
- QCBORDecode_StringsTagCB,
- uOffset);
- if(pMe->uLastError) {
- return;
- }
-
- if(pItem->uDataType == QCBOR_TYPE_POSBIGNUM) {
- *pbIsNegative = false;
- } else if(pItem->uDataType == QCBOR_TYPE_NEGBIGNUM) {
- *pbIsNegative = true;
- }
- *pBignumber = pItem->val.bigNum;
-}
-
-
-static void
-QCBORDecode_Private_BigNumberNoPreferredMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- QCBORItem *pItem,
- const size_t uOffset,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORDecode_Private_ProcessTagItemMulti(pMe,
- pItem,
- uTagRequirement,
- QCBORDecode_Private_BigNumberTypesNoPreferred,
- QCBORDecode_Private_BigNumberTagNumbers,
- QCBORDecode_StringsTagCB,
- uOffset);
- if(pMe->uLastError) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBORDecode_ProcessBigNumberNoPreferred(*pItem, BigNumberBuf, pBigNumber, pbIsNegative);
-}
-
-
-static void
-QCBORDecode_Private_BigNumberMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- QCBORItem *pItem,
- const size_t uOffset,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORDecode_Private_ProcessTagItemMulti(pMe,
- pItem,
- uTagRequirement,
- QCBORDecode_Private_BigNumberTypes,
- QCBORDecode_Private_BigNumberTagNumbers,
- QCBORDecode_StringsTagCB,
- uOffset);
- if(pMe->uLastError) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBORDecode_ProcessBigNumber(*pItem, BigNumberBuf, pBigNumber, pbIsNegative);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumber(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_BigNumberMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumberInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberMain(pMe,
- uTagRequirement,
- &Item,
- uOffset,
- BigNumberBuf,
- pBigNumber,
- pbIsNegative);
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumberInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberMain(pMe,
- uTagRequirement,
- &Item,
- uOffset,
- BigNumberBuf,
- pBigNumber,
- pbIsNegative);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumberNoPreferred(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumberNoPreferredInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
-
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h
- */
-void
-QCBORDecode_GetTBigNumberNoPreferredInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- UsefulBuf BigNumberBuf,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
-}
-
-
-
-/*
- * Public function, see header qcbor/qcbor_spiffy_decode.h
- */
-void
-QCBORDecode_GetTBigNumberRaw(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- UsefulBufC *pBignumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_BigNumberRawMain(pMe,
- uTagRequirement,
- &Item,
- pBignumber,
- pbIsNegative,
- uOffset);
-}
-
-/*
- * Public function, see header qcbor/qcbor_spiffy_decode.h
- */
-void
-QCBORDecode_GetTBigNumberRawInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberRawMain(pMe,
- uTagRequirement,
- &Item,
- pBigNumber,
- pbIsNegative,
- uOffset);
-}
-
-/*
- * Public function, see header qcbor/qcbor_spiffy_decode.h
- */
-void
-QCBORDecode_GetTBigNumberRawInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- UsefulBufC *pBigNumber,
- bool *pbIsNegative)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_BigNumberRawMain(pMe,
- uTagRequirement,
- &Item,
- pBigNumber,
- pbIsNegative,
- uOffset);
-}
-
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-
-
-// TODO: relocate these notes?
-/* Some notes from the work to disable tags.
- * Some are out of date since tag refactoring.
- *
- * The API for big floats and decimal fractions seems good.
- * If there's any issue with it it's that the code size to
- * implement is a bit large because of the conversion
- * to/from int and bignum that is required. There is no API
- * that doesn't do the conversion so dead stripping will never
- * leave that code out.
- *
- * The implementation itself seems correct, but not as clean
- * and neat as it could be. It could probably be smaller too.
- *
- * The implementation has three main parts / functions
- * - The decoding of the array of two
- * - All the tag and type checking for the various API functions
- * - Conversion to/from bignum and int
- *
- * The type checking seems like it wastes the most code for
- * what it needs to do.
- *
- * The inlining for the conversion is probably making the
- * overall code base larger.
- *
- * The tests cases could be organized a lot better and be
- * more thorough.
- *
- * Seems also like there could be more common code in the
- * first tier part of the public API. Some functions only
- * vary by a TagSpec.
- */
-
-
-static const uint8_t QCBORDecode_Private_DecimalFractionTypes[] = {
- QCBOR_TYPE_DECIMAL_FRACTION,
- QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM,
- QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM,
- QCBOR_TYPE_DECIMAL_FRACTION_POS_U64,
- QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64,
- QCBOR_TYPE_NONE};
-
-static const uint8_t QCBORDecode_Private_BigFloatTypes[] = {
- QCBOR_TYPE_BIGFLOAT,
- QCBOR_TYPE_BIGFLOAT_POS_BIGNUM,
- QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM,
- QCBOR_TYPE_BIGFLOAT_POS_U64,
- QCBOR_TYPE_BIGFLOAT_NEG_U64,
- QCBOR_TYPE_NONE};
-
-/**
- * @brief Common processor for exponent and int64_t mantissa.
- *
- * @param[in] pMe The decode context.
- * @param[in] uTagRequirement Whether tag number must be present or not.
- * @param[in] uTagNumber The tag number for which content is expected.
- * @param[in] uOffset Cursor offset for tag number consumption checking.
- * @param[in] pItem The data item to process.
- * @param[out] pnMantissa The returned mantissa as an int64_t.
- * @param[out] pnExponent The returned exponent as an int64_t.
- *
- * This handles exponent and mantissa for base 2 and 10. This
- * is limited to a mantissa that is an int64_t. See also
- * QCBORDecode_Private_ProcessExpMantissaBig().
- *
- * On output, the item is always a fully decoded decimal fraction or
- * big float.
- *
- * This errors out if the input tag and type aren't as required.
- *
- * This always provides the correctly offset mantissa, even when the
- * input CBOR is a negative big number. This works the
- * same in QCBOR v1 and v2.
- */
-static void
-QCBORDecode_Private_ExpIntMantissaMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const uint64_t uTagNumber,
- const size_t uOffset,
- QCBORItem *pItem,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORError uErr;
- const uint8_t *qTypes;
-
- if(pMe->uLastError) {
- return;
- }
-
- if(uTagNumber == CBOR_TAG_BIGFLOAT) {
- qTypes = QCBORDecode_Private_BigFloatTypes;
- } else {
- qTypes = QCBORDecode_Private_DecimalFractionTypes;
- }
-
- QCBORDecode_Private_ProcessTagItem(pMe,
- pItem,
- uTagRequirement,
- qTypes,
- uTagNumber,
- QCBORDecode_ExpMantissaTagCB,
- uOffset);
-
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- uErr = QCBOR_SUCCESS;
- switch (pItem->uDataType) {
-
- case QCBOR_TYPE_DECIMAL_FRACTION:
- case QCBOR_TYPE_BIGFLOAT:
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- *pnMantissa = pItem->val.expAndMantissa.Mantissa.nInt;
- break;
-
-#ifndef QCBOR_DISABLE_TAGS
- /* If tags are disabled, mantissas can never be big nums */
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
- break;
-#endif /* QCBOR_DISABLE_TAGS */
-
- case QCBOR_TYPE_BIGFLOAT_NEG_U64:
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
- case QCBOR_TYPE_BIGFLOAT_POS_U64:
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
- uErr = QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- break;
-
- default:
- uErr = QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- pMe->uLastError = (uint8_t)uErr;
-}
-
-static void
-QCBORDecode_Private_ExpBigMantissaRawMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const uint64_t uTagNumber,
- const size_t uOffset,
- QCBORItem *pItem,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORError uErr;
- uint64_t uMantissa;
- const uint8_t *qTypes;
-
- if(pMe->uLastError) {
- return;
- }
-
- if(uTagNumber == CBOR_TAG_BIGFLOAT) {
- qTypes = QCBORDecode_Private_BigFloatTypes;
- } else {
- qTypes = QCBORDecode_Private_DecimalFractionTypes;
- }
-
- QCBORDecode_Private_ProcessTagItem(pMe,
- pItem,
- uTagRequirement,
- qTypes,
- uTagNumber,
- QCBORDecode_ExpMantissaTagCB,
- uOffset);
-
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- uErr = QCBOR_SUCCESS;
-
- switch (pItem->uDataType) {
-
- case QCBOR_TYPE_DECIMAL_FRACTION:
- case QCBOR_TYPE_BIGFLOAT:
- if(pItem->val.expAndMantissa.Mantissa.nInt >= 0) {
- uMantissa = (uint64_t)pItem->val.expAndMantissa.Mantissa.nInt;
- *pbIsNegative = false;
- } else {
- if(pItem->val.expAndMantissa.Mantissa.nInt != INT64_MIN) {
- uMantissa = (uint64_t)-pItem->val.expAndMantissa.Mantissa.nInt;
- } else {
- /* Can't negate like above when int64_t is INT64_MIN because it
- * will overflow. See ExponentNN() */
- uMantissa = (uint64_t)INT64_MAX+1;
- }
- *pbIsNegative = true;
- }
- /* Reverse the offset by 1 for type 1 negative value to be consistent
- * with big num case below which don't offset because it requires
- * big number arithmetic. This is a bug fix for QCBOR v1.5.
- */
- uMantissa--;
- *pMantissa = QCBORDecode_Private_UIntToBigNumber(uMantissa, BufferForMantissa);
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- break;
-
-#ifndef QCBOR_DISABLE_TAGS
- /* If tags are disabled, mantissas can never be big nums */
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = false;
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = true;
- break;
-#endif /* QCBOR_DISABLE_TAGS */
-
- default:
- uErr = QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- pMe->uLastError = (uint8_t)uErr;
-}
-
-
-/**
- * @brief Decode exponent and mantissa into a big number with negative offset of 1.
- *
- * @param[in] pMe The decode context.
- * @param[in] uTagRequirement Whether a tag number must be present or not.
- * @param[in] pItem Item to decode and convert.
- * @param[in] BufferForMantissa Buffer to output mantissa into.
- * @param[out] pMantissa The output mantissa.
- * @param[out] pbIsNegative The sign of the output.
- * @param[out] pnExponent The mantissa of the output.
- *
- * This is the common processing of a decimal fraction or a big float
- * into a big number. This will decode and consume all the CBOR items
- * that make up the decimal fraction or big float.
- *
- * This performs the subtraction of 1 from the negative value so the
- * caller doesn't need to. This links more object code than QCBORDecode_Private_ProcessExpMantissaBig().
- */
-static void
-QCBORDecode_Private_ExpBigMantissaMain(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const uint64_t uTagNumber,
- const size_t uOffset,
- QCBORItem *pItem,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORError uErr;
- QCBORItem TempMantissa;
- const uint8_t *qTypes;
-
- if(pMe->uLastError) {
- return;
- }
-
- if(uTagNumber == CBOR_TAG_BIGFLOAT) {
- qTypes = QCBORDecode_Private_BigFloatTypes;
- } else {
- qTypes = QCBORDecode_Private_DecimalFractionTypes;
- }
-
- QCBORDecode_Private_ProcessTagItem(pMe,
- pItem,
- uTagRequirement,
- qTypes,
- uTagNumber,
- QCBORDecode_ExpMantissaTagCB,
- uOffset);
-
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- memset(&TempMantissa, 0, sizeof(TempMantissa));
-
- switch (pItem->uDataType) {
-
- case QCBOR_TYPE_DECIMAL_FRACTION:
- case QCBOR_TYPE_BIGFLOAT:
- TempMantissa.uDataType = QCBOR_TYPE_INT64;
- TempMantissa.val.int64 = pItem->val.expAndMantissa.Mantissa.nInt;
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
- case QCBOR_TYPE_BIGFLOAT_POS_U64:
- TempMantissa.uDataType = QCBOR_TYPE_UINT64;
- TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
- case QCBOR_TYPE_BIGFLOAT_NEG_U64:
- TempMantissa.uDataType = QCBOR_TYPE_65BIT_NEG_INT;
- TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
- break;
-
-#ifndef QCBOR_DISABLE_TAGS
- /* If tags are disabled, mantissas can never be big nums */
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
- TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = false;
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
- TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
- *pbIsNegative = true;
- break;
-#endif /* ! QCBOR_DISABLE_TAGS */
- }
-
- *pnExponent = pItem->val.expAndMantissa.nExponent;
- uErr = QCBORDecode_ProcessBigNumber(TempMantissa, BufferForMantissa, pMantissa, pbIsNegative);
-
- pMe->uLastError = (uint8_t)uErr;
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFraction(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissa(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRaw(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_DECIMAL_FRACTION,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloat(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- int64_t *pnMantissa,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpIntMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- pnMantissa,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissa(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaRaw(QCBORDecodeContext *pMe,
- const uint8_t uTagRequirement,
- const UsefulBuf MantissaBuffer,
- UsefulBufC *pMantissa,
- bool *pbMantissaIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- MantissaBuffer,
- pMantissa,
- pbMantissaIsNegative,
- pnExponent);
-}
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaRawInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint8_t uTagRequirement,
- const UsefulBuf BufferForMantissa,
- UsefulBufC *pMantissa,
- bool *pbIsNegative,
- int64_t *pnExponent)
-{
- QCBORItem Item;
- size_t uOffset;
-
- QCBORDecode_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
- QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
- uTagRequirement,
- CBOR_TAG_BIGFLOAT,
- uOffset,
- &Item,
- BufferForMantissa,
- pMantissa,
- pbIsNegative,
- pnExponent);
-}
-
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
-
-
-/**
- * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pnValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetInt64Convert().
- */
-void
-QCBORDecode_Private_GetInt64Convert(QCBORDecodeContext *pMe,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem)
-{
- QCBORDecode_VGetNext(pMe, pItem);
- if(pMe->uLastError) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
- uConvertTypes,
- pnValue);
-}
-
-/**
- * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] nLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pnValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetInt64ConvertInMapN().
- */
-void
-QCBORDecode_Private_GetInt64ConvertInMapN(QCBORDecodeContext *pMe,
- int64_t nLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
- uConvertTypes,
- pnValue);
-}
-
-/**
- * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] szLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pnValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetInt64ConvertInMapSZ().
- */
-void
-QCBORDecode_Private_GetInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
- const char * szLabel,
- uint32_t uConvertTypes,
- int64_t *pnValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
- uConvertTypes,
- pnValue);
-}
-
-
-/**
- * @brief Convert many number types to an int64_t.
- *
- * @param[in] pItem The item to convert.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pnValue The resulting converted value.
- *
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
- * in uConvertTypes.
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
- * or too small.
- */
-static QCBORError
-QCBOR_Private_Int64ConvertAll(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- switch(pItem->uDataType) {
-
- case QCBOR_TYPE_POSBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- return QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.bigNum, pnValue);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- return QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.bigNum, pnValue);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
- case QCBOR_TYPE_DECIMAL_FRACTION:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- return QCBOR_Private_ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- &QCBOR_Private_Exponentitate10);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
- return QCBOR_Private_ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- QCBOR_Private_Exponentitate2);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(uErr) {
- return uErr;
- }
- return QCBOR_Private_ExponentiateNN(nMantissa,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- QCBOR_Private_Exponentitate10);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(uErr) {
- return uErr;
- }
- return QCBOR_Private_ExponentiateNN(nMantissa,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- QCBOR_Private_Exponentitate10);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(uErr) {
- return uErr;
- }
- return QCBOR_Private_ExponentiateNN(nMantissa,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- QCBOR_Private_Exponentitate2);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- int64_t nMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
- if(uErr) {
- return uErr;
- }
- return QCBOR_Private_ExponentiateNN(nMantissa,
- pItem->val.expAndMantissa.nExponent,
- pnValue,
- QCBOR_Private_Exponentitate2);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE; }
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
-
- QCBORDecode_Private_GetInt64Convert(pMe, uConvertTypes, 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)QCBOR_Private_Int64ConvertAll(&Item,
- uConvertTypes,
- pnValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
-
- QCBORDecode_Private_GetInt64ConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- 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)QCBOR_Private_Int64ConvertAll(&Item,
- uConvertTypes,
- pnValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- int64_t *pnValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetInt64ConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- 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)QCBOR_Private_Int64ConvertAll(&Item,
- uConvertTypes,
- pnValue);
-}
-
-
-/**
- * @brief Convert many number types to an uint64_t.
- *
- * @param[in] pItem The item to convert.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] puValue The resulting converted value.
- *
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
- * in uConvertTypes.
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
- * or too small.
- */
-static QCBORError
-QCBOR_Private_ConvertUInt64(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- switch(pItem->uDataType) {
- case QCBOR_TYPE_DOUBLE:
- case QCBOR_TYPE_FLOAT:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- // Can't use llround here because it will not convert values
- // greater than INT64_MAX and less than UINT64_MAX that
- // need to be converted so it is more complicated.
- feclearexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO);
- if(pItem->uDataType == QCBOR_TYPE_DOUBLE) {
- if(isnan(pItem->val.dfnum)) {
- return QCBOR_ERR_FLOAT_EXCEPTION;
- } else if(pItem->val.dfnum < 0) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- } else {
- double dRounded = round(pItem->val.dfnum);
- // See discussion in DecodeDateEpoch() for
- // explanation of - 0x7ff
- if(dRounded > (double)(UINT64_MAX- 0x7ff)) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- *puValue = (uint64_t)dRounded;
- }
- } else {
- if(isnan(pItem->val.fnum)) {
- return QCBOR_ERR_FLOAT_EXCEPTION;
- } else if(pItem->val.fnum < 0) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- } else {
- float fRounded = roundf(pItem->val.fnum);
- // See discussion in DecodeDateEpoch() for
- // explanation of - 0x7ff
- if(fRounded > (float)(UINT64_MAX- 0x7ff)) {
- return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
- }
- *puValue = (uint64_t)fRounded;
- }
- }
- if(fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO)) {
- // round() and roundf() shouldn't result in exceptions here, but
- // catch them to be robust and thorough. Don't try to
- // distinguish between the various exceptions because it seems
- // they vary by CPU, compiler and OS.
- return QCBOR_ERR_FLOAT_EXCEPTION;
- }
-
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-#else
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
- break;
-
- case QCBOR_TYPE_INT64:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- if(pItem->val.int64 >= 0) {
- *puValue = (uint64_t)pItem->val.int64;
- } else {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- }
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_UINT64:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- *puValue = pItem->val.uint64;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_65BIT_NEG_INT:
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] puValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetUInt64Convert().
- */
-void
-QCBORDecode_Private_GetUInt64Convert(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem)
-{
- QCBORDecode_VGetNext(pMe, pItem);
- if(pMe->uLastError) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
- uConvertTypes,
- puValue);
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] nLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] puValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetUInt64ConvertInMapN().
- */
-void
-QCBORDecode_Private_GetUInt64ConvertInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
- uConvertTypes,
- puValue);
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] szLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] puValue Result of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetUInt64ConvertInMapSZ().
- */
-void
-QCBORDecode_Private_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
- uConvertTypes,
- puValue);
-}
-
-
-/**
- * @brief Convert many number types to an unt64_t.
- *
- * @param[in] pItem The item to convert.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] puValue The resulting converted value.
- *
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
- * in uConvertTypes.
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
- * or too small.
- */
-static QCBORError
-QCBOR_Private_UInt64ConvertAll(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- switch(pItem->uDataType) { /* -Wmaybe-uninitialized falsly warns here */
-
- case QCBOR_TYPE_POSBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- return QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.bigNum, puValue);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
-
- case QCBOR_TYPE_DECIMAL_FRACTION:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- return QCBOR_Private_ExponentitateNU(pItem->val.expAndMantissa.Mantissa.nInt,
- pItem->val.expAndMantissa.nExponent,
- puValue,
- QCBOR_Private_Exponentitate10);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
- return QCBOR_Private_ExponentitateNU(pItem->val.expAndMantissa.Mantissa.nInt,
- pItem->val.expAndMantissa.nExponent,
- puValue,
- QCBOR_Private_Exponentitate2);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- uint64_t uMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.expAndMantissa.Mantissa.bigNum, &uMantissa);
- if(uErr != QCBOR_SUCCESS) {
- return uErr;
- }
- return QCBOR_Private_ExponentitateUU(uMantissa,
- pItem->val.expAndMantissa.nExponent,
- puValue,
- QCBOR_Private_Exponentitate10);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- uint64_t uMantissa;
- QCBORError uErr;
- uErr = QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.expAndMantissa.Mantissa.bigNum,
- &uMantissa);
- if(uErr != QCBOR_SUCCESS) {
- return uErr;
- }
- return QCBOR_Private_ExponentitateUU(uMantissa,
- pItem->val.expAndMantissa.nExponent,
- puValue,
- QCBOR_Private_Exponentitate2);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetUInt64ConvertAll(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
-
- QCBORDecode_Private_GetUInt64Convert(pMe, uConvertTypes, puValue, &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)QCBOR_Private_UInt64ConvertAll(&Item,
- uConvertTypes,
- puValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetUInt64ConvertAllInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
-
- QCBORDecode_Private_GetUInt64ConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- puValue,
- &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)QCBOR_Private_UInt64ConvertAll(&Item,
- uConvertTypes,
- puValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetUInt64ConvertAllInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- uint64_t *puValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetUInt64ConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- puValue,
- &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)QCBOR_Private_UInt64ConvertAll(&Item,
- uConvertTypes,
- puValue);
-}
-
-
-
-
-#ifndef USEFULBUF_DISABLE_ALL_FLOAT
-/**
- * @brief Basic conversions to a double.
- *
- * @param[in] pItem The item to convert
- * @param[in] uConvertTypes Bit flags indicating source types for conversion
- * @param[out] pdValue The value converted to a double
- *
- * This does the conversions that don't need much object code,
- * the conversions from int, uint and float to double.
- *
- * See QCBOR_Private_DoubleConvertAll() for the full set
- * of conversions.
- */
-static QCBORError
-QCBOR_Private_ConvertDouble(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
- switch(pItem->uDataType) {
- case QCBOR_TYPE_FLOAT:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- // Simple cast does the job.
- *pdValue = (double)pItem->val.fnum;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- }
-#else /* QCBOR_DISABLE_FLOAT_HW_USE */
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
- break;
-
- case QCBOR_TYPE_DOUBLE:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
- *pdValue = pItem->val.dfnum;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- }
- break;
-
- case QCBOR_TYPE_INT64:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- // A simple cast seems to do the job with no worry of exceptions.
- // There will be precision loss for some values.
- *pdValue = (double)pItem->val.int64;
-
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-#else
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
- break;
-
- case QCBOR_TYPE_UINT64:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
- // A simple cast seems to do the job with no worry of exceptions.
- // There will be precision loss for some values.
- *pdValue = (double)pItem->val.uint64;
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-#else
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-
- case QCBOR_TYPE_65BIT_NEG_INT:
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- // TODO: don't use float HW. We have the function to do it.
- *pdValue = -(double)pItem->val.uint64 - 1;
- break;
-#else
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- return QCBOR_SUCCESS;
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to double (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] uConvertTypes Bit mask list of conversion options
- * @param[out] pdValue The output of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetDoubleConvert().
- */
-void
-QCBORDecode_Private_GetDoubleConvert(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- double *pdValue,
- QCBORItem *pItem)
-{
- QCBORDecode_VGetNext(pMe, pItem);
- if(pMe->uLastError) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
- uConvertTypes,
- pdValue);
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to double (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] nLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options
- * @param[out] pdValue The output of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetDoubleConvertInMapN().
- */
-void
-QCBORDecode_Private_GetDoubleConvertInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- double *pdValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
- uConvertTypes,
- pdValue);
-}
-
-
-/**
- * @brief Almost-public method to decode a number and convert to double (semi-private).
- *
- * @param[in] pMe The decode context.
- * @param[in] szLabel Label to find in map.
- * @param[in] uConvertTypes Bit mask list of conversion options
- * @param[out] pdValue The output of the conversion.
- * @param[in,out] pItem Temporary space to store Item, returned item.
- *
- * See QCBORDecode_GetDoubleConvertInMapSZ().
- */
-void
-QCBORDecode_Private_GetDoubleConvertInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- double *pdValue,
- QCBORItem *pItem)
-{
- QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
- if(pMe->uLastError != QCBOR_SUCCESS) {
- return;
- }
-
- pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
- uConvertTypes,
- pdValue);
-}
-
-
-/**
- * @brief Convert many number types to a double.
- *
- * @param[in] pItem The item to convert.
- * @param[in] uConvertTypes Bit mask list of conversion options.
- * @param[out] pdValue The resulting converted value.
- *
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
- * in uConvertTypes.
- * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
- * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
- * or too small.
- */
-static QCBORError
-QCBOR_Private_DoubleConvertAll(const QCBORItem *pItem,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
-#ifndef QCBOR_DISABLE_FLOAT_HW_USE
- /*
- * What Every Computer Scientist Should Know About Floating-Point Arithmetic
- * https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
- */
- switch(pItem->uDataType) {
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
- case QCBOR_TYPE_DECIMAL_FRACTION:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- // Underflow gives 0, overflow gives infinity
- *pdValue = (double)pItem->val.expAndMantissa.Mantissa.nInt *
- pow(10.0, (double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT ) {
- // Underflow gives 0, overflow gives infinity
- *pdValue = (double)pItem->val.expAndMantissa.Mantissa.nInt *
- exp2((double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
- case QCBOR_TYPE_POSBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- *pdValue = QCBORDecode_Private_BigNumberToDouble(pItem->val.bigNum);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_NEGBIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
- *pdValue = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.bigNum);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
-#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
- case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- double dMantissa = QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
- *pdValue = dMantissa * pow(10, (double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
- /* Must subtract 1 for CBOR negative integer offset */
- double dMantissa = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
- *pdValue = dMantissa * pow(10, (double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
- double dMantissa = QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
- *pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-
- case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
- if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
- double dMantissa = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
- *pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
- } else {
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
- break;
-#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
-
- default:
- return QCBOR_ERR_UNEXPECTED_TYPE;
- }
-
- return QCBOR_SUCCESS;
-
-#else
- (void)pItem;
- (void)uConvertTypes;
- (void)pdValue;
- return QCBOR_ERR_HW_FLOAT_DISABLED;
-#endif /* QCBOR_DISABLE_FLOAT_HW_USE */
-
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetDoubleConvertAll(QCBORDecodeContext *pMe,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
-
- QCBORItem Item;
-
- QCBORDecode_Private_GetDoubleConvert(pMe, uConvertTypes, pdValue, &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)QCBOR_Private_DoubleConvertAll(&Item,
- uConvertTypes,
- pdValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetDoubleConvertAllInMapN(QCBORDecodeContext *pMe,
- const int64_t nLabel,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
- QCBORItem Item;
-
- QCBORDecode_Private_GetDoubleConvertInMapN(pMe,
- nLabel,
- uConvertTypes,
- pdValue,
- &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)QCBOR_Private_DoubleConvertAll(&Item,
- uConvertTypes,
- pdValue);
-}
-
-
-/*
- * Public function, see header qcbor/qcbor_decode.h file
- */
-void
-QCBORDecode_GetDoubleConvertAllInMapSZ(QCBORDecodeContext *pMe,
- const char *szLabel,
- const uint32_t uConvertTypes,
- double *pdValue)
-{
- QCBORItem Item;
- QCBORDecode_Private_GetDoubleConvertInMapSZ(pMe,
- szLabel,
- uConvertTypes,
- pdValue,
- &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)QCBOR_Private_DoubleConvertAll(&Item,
- uConvertTypes,
- pdValue);
-}
-#endif /* USEFULBUF_DISABLE_ALL_FLOAT */
-
-
-// TODO: re order above functions in tag number order
diff --git a/src/qcbor_number_decode.c b/src/qcbor_number_decode.c
new file mode 100644
index 0000000..6873b94
--- /dev/null
+++ b/src/qcbor_number_decode.c
@@ -0,0 +1,3148 @@
+/* ==========================================================================
+ * number_decode.c -- Number decoding beyond the basic ints and floats
+ *
+ * Copyright (c) 2016-2018, The Linux Foundation.
+ * Copyright (c) 2018-2024, Laurence Lundblade.
+ * Copyright (c) 2021, Arm Limited.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * See BSD-3-Clause license in README.md
+ *
+ * Created on 11/14/24 from qcbor_decode.c
+ * ========================================================================== */
+
+
+#include "qcbor/qcbor_decode.h"
+#include "qcbor/qcbor_spiffy_decode.h"
+#include "qcbor/qcbor_number_decode.h"
+#include "qcbor/qcbor_tag_decode.h"
+#include "decode_private.h"
+#include "ieee754.h" /* Does not use math.h */
+
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+
+#include <math.h> /* For isnan(), llround(), llroudf(), round(), roundf(),
+ * pow(), exp2()
+ */
+#include <fenv.h> /* feclearexcept(), fetestexcept() */
+
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+
+
+/* Order of stuff here is
+ * Simple conversions between ints and floats
+ * Complicated conversions involving big numbers, mantissa and exponent
+ * Big number decoding
+ * Mantissa and exponent decoding
+ */
+
+
+#if (defined(__GNUC__) && !defined(__clang__))
+/*
+ * This is how the -Wmaybe-uninitialized compiler warning is
+ * handled. It can’t be ignored because some version of gcc enable it
+ * with -Wall which is a common and useful gcc warning option. It also
+ * can’t be ignored because it is the goal of QCBOR to compile clean
+ * out of the box in all environments.
+ *
+ * The big problem with -Wmaybe-uninitialized is that it generates
+ * false positives. It complains things are uninitialized when they
+ * are not. This is because it is not a thorough static analyzer. This
+ * is why “maybe” is in its name. The problem is it is just not
+ * thorough enough to understand all the code (and someone saw fit to
+ * put it in gcc and worse to enable it with -Wall).
+ *
+ * One solution would be to change the code so -Wmaybe-uninitialized
+ * doesn’t get confused, for example adding an unnecessary extra
+ * initialization to zero. (If variables were truly uninitialized, the
+ * correct path is to understand the code thoroughly and set them to
+ * the correct value at the correct time; in essence this is already
+ * done; -Wmaybe-uninitialized just can’t tell). This path is not
+ * taken because it makes the code bigger and is kind of the tail
+ * wagging the dog.
+ *
+ * The solution here is to just use a pragma to disable it for the
+ * whole file. Disabling it for each line makes the code fairly ugly
+ * requiring #pragma to push, pop and ignore. Another reason is the
+ * warnings issues vary by version of gcc and which optimization
+ * optimizations are selected. Another reason is that compilers other
+ * than gcc don’t have -Wmaybe-uninitialized.
+ *
+ * One may ask how to be sure these warnings are false positives and
+ * not real issues. 1) The code has been read carefully to check. 2)
+ * Testing is pretty thorough. 3) This code has been run through
+ * thorough high-quality static analyzers.
+ *
+ * In particularly, most of the warnings are about
+ * Item.Item->uDataType being uninitialized. QCBORDecode_GetNext()
+ * *always* sets this value and test case confirm
+ * this. -Wmaybe-uninitialized just can't tell.
+ *
+ * https://stackoverflow.com/questions/5080848/disable-gcc-may-be-used-uninitialized-on-a-particular-variable
+ */
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+
+
+/**
+ * @brief Convert integers and floats to an int64_t.
+ *
+ * @param[in] pItem The item to convert.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pnValue The resulting converted value.
+ *
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
+ * in uConvertTypes.
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
+ * or too small.
+ */
+static QCBORError
+QCBOR_Private_ConvertInt64(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ switch(pItem->uDataType) {
+ case QCBOR_TYPE_FLOAT:
+ case QCBOR_TYPE_DOUBLE:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ /* https://pubs.opengroup.org/onlinepubs/009695399/functions/llround.html
+ http://www.cplusplus.com/reference/cmath/llround/
+ */
+ // Not interested in FE_INEXACT
+ feclearexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO);
+ if(pItem->uDataType == QCBOR_TYPE_DOUBLE) {
+ *pnValue = llround(pItem->val.dfnum);
+ } else {
+ *pnValue = lroundf(pItem->val.fnum);
+ }
+ if(fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO)) {
+ // llround() shouldn't result in divide by zero, but catch
+ // it here in case it unexpectedly does. Don't try to
+ // distinguish between the various exceptions because it seems
+ // they vary by CPU, compiler and OS.
+ return QCBOR_ERR_FLOAT_EXCEPTION;
+ }
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ break;
+
+ case QCBOR_TYPE_INT64:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ *pnValue = pItem->val.int64;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_UINT64:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ if(pItem->val.uint64 < INT64_MAX) {
+ *pnValue = pItem->val.int64;
+ } else {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_65BIT_NEG_INT:
+ /* This type occurs if the value won't fit into int64_t
+ * so this is always an error. */
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pnValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetInt64Convert().
+ */
+void
+QCBORDecode_Private_GetInt64Convert(QCBORDecodeContext *pMe,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_VGetNext(pMe, pItem);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
+ uConvertTypes,
+ pnValue);
+}
+
+/**
+ * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] nLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pnValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetInt64ConvertInMapN().
+ */
+void
+QCBORDecode_Private_GetInt64ConvertInMapN(QCBORDecodeContext *pMe,
+ int64_t nLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
+ uConvertTypes,
+ pnValue);
+}
+
+/**
+ * @brief Almost-public method to decode a number and convert to int64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] szLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pnValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetInt64ConvertInMapSZ().
+ */
+void
+QCBORDecode_Private_GetInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char * szLabel,
+ uint32_t uConvertTypes,
+ int64_t *pnValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertInt64(pItem,
+ uConvertTypes,
+ pnValue);
+}
+
+
+/**
+ * @brief Convert many number types to an uint64_t.
+ *
+ * @param[in] pItem The item to convert.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] puValue The resulting converted value.
+ *
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
+ * in uConvertTypes.
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
+ * or too small.
+ */
+static QCBORError
+QCBOR_Private_ConvertUInt64(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ switch(pItem->uDataType) {
+ case QCBOR_TYPE_DOUBLE:
+ case QCBOR_TYPE_FLOAT:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ // Can't use llround here because it will not convert values
+ // greater than INT64_MAX and less than UINT64_MAX that
+ // need to be converted so it is more complicated.
+ feclearexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO);
+ if(pItem->uDataType == QCBOR_TYPE_DOUBLE) {
+ if(isnan(pItem->val.dfnum)) {
+ return QCBOR_ERR_FLOAT_EXCEPTION;
+ } else if(pItem->val.dfnum < 0) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ } else {
+ double dRounded = round(pItem->val.dfnum);
+ // See discussion in DecodeDateEpoch() for
+ // explanation of - 0x7ff
+ if(dRounded > (double)(UINT64_MAX- 0x7ff)) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ *puValue = (uint64_t)dRounded;
+ }
+ } else {
+ if(isnan(pItem->val.fnum)) {
+ return QCBOR_ERR_FLOAT_EXCEPTION;
+ } else if(pItem->val.fnum < 0) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ } else {
+ float fRounded = roundf(pItem->val.fnum);
+ // See discussion in DecodeDateEpoch() for
+ // explanation of - 0x7ff
+ if(fRounded > (float)(UINT64_MAX- 0x7ff)) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ *puValue = (uint64_t)fRounded;
+ }
+ }
+ if(fetestexcept(FE_INVALID|FE_OVERFLOW|FE_UNDERFLOW|FE_DIVBYZERO)) {
+ // round() and roundf() shouldn't result in exceptions here, but
+ // catch them to be robust and thorough. Don't try to
+ // distinguish between the various exceptions because it seems
+ // they vary by CPU, compiler and OS.
+ return QCBOR_ERR_FLOAT_EXCEPTION;
+ }
+
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ break;
+
+ case QCBOR_TYPE_INT64:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ if(pItem->val.int64 >= 0) {
+ *puValue = (uint64_t)pItem->val.int64;
+ } else {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ }
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_UINT64:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ *puValue = pItem->val.uint64;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_65BIT_NEG_INT:
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] puValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetUInt64Convert().
+ */
+void
+QCBORDecode_Private_GetUInt64Convert(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_VGetNext(pMe, pItem);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
+ uConvertTypes,
+ puValue);
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] nLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] puValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetUInt64ConvertInMapN().
+ */
+void
+QCBORDecode_Private_GetUInt64ConvertInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
+ uConvertTypes,
+ puValue);
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to uint64_t (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] szLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] puValue Result of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetUInt64ConvertInMapSZ().
+ */
+void
+QCBORDecode_Private_GetUInt64ConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertUInt64(pItem,
+ uConvertTypes,
+ puValue);
+}
+
+
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+/**
+ * @brief Basic conversions to a double.
+ *
+ * @param[in] pItem The item to convert
+ * @param[in] uConvertTypes Bit flags indicating source types for conversion
+ * @param[out] pdValue The value converted to a double
+ *
+ * This does the conversions that don't need much object code,
+ * the conversions from int, uint and float to double.
+ *
+ * See QCBOR_Private_DoubleConvertAll() for the full set
+ * of conversions.
+ */
+static QCBORError
+QCBOR_Private_ConvertDouble(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+ switch(pItem->uDataType) {
+ case QCBOR_TYPE_FLOAT:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ // Simple cast does the job.
+ *pdValue = (double)pItem->val.fnum;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ }
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ break;
+
+ case QCBOR_TYPE_DOUBLE:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_FLOAT) {
+ *pdValue = pItem->val.dfnum;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ }
+ break;
+
+ case QCBOR_TYPE_INT64:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ // A simple cast seems to do the job with no worry of exceptions.
+ // There will be precision loss for some values.
+ *pdValue = (double)pItem->val.int64;
+
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ break;
+
+ case QCBOR_TYPE_UINT64:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_XINT64) {
+ // A simple cast seems to do the job with no worry of exceptions.
+ // There will be precision loss for some values.
+ *pdValue = (double)pItem->val.uint64;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+
+ case QCBOR_TYPE_65BIT_NEG_INT:
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ // TODO: don't use float HW. We have the function to do it.
+ *pdValue = -(double)pItem->val.uint64 - 1;
+ break;
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to double (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] uConvertTypes Bit mask list of conversion options
+ * @param[out] pdValue The output of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetDoubleConvert().
+ */
+void
+QCBORDecode_Private_GetDoubleConvert(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ double *pdValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_VGetNext(pMe, pItem);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
+ uConvertTypes,
+ pdValue);
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to double (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] nLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options
+ * @param[out] pdValue The output of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetDoubleConvertInMapN().
+ */
+void
+QCBORDecode_Private_GetDoubleConvertInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ double *pdValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapN(pMe, nLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
+ uConvertTypes,
+ pdValue);
+}
+
+
+/**
+ * @brief Almost-public method to decode a number and convert to double (semi-private).
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] szLabel Label to find in map.
+ * @param[in] uConvertTypes Bit mask list of conversion options
+ * @param[out] pdValue The output of the conversion.
+ * @param[in,out] pItem Temporary space to store Item, returned item.
+ *
+ * See QCBORDecode_GetDoubleConvertInMapSZ().
+ */
+void
+QCBORDecode_Private_GetDoubleConvertInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ double *pdValue,
+ QCBORItem *pItem)
+{
+ QCBORDecode_GetItemInMapSZ(pMe, szLabel, QCBOR_TYPE_ANY, pItem);
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBOR_Private_ConvertDouble(pItem,
+ uConvertTypes,
+ pdValue);
+}
+
+
+#ifndef QCBOR_DISABLE_PREFERRED_FLOAT
+/*
+ * Public function, see header qcbor/qcbor_spiffy_decode.h file
+ */
+void
+QCBORDecode_GetNumberConvertPrecisely(QCBORDecodeContext *pMe,
+ QCBORItem *pNumber)
+{
+ QCBORItem Item;
+ struct IEEE754_ToInt ToInt;
+ double dNum;
+ QCBORError uError;
+
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ // TODO:VGetNext?
+ uError = QCBORDecode_GetNext(pMe, &Item);
+ if(uError != QCBOR_SUCCESS) {
+ *pNumber = Item;
+ pMe->uLastError = (uint8_t)uError;
+ return;
+ }
+
+ switch(Item.uDataType) {
+ case QCBOR_TYPE_INT64:
+ case QCBOR_TYPE_UINT64:
+ *pNumber = Item;
+ break;
+
+ case QCBOR_TYPE_DOUBLE:
+ ToInt = IEEE754_DoubleToInt(Item.val.dfnum);
+ if(ToInt.type == IEEE754_ToInt_IS_INT) {
+ pNumber->uDataType = QCBOR_TYPE_INT64;
+ pNumber->val.int64 = ToInt.integer.is_signed;
+ } else if(ToInt.type == IEEE754_ToInt_IS_UINT) {
+ if(ToInt.integer.un_signed <= INT64_MAX) {
+ /* Do the same as base QCBOR integer decoding */
+ pNumber->uDataType = QCBOR_TYPE_INT64;
+ pNumber->val.int64 = (int64_t)ToInt.integer.un_signed;
+ } else {
+ pNumber->uDataType = QCBOR_TYPE_UINT64;
+ pNumber->val.uint64 = ToInt.integer.un_signed;
+ }
+ } else {
+ *pNumber = Item;
+ }
+ break;
+
+ case QCBOR_TYPE_FLOAT:
+ ToInt = IEEE754_SingleToInt(Item.val.fnum);
+ if(ToInt.type == IEEE754_ToInt_IS_INT) {
+ pNumber->uDataType = QCBOR_TYPE_INT64;
+ pNumber->val.int64 = ToInt.integer.is_signed;
+ } else if(ToInt.type == IEEE754_ToInt_IS_UINT) {
+ if(ToInt.integer.un_signed <= INT64_MAX) {
+ /* Do the same as base QCBOR integer decoding */
+ pNumber->uDataType = QCBOR_TYPE_INT64;
+ pNumber->val.int64 = (int64_t)ToInt.integer.un_signed;
+ } else {
+ pNumber->uDataType = QCBOR_TYPE_UINT64;
+ pNumber->val.uint64 = ToInt.integer.un_signed;
+ }
+ } else {
+ *pNumber = Item;
+ }
+ break;
+
+ case QCBOR_TYPE_65BIT_NEG_INT:
+ if(Item.val.uint64 == UINT64_MAX) {
+ /* The value -18446744073709551616 is encoded as an
+ * unsigned 18446744073709551615. It's a whole number that
+ * needs to be returned as a double. It can't be handled
+ * by IEEE754_UintToDouble because 18446744073709551616
+ * doesn't fit into a uint64_t. You can't get it by adding
+ * 1 to 18446744073709551615.
+ */
+ pNumber->val.dfnum = -18446744073709551616.0;
+ pNumber->uDataType = QCBOR_TYPE_DOUBLE;
+ } else {
+ dNum = IEEE754_UintToDouble(Item.val.uint64 + 1, 1);
+ if(dNum == IEEE754_UINT_TO_DOUBLE_OOB) {
+ *pNumber = Item;
+ } else {
+ pNumber->val.dfnum = dNum;
+ pNumber->uDataType = QCBOR_TYPE_DOUBLE;
+ }
+ }
+ break;
+
+ default:
+ pMe->uLastError = QCBOR_ERR_UNEXPECTED_TYPE;
+ pNumber->uDataType = QCBOR_TYPE_NONE;
+ break;
+ }
+}
+
+#endif /* ! QCBOR_DISABLE_PREFERRED_FLOAT */
+#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT */
+
+
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+
+/**
+ * @brief Prototype for conversion of exponent and mantissa to unsigned integer.
+ *
+ * @param[in] uMantissa The mantissa.
+ * @param[in] nExponent The exponent.
+ * @param[out] puResult The resulting integer.
+ *
+ * Concrete implementations of this are for exponent base 10 and 2 supporting
+ * decimal fractions and big floats.
+ */
+typedef QCBORError (*fExponentiator)(uint64_t uMantissa, int64_t nExponent, uint64_t *puResult);
+
+
+/**
+ * @brief Base 10 exponentiate a mantissa and exponent into an unsigned 64-bit integer.
+ *
+ * @param[in] uMantissa The unsigned integer mantissa.
+ * @param[in] nExponent The signed integer exponent.
+ * @param[out] puResult Place to return the unsigned integer result.
+ *
+ * This computes: mantissa * 10 ^^ exponent as for a decimal fraction. The output is a 64-bit
+ * unsigned integer.
+ *
+ * There are many inputs for which the result will not fit in the
+ * 64-bit integer and @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will
+ * be returned.
+ */
+static QCBORError
+QCBOR_Private_Exponentitate10(const uint64_t uMantissa,
+ int64_t nExponent,
+ uint64_t *puResult)
+{
+ uint64_t uResult = uMantissa;
+
+ if(uResult != 0) {
+ /* This loop will run a maximum of 19 times because
+ * UINT64_MAX < 10 ^^ 19. More than that will cause
+ * exit with the overflow error
+ */
+ for(; nExponent > 0; nExponent--) {
+ if(uResult > UINT64_MAX / 10) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ uResult = uResult * 10;
+ }
+
+ for(; nExponent < 0; nExponent++) {
+ uResult = uResult / 10;
+ if(uResult == 0) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ }
+ }
+ /* else, mantissa is zero so this returns zero */
+
+ *puResult = uResult;
+
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Base 2 exponentiate a mantissa and exponent into an unsigned 64-bit integer.
+ *
+ * @param[in] uMantissa The unsigned integer mantissa.
+ * @param[in] nExponent The signed integer exponent.
+ * @param[out] puResult Place to return the unsigned integer result.
+ *
+ * This computes: mantissa * 2 ^^ exponent as for a big float. The
+ * output is a 64-bit unsigned integer.
+ *
+ * There are many inputs for which the result will not fit in the
+ * 64-bit integer and @ref QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW will
+ * be returned.
+ */
+static QCBORError
+QCBOR_Private_Exponentitate2(const uint64_t uMantissa,
+ int64_t nExponent,
+ uint64_t *puResult)
+{
+ uint64_t uResult;
+
+ uResult = uMantissa;
+
+ /* This loop will run a maximum of 64 times because INT64_MAX <
+ * 2^31. More than that will cause exit with the overflow error
+ */
+ while(nExponent > 0) {
+ if(uResult > UINT64_MAX >> 1) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ uResult = uResult << 1;
+ nExponent--;
+ }
+
+ while(nExponent < 0 ) {
+ if(uResult == 0) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ uResult = uResult >> 1;
+ nExponent++;
+ }
+
+ *puResult = uResult;
+
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Exponentiate a signed mantissa and signed exponent to produce a signed result.
+ *
+ * @param[in] nMantissa Signed integer mantissa.
+ * @param[in] nExponent Signed integer exponent.
+ * @param[out] pnResult Place to put the signed integer result.
+ * @param[in] pfExp Exponentiation function.
+ *
+ * @returns Error code
+ *
+ * @c pfExp performs exponentiation on and unsigned mantissa and
+ * produces an unsigned result. This converts the mantissa from signed
+ * and converts the result to signed. The exponentiation function is
+ * either for base 2 or base 10 (and could be other if needed).
+ */
+static QCBORError
+QCBOR_Private_ExponentiateNN(const int64_t nMantissa,
+ const int64_t nExponent,
+ int64_t *pnResult,
+ fExponentiator pfExp)
+{
+ uint64_t uResult;
+ uint64_t uMantissa;
+
+ /* Take the absolute value and put it into an unsigned. */
+ if(nMantissa >= 0) {
+ /* Positive case is straightforward */
+ uMantissa = (uint64_t)nMantissa;
+ } else if(nMantissa != INT64_MIN) {
+ /* The common negative case. See next. */
+ uMantissa = (uint64_t)-nMantissa;
+ } else {
+ /* int64_t and uint64_t are always two's complement per the
+ * C standard (and since QCBOR uses these it only works with
+ * two's complement, which is pretty much universal these
+ * days). The range of a negative two's complement integer is
+ * one more that than a positive, so the simple code above might
+ * not work all the time because you can't simply negate the
+ * value INT64_MIN because it can't be represented in an
+ * int64_t. -INT64_MIN can however be represented in a
+ * uint64_t. Some compilers seem to recognize this case for the
+ * above code and put the correct value in uMantissa, however
+ * they are not required to do this by the C standard. This next
+ * line does however work for all compilers.
+ *
+ * This does assume two's complement where -INT64_MIN ==
+ * INT64_MAX + 1 (which wouldn't be true for one's complement or
+ * sign and magnitude (but we know we're using two's complement
+ * because int64_t requires it)).
+ *
+ * See these, particularly the detailed commentary:
+ * https://stackoverflow.com/questions/54915742/does-c99-mandate-a-int64-t-type-be-available-always
+ * https://stackoverflow.com/questions/37301078/is-negating-int-min-undefined-behaviour
+ */
+ uMantissa = (uint64_t)INT64_MAX+1;
+ }
+
+ /* Call the exponentiator passed for either base 2 or base 10.
+ * Here is where most of the overflow errors are caught. */
+ QCBORError uReturn = (*pfExp)(uMantissa, nExponent, &uResult);
+ if(uReturn) {
+ return uReturn;
+ }
+
+ /* Convert back to the sign of the original mantissa */
+ if(nMantissa >= 0) {
+ if(uResult > INT64_MAX) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ *pnResult = (int64_t)uResult;
+ } else {
+ /* (uint64_t)INT64_MAX+1 is used to represent the absolute value
+ * of INT64_MIN. This assumes two's compliment representation
+ * where INT64_MIN is one increment farther from 0 than
+ * INT64_MAX. Trying to write -INT64_MIN doesn't work to get
+ * this because the compiler makes it an int64_t which can't
+ * represent -INT64_MIN. Also see above.
+ */
+ if(uResult > (uint64_t)INT64_MAX+1) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ *pnResult = -(int64_t)uResult;
+ }
+
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Exponentiate an unsigned mantissa and signed exponent to produce an unsigned result.
+ *
+ * @param[in] nMantissa Signed integer mantissa.
+ * @param[in] nExponent Signed integer exponent.
+ * @param[out] puResult Place to put the signed integer result.
+ * @param[in] pfExp Exponentiation function.
+ *
+ * @returns Error code
+ *
+ * @c pfExp performs exponentiation on and unsigned mantissa and
+ * produces an unsigned result. This errors out if the mantissa
+ * is negative because the output is unsigned.
+ */
+static QCBORError
+QCBOR_Private_ExponentitateNU(const int64_t nMantissa,
+ const int64_t nExponent,
+ uint64_t *puResult,
+ fExponentiator pfExp)
+{
+ if(nMantissa < 0) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ }
+
+ /* Cast to unsigned is OK because of check for negative.
+ * Cast to unsigned is OK because UINT64_MAX > INT64_MAX.
+ * Exponentiation is straight forward
+ */
+ return (*pfExp)((uint64_t)nMantissa, nExponent, puResult);
+}
+
+
+/**
+ * @brief Exponentiate an usnigned mantissa and unsigned exponent to produce an unsigned result.
+ *
+ * @param[in] uMantissa Unsigned integer mantissa.
+ * @param[in] nExponent Unsigned integer exponent.
+ * @param[out] puResult Place to put the unsigned integer result.
+ * @param[in] pfExp Exponentiation function.
+ *
+ * @returns Error code
+ *
+ * @c pfExp performs exponentiation on and unsigned mantissa and
+ * produces an unsigned result so this is just a wrapper that does
+ * nothing (and is likely inlined).
+ */
+static QCBORError
+QCBOR_Private_ExponentitateUU(const uint64_t uMantissa,
+ const int64_t nExponent,
+ uint64_t *puResult,
+ fExponentiator pfExp)
+{
+ return (*pfExp)(uMantissa, nExponent, puResult);
+}
+
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+
+
+
+/**
+ * @brief Convert a CBOR big number to a uint64_t.
+ *
+ * @param[in] BigNumber Bytes of the big number to convert.
+ * @param[in] uMax Maximum value allowed for the result.
+ * @param[out] pResult Place to put the unsigned integer result.
+ *
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
+ * too large to fit
+ * @retval QCBOR_SUCCESS The conversion succeeded.
+ *
+ * Many values will overflow because a big number can represent a much
+ * larger range than uint64_t.
+ */
+static QCBORError
+QCBORDecode_Private_BigNumberToUInt(const UsefulBufC BigNumber,
+ const uint64_t uMax,
+ uint64_t *pResult)
+{
+ uint64_t uResult;
+ size_t uLen;
+
+ const uint8_t *pByte = BigNumber.ptr;
+
+ uResult = 0;
+ for(uLen = BigNumber.len; uLen > 0; uLen--) {
+ if(uResult > (uMax >> 8)) {
+ return QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ }
+ uResult = (uResult << 8) + *pByte++;
+ }
+
+ *pResult = uResult;
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Convert a CBOR postive big number to a uint64_t.
+ *
+ * @param[in] BigNumber Bytes of the big number to convert.
+ * @param[out] pResult Place to put the unsigned integer result.
+ *
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
+ * too large to fit
+ * @retval QCBOR_SUCCESS The conversion succeeded.
+ *
+ * Many values will overflow because a big num can represent a much
+ * larger range than uint64_t.
+ */
+static QCBORError
+QCBORDecode_Private_PositiveBigNumberToUInt(const UsefulBufC BigNumber,
+ uint64_t *pResult)
+{
+ return QCBORDecode_Private_BigNumberToUInt(BigNumber, UINT64_MAX, pResult);
+}
+
+
+/**
+ * @brief Convert a CBOR positive big number to an int64_t.
+ *
+ * @param[in] BigNumber Bytes of the big number to convert.
+ * @param[out] pResult Place to put the signed integer result.
+ *
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
+ * too large to fit
+ * @retval QCBOR_SUCCESS The conversion succeeded.
+ *
+ * Many values will overflow because a big num can represent a much
+ * larger range than int64_t.
+ */
+static QCBORError
+QCBORDecode_Private_PositiveBigNumberToInt(const UsefulBufC BigNumber,
+ int64_t *pResult)
+{
+ uint64_t uResult;
+ QCBORError uError;
+
+ uError = QCBORDecode_Private_BigNumberToUInt(BigNumber, INT64_MAX, &uResult);
+ if(uError != QCBOR_SUCCESS) {
+ return uError;
+ }
+ /* Cast safe because QCBORDecode_Private_BigNumberToUInt() limits to INT64_MAX */
+ *pResult = (int64_t)uResult;
+ return QCBOR_SUCCESS;
+}
+
+
+/**
+ * @brief Convert a CBOR negative big number to an int64_t.
+ *
+ * @param[in] BigNumber Bytes of the big number to convert.
+ * @param[out] pnResult Place to put the signed integer result.
+ *
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW When the bignumber is
+ * too large to fit
+ * @retval QCBOR_SUCCESS The conversion succeeded.
+ *
+ * Many values will overflow because a big num can represent a much
+ * larger range than int64_t.
+ */
+static QCBORError
+QCBORDecode_Private_NegativeBigNumberToInt(const UsefulBufC BigNumber,
+ int64_t *pnResult)
+{
+ uint64_t uResult;
+ QCBORError uError;
+
+ /* The negative integer furthest from zero for a C int64_t is
+ * INT64_MIN which is expressed as -INT64_MAX - 1. The value of a
+ * negative number in CBOR is computed as -n - 1 where n is the
+ * encoded integer, where n is what is in the variable BigNum. When
+ * converting BigNum to a uint64_t, the maximum value is thus
+ * INT64_MAX, so that when it -n - 1 is applied to it the result
+ * will never be further from 0 than INT64_MIN.
+ *
+ * -n - 1 <= INT64_MIN.
+ * -n - 1 <= -INT64_MAX - 1
+ * n <= INT64_MAX.
+ */
+ uError = QCBORDecode_Private_BigNumberToUInt(BigNumber, INT64_MAX, &uResult);
+ if(uError != QCBOR_SUCCESS) {
+ return uError;
+ }
+
+ /* Now apply -n - 1. The cast is safe because
+ * ConvertBigNumToUnsigned() is limited to INT64_MAX which does fit
+ * is the largest positive integer that an int64_t can
+ * represent. */
+ *pnResult = -(int64_t)uResult - 1;
+
+ return QCBOR_SUCCESS;
+}
+
+/**
+ * @brief Convert an integer to a big number.
+ *
+ * @param[in] uNum The integer to convert.
+ * @param[in] BigNumberBuf The buffer to output the big number to.
+ *
+ * @returns The big number or NULLUsefulBufC is the buffer is to small.
+ *
+ * This always succeeds unless the buffer is too small.
+ */
+static UsefulBufC
+QCBORDecode_Private_UIntToBigNumber(uint64_t uNum, const UsefulBuf BigNumberBuf)
+{
+ UsefulOutBuf UOB;
+
+ /* With a UsefulOutBuf, there's no pointer math */
+ UsefulOutBuf_Init(&UOB, BigNumberBuf);
+
+ /* Must copy one byte even if zero. The loop, mask and shift
+ * algorithm provides endian conversion.
+ */
+ do {
+ UsefulOutBuf_InsertByte(&UOB, uNum & 0xff, 0);
+ uNum >>= 8;
+ } while(uNum);
+
+ return UsefulOutBuf_OutUBuf(&UOB);
+}
+
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+/**
+ * @brief Convert a big number to double-precision float.
+ *
+ * @param[in] BigNumber The big number to convert.
+ *
+ * @returns The double value.
+ *
+ * This will always succeed. It will lose precision for larger
+ * numbers. If the big number is too large to fit (more than
+ * 1.7976931348623157E+308) infinity will be returned. NaN is never
+ * returned.
+ */
+static double
+QCBORDecode_Private_BigNumberToDouble(const UsefulBufC BigNumber)
+{
+ double dResult;
+ size_t uLen;
+
+ const uint8_t *pByte = BigNumber.ptr;
+
+ dResult = 0.0;
+ /* This will overflow and become the float value INFINITY if the number
+ * is too large to fit. */
+ for(uLen = BigNumber.len; uLen > 0; uLen--){
+ dResult = (dResult * 256.0) + (double)*pByte++;
+ }
+
+ return dResult;
+}
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+
+
+
+/**
+ * @brief Convert many number types to an int64_t.
+ *
+ * @param[in] pItem The item to convert.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pnValue The resulting converted value.
+ *
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
+ * in uConvertTypes.
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
+ * or too small.
+ */
+static QCBORError
+QCBOR_Private_Int64ConvertAll(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ switch(pItem->uDataType) {
+
+ case QCBOR_TYPE_POSBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.bigNum, pnValue);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_NEGBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.bigNum, pnValue);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ return QCBOR_Private_ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ &QCBOR_Private_Exponentitate10);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
+ return QCBOR_Private_ExponentiateNN(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ QCBOR_Private_Exponentitate2);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ QCBOR_Private_Exponentitate10);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ QCBOR_Private_Exponentitate10);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ QCBOR_Private_Exponentitate2);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ int64_t nMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, &nMantissa);
+ if(uErr) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentiateNN(nMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ pnValue,
+ QCBOR_Private_Exponentitate2);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE; }
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetInt64ConvertAll(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetInt64Convert(pMe, uConvertTypes, 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)QCBOR_Private_Int64ConvertAll(&Item,
+ uConvertTypes,
+ pnValue);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetInt64ConvertAllInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetInt64ConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ 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)QCBOR_Private_Int64ConvertAll(&Item,
+ uConvertTypes,
+ pnValue);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetInt64ConvertAllInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ int64_t *pnValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetInt64ConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ 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)QCBOR_Private_Int64ConvertAll(&Item,
+ uConvertTypes,
+ pnValue);
+}
+
+
+
+/**
+ * @brief Convert many number types to an unt64_t.
+ *
+ * @param[in] pItem The item to convert.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] puValue The resulting converted value.
+ *
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
+ * in uConvertTypes.
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
+ * or too small.
+ */
+static QCBORError
+QCBOR_Private_UInt64ConvertAll(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ switch(pItem->uDataType) { /* -Wmaybe-uninitialized falsly warns here */
+
+ case QCBOR_TYPE_POSBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.bigNum, puValue);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_NEGBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ return QCBOR_Private_ExponentitateNU(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ puValue,
+ QCBOR_Private_Exponentitate10);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
+ return QCBOR_Private_ExponentitateNU(pItem->val.expAndMantissa.Mantissa.nInt,
+ pItem->val.expAndMantissa.nExponent,
+ puValue,
+ QCBOR_Private_Exponentitate2);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ uint64_t uMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.expAndMantissa.Mantissa.bigNum, &uMantissa);
+ if(uErr != QCBOR_SUCCESS) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentitateUU(uMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ puValue,
+ QCBOR_Private_Exponentitate10);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ uint64_t uMantissa;
+ QCBORError uErr;
+ uErr = QCBORDecode_Private_PositiveBigNumberToUInt(pItem->val.expAndMantissa.Mantissa.bigNum,
+ &uMantissa);
+ if(uErr != QCBOR_SUCCESS) {
+ return uErr;
+ }
+ return QCBOR_Private_ExponentitateUU(uMantissa,
+ pItem->val.expAndMantissa.nExponent,
+ puValue,
+ QCBOR_Private_Exponentitate2);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ return QCBOR_ERR_NUMBER_SIGN_CONVERSION;
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetUInt64ConvertAll(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetUInt64Convert(pMe, uConvertTypes, puValue, &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)QCBOR_Private_UInt64ConvertAll(&Item,
+ uConvertTypes,
+ puValue);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetUInt64ConvertAllInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetUInt64ConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ puValue,
+ &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)QCBOR_Private_UInt64ConvertAll(&Item,
+ uConvertTypes,
+ puValue);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetUInt64ConvertAllInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ uint64_t *puValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetUInt64ConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ puValue,
+ &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)QCBOR_Private_UInt64ConvertAll(&Item,
+ uConvertTypes,
+ puValue);
+}
+
+
+
+#ifndef USEFULBUF_DISABLE_ALL_FLOAT
+
+/**
+ * @brief Convert many number types to a double.
+ *
+ * @param[in] pItem The item to convert.
+ * @param[in] uConvertTypes Bit mask list of conversion options.
+ * @param[out] pdValue The resulting converted value.
+ *
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Conversion, possible, but not requested
+ * in uConvertTypes.
+ * @retval QCBOR_ERR_UNEXPECTED_TYPE Of a type that can't be converted
+ * @retval QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW Conversion result is too large
+ * or too small.
+ */
+static QCBORError
+QCBOR_Private_DoubleConvertAll(const QCBORItem *pItem,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+#ifndef QCBOR_DISABLE_FLOAT_HW_USE
+ /*
+ * What Every Computer Scientist Should Know About Floating-Point Arithmetic
+ * https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
+ */
+ switch(pItem->uDataType) {
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ // Underflow gives 0, overflow gives infinity
+ *pdValue = (double)pItem->val.expAndMantissa.Mantissa.nInt *
+ pow(10.0, (double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT ) {
+ // Underflow gives 0, overflow gives infinity
+ *pdValue = (double)pItem->val.expAndMantissa.Mantissa.nInt *
+ exp2((double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+ case QCBOR_TYPE_POSBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ *pdValue = QCBORDecode_Private_BigNumberToDouble(pItem->val.bigNum);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_NEGBIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIG_NUM) {
+ *pdValue = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.bigNum);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ double dMantissa = QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
+ *pdValue = dMantissa * pow(10, (double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_DECIMAL_FRACTION) {
+ /* Must subtract 1 for CBOR negative integer offset */
+ double dMantissa = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
+ *pdValue = dMantissa * pow(10, (double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
+ double dMantissa = QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
+ *pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ if(uConvertTypes & QCBOR_CONVERT_TYPE_BIGFLOAT) {
+ double dMantissa = -1-QCBORDecode_Private_BigNumberToDouble(pItem->val.expAndMantissa.Mantissa.bigNum);
+ *pdValue = dMantissa * exp2((double)pItem->val.expAndMantissa.nExponent);
+ } else {
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+ break;
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ return QCBOR_SUCCESS;
+
+#else /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+ (void)pItem;
+ (void)uConvertTypes;
+ (void)pdValue;
+ return QCBOR_ERR_HW_FLOAT_DISABLED;
+#endif /* ! QCBOR_DISABLE_FLOAT_HW_USE */
+
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetDoubleConvertAll(QCBORDecodeContext *pMe,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetDoubleConvert(pMe, uConvertTypes, pdValue, &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)QCBOR_Private_DoubleConvertAll(&Item,
+ uConvertTypes,
+ pdValue);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetDoubleConvertAllInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+ QCBORItem Item;
+
+ QCBORDecode_Private_GetDoubleConvertInMapN(pMe,
+ nLabel,
+ uConvertTypes,
+ pdValue,
+ &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)QCBOR_Private_DoubleConvertAll(&Item,
+ uConvertTypes,
+ pdValue);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetDoubleConvertAllInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint32_t uConvertTypes,
+ double *pdValue)
+{
+ QCBORItem Item;
+ QCBORDecode_Private_GetDoubleConvertInMapSZ(pMe,
+ szLabel,
+ uConvertTypes,
+ pdValue,
+ &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)QCBOR_Private_DoubleConvertAll(&Item,
+ uConvertTypes,
+ pdValue);
+}
+
+#endif /* ! USEFULBUF_DISABLE_ALL_FLOAT */
+
+
+
+/* Add one to the big number and put the result in a new UsefulBufC
+ * from storage in UsefulBuf.
+ *
+ * Leading zeros must be removed before calling this.
+ *
+ * Code Reviewers: THIS FUNCTION DOES POINTER MATH
+ */
+static UsefulBufC
+QCBORDecode_BigNumberCopyPlusOne(UsefulBufC BigNumber, UsefulBuf BigNumberBuf)
+{
+ uint8_t uCarry;
+ uint8_t uSourceValue;
+ const uint8_t *pSource;
+ uint8_t *pDest;
+ ptrdiff_t uDestBytesLeft;
+
+ /* Start adding at the LSB */
+ pSource = &((const uint8_t *)BigNumber.ptr)[BigNumber.len-1];
+ pDest = &((uint8_t *)BigNumberBuf.ptr)[BigNumberBuf.len-1];
+
+ uCarry = 1; /* Gets set back to zero if add the next line doesn't wrap */
+ *pDest = *pSource + 1;
+ while(1) {
+ /* Wrap around from 0xff to 0 is a defined operation for
+ * unsigned addition in C.*/
+ if(*pDest != 0) {
+ /* The add operation didn't wrap so no more carry. This
+ * funciton only adds one, so when there is no more carry,
+ * carrying is over to the end.
+ */
+ uCarry = 0;
+ }
+
+ uDestBytesLeft = pDest - (uint8_t *)BigNumberBuf.ptr;
+ if(pSource <= (const uint8_t *)BigNumber.ptr && uCarry == 0) {
+ break; /* Successful exit */
+ }
+ if(pSource > (const uint8_t *)BigNumber.ptr) {
+ uSourceValue = *--pSource;
+ } else {
+ /* All source bytes processed, but not the last carry */
+ uSourceValue = 0;
+ }
+
+ pDest--;
+ if(uDestBytesLeft < 0) {
+ return NULLUsefulBufC; /* Not enough space in destination buffer */
+ }
+
+ *pDest = uSourceValue + uCarry;
+ }
+
+ return (UsefulBufC){pDest, BigNumberBuf.len - (size_t)uDestBytesLeft};
+}
+
+
+/* This returns 1 when uNum is 0 */
+static size_t
+QCBORDecode_Private_CountNonZeroBytes(uint64_t uNum)
+{
+ size_t uCount = 0;
+ do {
+ uCount++;
+ uNum >>= 8;
+ } while(uNum);
+
+ return uCount;
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+QCBORError
+QCBORDecode_ProcessBigNumberNoPreferred(const QCBORItem Item,
+ const UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ size_t uLen;
+ UsefulBufC BigNumber;
+ int uType;
+
+ uType = Item.uDataType;
+ if(uType == QCBOR_TYPE_BYTE_STRING) {
+ uType = *pbIsNegative ? QCBOR_TYPE_NEGBIGNUM : QCBOR_TYPE_POSBIGNUM;
+ }
+
+ static const uint8_t Zero[] = {0x00};
+ BigNumber = UsefulBuf_SkipLeading(Item.val.bigNum, 0);
+ if(BigNumber.len == 0) {
+ BigNumber = UsefulBuf_FROM_BYTE_ARRAY_LITERAL(Zero);
+ }
+
+ /* Compute required length so it can be returned if buffer is too small */
+ switch(uType) {
+
+ case QCBOR_TYPE_POSBIGNUM:
+ uLen = BigNumber.len;
+ break;
+
+ case QCBOR_TYPE_NEGBIGNUM:
+ uLen = BigNumber.len;
+ if(UsefulBuf_IsValue(UsefulBuf_SkipLeading(BigNumber, 0), 0xff) == SIZE_MAX) {
+ uLen++;
+ }
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ *pBigNumber = (UsefulBufC){NULL, uLen};
+
+ if(BigNumberBuf.len < uLen || uLen == 0 || BigNumberBuf.ptr == NULL) {
+ return BigNumberBuf.ptr == NULL ? QCBOR_SUCCESS : QCBOR_ERR_BUFFER_TOO_SMALL;
+ /* Buffer is too short or type is wrong */
+ }
+
+
+ if(uType == QCBOR_TYPE_POSBIGNUM) {
+ *pBigNumber = UsefulBuf_Copy(BigNumberBuf, BigNumber);
+ *pbIsNegative = false;
+ } else if(uType == QCBOR_TYPE_NEGBIGNUM) {
+ /* The messy one. Take the stuff in the buffer and copy it to
+ * the new buffer, adding one to it. This might be one byte
+ * bigger than the original because of the carry from adding
+ * one.*/
+ *pbIsNegative = true;
+ *pBigNumber = QCBORDecode_BigNumberCopyPlusOne(BigNumber, BigNumberBuf);
+ }
+
+ return QCBOR_SUCCESS;
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+QCBORError
+QCBORDecode_ProcessBigNumber(const QCBORItem Item,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORError uResult;
+ size_t uLen;
+ int uType;
+
+ uType = Item.uDataType;
+
+ switch(uType) {
+ case QCBOR_TYPE_POSBIGNUM:
+ case QCBOR_TYPE_NEGBIGNUM:
+ case QCBOR_TYPE_BYTE_STRING:
+ return QCBORDecode_ProcessBigNumberNoPreferred(Item, BigNumberBuf, pBigNumber, pbIsNegative);
+ break;
+
+ case QCBOR_TYPE_INT64:
+ uLen = QCBORDecode_Private_CountNonZeroBytes((uint64_t)ABSOLUTE_VALUE(Item.val.int64));
+ break;
+
+ case QCBOR_TYPE_UINT64:
+ uLen = QCBORDecode_Private_CountNonZeroBytes(Item.val.uint64);
+ break;
+
+ case QCBOR_TYPE_65BIT_NEG_INT:
+ uLen = Item.val.uint64 == UINT64_MAX ? 9 : QCBORDecode_Private_CountNonZeroBytes(Item.val.uint64);
+ break;
+
+ default:
+ return QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+
+ *pBigNumber = (UsefulBufC){NULL, uLen};
+
+ if(BigNumberBuf.len < uLen || uLen == 0 || BigNumberBuf.ptr == NULL) {
+ return BigNumberBuf.ptr == NULL ? QCBOR_SUCCESS : QCBOR_ERR_BUFFER_TOO_SMALL;
+ /* Buffer is too short or type is wrong */
+ }
+
+ uResult = QCBOR_SUCCESS;
+
+ if(uType == QCBOR_TYPE_UINT64) {
+ *pBigNumber = QCBORDecode_Private_UIntToBigNumber(Item.val.uint64, BigNumberBuf);
+ *pbIsNegative = false;
+ } else if(uType == QCBOR_TYPE_INT64) {
+ /* Offset of 1 for negative numbers already performed */
+ *pbIsNegative = Item.val.int64 < 0;
+ *pBigNumber = QCBORDecode_Private_UIntToBigNumber((uint64_t)(*pbIsNegative ? -Item.val.int64 : Item.val.int64), BigNumberBuf);
+ } else if(uType == QCBOR_TYPE_65BIT_NEG_INT) {
+ /* Offset of 1 for negative numbers NOT already performed */
+ *pbIsNegative = true;
+ if(Item.val.uint64 == UINT64_MAX) {
+ /* The one value that can't be done with a computation
+ * because it would overflow a uint64_t */
+ static const uint8_t TwoToThe64[] = {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ *pBigNumber = UsefulBuf_Copy(BigNumberBuf, UsefulBuf_FROM_BYTE_ARRAY_LITERAL(TwoToThe64));
+ } else {
+ /* +1 because negative big numbers are encoded one less than actual */
+ *pBigNumber = QCBORDecode_Private_UIntToBigNumber(Item.val.uint64 + 1, BigNumberBuf);
+ }
+ }
+
+ return uResult;
+}
+
+
+
+static const uint64_t QCBORDecode_Private_BigNumberTagNumbers[] = {
+ CBOR_TAG_POS_BIGNUM,
+ CBOR_TAG_NEG_BIGNUM,
+ CBOR_TAG_INVALID64};
+
+static const uint8_t QCBORDecode_Private_BigNumberTypes[] = {
+ QCBOR_TYPE_INT64,
+ QCBOR_TYPE_UINT64,
+ QCBOR_TYPE_65BIT_NEG_INT,
+ QCBOR_TYPE_POSBIGNUM,
+ QCBOR_TYPE_NEGBIGNUM,
+ QCBOR_TYPE_NONE};
+
+#define QCBORDecode_Private_BigNumberTypesNoPreferred &QCBORDecode_Private_BigNumberTypes[3]
+
+/**
+ * @brief Common processing for a big number tag.
+ *
+ * @param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
+ * @param[in] pItem The item with the date.
+ * @param[out] pBignumber The returned big number
+ * @param[out] pbIsNegative The returned sign of the big number.
+ *
+ * Common processing for the big number tag. Mostly make sure
+ * the tag content is correct and copy forward any further other tag
+ * numbers.
+ */
+static void
+QCBORDecode_Private_BigNumberRawMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ QCBORItem *pItem,
+ UsefulBufC *pBignumber,
+ bool *pbIsNegative,
+ size_t uOffset)
+{
+ QCBORDecode_Private_ProcessTagItemMulti(pMe,
+ pItem,
+ uTagRequirement,
+ QCBORDecode_Private_BigNumberTypesNoPreferred,
+ QCBORDecode_Private_BigNumberTagNumbers,
+ QCBORDecode_StringsTagCB,
+ uOffset);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ if(pItem->uDataType == QCBOR_TYPE_POSBIGNUM) {
+ *pbIsNegative = false;
+ } else if(pItem->uDataType == QCBOR_TYPE_NEGBIGNUM) {
+ *pbIsNegative = true;
+ }
+ *pBignumber = pItem->val.bigNum;
+}
+
+
+static void
+QCBORDecode_Private_BigNumberNoPreferredMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ QCBORItem *pItem,
+ const size_t uOffset,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORDecode_Private_ProcessTagItemMulti(pMe,
+ pItem,
+ uTagRequirement,
+ QCBORDecode_Private_BigNumberTypesNoPreferred,
+ QCBORDecode_Private_BigNumberTagNumbers,
+ QCBORDecode_StringsTagCB,
+ uOffset);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBORDecode_ProcessBigNumberNoPreferred(*pItem, BigNumberBuf, pBigNumber, pbIsNegative);
+}
+
+
+static void
+QCBORDecode_Private_BigNumberMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ QCBORItem *pItem,
+ const size_t uOffset,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORDecode_Private_ProcessTagItemMulti(pMe,
+ pItem,
+ uTagRequirement,
+ QCBORDecode_Private_BigNumberTypes,
+ QCBORDecode_Private_BigNumberTagNumbers,
+ QCBORDecode_StringsTagCB,
+ uOffset);
+ if(pMe->uLastError) {
+ return;
+ }
+
+ pMe->uLastError = (uint8_t)QCBORDecode_ProcessBigNumber(*pItem, BigNumberBuf, pBigNumber, pbIsNegative);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumber(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberMain(pMe,
+ uTagRequirement,
+ &Item,
+ uOffset,
+ BigNumberBuf,
+ pBigNumber,
+ pbIsNegative);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberMain(pMe,
+ uTagRequirement,
+ &Item,
+ uOffset,
+ BigNumberBuf,
+ pBigNumber,
+ pbIsNegative);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberNoPreferred(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberNoPreferredInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberNoPreferredInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ UsefulBuf BigNumberBuf,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberNoPreferredMain(pMe, uTagRequirement, &Item, uOffset, BigNumberBuf, pBigNumber, pbIsNegative);
+}
+
+
+
+/*
+ * Public function, see header qcbor/qcbor_spiffy_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberRaw(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBignumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberRawMain(pMe,
+ uTagRequirement,
+ &Item,
+ pBignumber,
+ pbIsNegative,
+ uOffset);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_spiffy_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberRawInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberRawMain(pMe,
+ uTagRequirement,
+ &Item,
+ pBigNumber,
+ pbIsNegative,
+ uOffset);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_spiffy_decode.h
+ */
+void
+QCBORDecode_GetTBigNumberRawInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ UsefulBufC *pBigNumber,
+ bool *pbIsNegative)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_BigNumberRawMain(pMe,
+ uTagRequirement,
+ &Item,
+ pBigNumber,
+ pbIsNegative,
+ uOffset);
+}
+
+
+
+
+#ifndef QCBOR_DISABLE_EXP_AND_MANTISSA
+
+
+// TODO: relocate these notes?
+/* Some notes from the work to disable tags.
+ * Some are out of date since tag refactoring.
+ *
+ * The API for big floats and decimal fractions seems good.
+ * If there's any issue with it it's that the code size to
+ * implement is a bit large because of the conversion
+ * to/from int and bignum that is required. There is no API
+ * that doesn't do the conversion so dead stripping will never
+ * leave that code out.
+ *
+ * The implementation itself seems correct, but not as clean
+ * and neat as it could be. It could probably be smaller too.
+ *
+ * The implementation has three main parts / functions
+ * - The decoding of the array of two
+ * - All the tag and type checking for the various API functions
+ * - Conversion to/from bignum and int
+ *
+ * The type checking seems like it wastes the most code for
+ * what it needs to do.
+ *
+ * The inlining for the conversion is probably making the
+ * overall code base larger.
+ *
+ * The tests cases could be organized a lot better and be
+ * more thorough.
+ *
+ * Seems also like there could be more common code in the
+ * first tier part of the public API. Some functions only
+ * vary by a TagSpec.
+ */
+
+
+static const uint8_t QCBORDecode_Private_DecimalFractionTypes[] = {
+ QCBOR_TYPE_DECIMAL_FRACTION,
+ QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM,
+ QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM,
+ QCBOR_TYPE_DECIMAL_FRACTION_POS_U64,
+ QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64,
+ QCBOR_TYPE_NONE};
+
+static const uint8_t QCBORDecode_Private_BigFloatTypes[] = {
+ QCBOR_TYPE_BIGFLOAT,
+ QCBOR_TYPE_BIGFLOAT_POS_BIGNUM,
+ QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM,
+ QCBOR_TYPE_BIGFLOAT_POS_U64,
+ QCBOR_TYPE_BIGFLOAT_NEG_U64,
+ QCBOR_TYPE_NONE};
+
+/**
+ * @brief Common processor for exponent and int64_t mantissa.
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] uTagRequirement Whether tag number must be present or not.
+ * @param[in] uTagNumber The tag number for which content is expected.
+ * @param[in] uOffset Cursor offset for tag number consumption checking.
+ * @param[in] pItem The data item to process.
+ * @param[out] pnMantissa The returned mantissa as an int64_t.
+ * @param[out] pnExponent The returned exponent as an int64_t.
+ *
+ * This handles exponent and mantissa for base 2 and 10. This
+ * is limited to a mantissa that is an int64_t. See also
+ * QCBORDecode_Private_ProcessExpMantissaBig().
+ *
+ * On output, the item is always a fully decoded decimal fraction or
+ * big float.
+ *
+ * This errors out if the input tag and type aren't as required.
+ *
+ * This always provides the correctly offset mantissa, even when the
+ * input CBOR is a negative big number. This works the
+ * same in QCBOR v1 and v2.
+ */
+static void
+QCBORDecode_Private_ExpIntMantissaMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const uint64_t uTagNumber,
+ const size_t uOffset,
+ QCBORItem *pItem,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORError uErr;
+ const uint8_t *qTypes;
+
+ if(pMe->uLastError) {
+ return;
+ }
+
+ if(uTagNumber == CBOR_TAG_BIGFLOAT) {
+ qTypes = QCBORDecode_Private_BigFloatTypes;
+ } else {
+ qTypes = QCBORDecode_Private_DecimalFractionTypes;
+ }
+
+ QCBORDecode_Private_ProcessTagItem(pMe,
+ pItem,
+ uTagRequirement,
+ qTypes,
+ uTagNumber,
+ QCBORDecode_ExpMantissaTagCB,
+ uOffset);
+
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ uErr = QCBOR_SUCCESS;
+ switch (pItem->uDataType) {
+
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ case QCBOR_TYPE_BIGFLOAT:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ *pnMantissa = pItem->val.expAndMantissa.Mantissa.nInt;
+ break;
+
+#ifndef QCBOR_DISABLE_TAGS
+ /* If tags are disabled, mantissas can never be big nums */
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ uErr = QCBORDecode_Private_PositiveBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ uErr = QCBORDecode_Private_NegativeBigNumberToInt(pItem->val.expAndMantissa.Mantissa.bigNum, pnMantissa);
+ break;
+#endif /* ! QCBOR_DISABLE_TAGS */
+
+ case QCBOR_TYPE_BIGFLOAT_NEG_U64:
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
+ case QCBOR_TYPE_BIGFLOAT_POS_U64:
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
+ uErr = QCBOR_ERR_CONVERSION_UNDER_OVER_FLOW;
+ break;
+
+ default:
+ uErr = QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ pMe->uLastError = (uint8_t)uErr;
+}
+
+static void
+QCBORDecode_Private_ExpBigMantissaRawMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const uint64_t uTagNumber,
+ const size_t uOffset,
+ QCBORItem *pItem,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORError uErr;
+ uint64_t uMantissa;
+ const uint8_t *qTypes;
+
+ if(pMe->uLastError) {
+ return;
+ }
+
+ if(uTagNumber == CBOR_TAG_BIGFLOAT) {
+ qTypes = QCBORDecode_Private_BigFloatTypes;
+ } else {
+ qTypes = QCBORDecode_Private_DecimalFractionTypes;
+ }
+
+ QCBORDecode_Private_ProcessTagItem(pMe,
+ pItem,
+ uTagRequirement,
+ qTypes,
+ uTagNumber,
+ QCBORDecode_ExpMantissaTagCB,
+ uOffset);
+
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ uErr = QCBOR_SUCCESS;
+
+ switch (pItem->uDataType) {
+
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ case QCBOR_TYPE_BIGFLOAT:
+ if(pItem->val.expAndMantissa.Mantissa.nInt >= 0) {
+ uMantissa = (uint64_t)pItem->val.expAndMantissa.Mantissa.nInt;
+ *pbIsNegative = false;
+ } else {
+ if(pItem->val.expAndMantissa.Mantissa.nInt != INT64_MIN) {
+ uMantissa = (uint64_t)-pItem->val.expAndMantissa.Mantissa.nInt;
+ } else {
+ /* Can't negate like above when int64_t is INT64_MIN because it
+ * will overflow. See ExponentNN() */
+ uMantissa = (uint64_t)INT64_MAX+1;
+ }
+ *pbIsNegative = true;
+ }
+ /* Reverse the offset by 1 for type 1 negative value to be consistent
+ * with big num case below which don't offset because it requires
+ * big number arithmetic. This is a bug fix for QCBOR v1.5.
+ */
+ uMantissa--;
+ *pMantissa = QCBORDecode_Private_UIntToBigNumber(uMantissa, BufferForMantissa);
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ break;
+
+#ifndef QCBOR_DISABLE_TAGS
+ /* If tags are disabled, mantissas can never be big nums */
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = false;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ *pMantissa = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = true;
+ break;
+#endif /* ! QCBOR_DISABLE_TAGS */
+
+ default:
+ uErr = QCBOR_ERR_UNEXPECTED_TYPE;
+ }
+
+ pMe->uLastError = (uint8_t)uErr;
+}
+
+
+/**
+ * @brief Decode exponent and mantissa into a big number with negative offset of 1.
+ *
+ * @param[in] pMe The decode context.
+ * @param[in] uTagRequirement Whether a tag number must be present or not.
+ * @param[in] pItem Item to decode and convert.
+ * @param[in] BufferForMantissa Buffer to output mantissa into.
+ * @param[out] pMantissa The output mantissa.
+ * @param[out] pbIsNegative The sign of the output.
+ * @param[out] pnExponent The mantissa of the output.
+ *
+ * This is the common processing of a decimal fraction or a big float
+ * into a big number. This will decode and consume all the CBOR items
+ * that make up the decimal fraction or big float.
+ *
+ * This performs the subtraction of 1 from the negative value so the
+ * caller doesn't need to. This links more object code than QCBORDecode_Private_ProcessExpMantissaBig().
+ */
+static void
+QCBORDecode_Private_ExpBigMantissaMain(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const uint64_t uTagNumber,
+ const size_t uOffset,
+ QCBORItem *pItem,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORError uErr;
+ QCBORItem TempMantissa;
+ const uint8_t *qTypes;
+
+ if(pMe->uLastError) {
+ return;
+ }
+
+ if(uTagNumber == CBOR_TAG_BIGFLOAT) {
+ qTypes = QCBORDecode_Private_BigFloatTypes;
+ } else {
+ qTypes = QCBORDecode_Private_DecimalFractionTypes;
+ }
+
+ QCBORDecode_Private_ProcessTagItem(pMe,
+ pItem,
+ uTagRequirement,
+ qTypes,
+ uTagNumber,
+ QCBORDecode_ExpMantissaTagCB,
+ uOffset);
+
+ if(pMe->uLastError != QCBOR_SUCCESS) {
+ return;
+ }
+
+ memset(&TempMantissa, 0, sizeof(TempMantissa));
+
+ switch (pItem->uDataType) {
+
+ case QCBOR_TYPE_DECIMAL_FRACTION:
+ case QCBOR_TYPE_BIGFLOAT:
+ TempMantissa.uDataType = QCBOR_TYPE_INT64;
+ TempMantissa.val.int64 = pItem->val.expAndMantissa.Mantissa.nInt;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_U64:
+ case QCBOR_TYPE_BIGFLOAT_POS_U64:
+ TempMantissa.uDataType = QCBOR_TYPE_UINT64;
+ TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_U64:
+ case QCBOR_TYPE_BIGFLOAT_NEG_U64:
+ TempMantissa.uDataType = QCBOR_TYPE_65BIT_NEG_INT;
+ TempMantissa.val.uint64 = pItem->val.expAndMantissa.Mantissa.uInt;
+ break;
+
+#ifndef QCBOR_DISABLE_TAGS
+ /* If tags are disabled, mantissas can never be big nums */
+ case QCBOR_TYPE_DECIMAL_FRACTION_POS_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_POS_BIGNUM:
+ TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
+ TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = false;
+ break;
+
+ case QCBOR_TYPE_DECIMAL_FRACTION_NEG_BIGNUM:
+ case QCBOR_TYPE_BIGFLOAT_NEG_BIGNUM:
+ TempMantissa.uDataType = QCBOR_TYPE_BYTE_STRING;
+ TempMantissa.val.bigNum = pItem->val.expAndMantissa.Mantissa.bigNum;
+ *pbIsNegative = true;
+ break;
+#endif /* ! QCBOR_DISABLE_TAGS */
+ }
+
+ *pnExponent = pItem->val.expAndMantissa.nExponent;
+ uErr = QCBORDecode_ProcessBigNumber(TempMantissa, BufferForMantissa, pMantissa, pbIsNegative);
+
+ pMe->uLastError = (uint8_t)uErr;
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFraction(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissa(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRaw(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRawInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTDecimalFractionBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_DECIMAL_FRACTION,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloat(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ int64_t *pnMantissa,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpIntMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ pnMantissa,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissa(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaRaw(QCBORDecodeContext *pMe,
+ const uint8_t uTagRequirement,
+ const UsefulBuf MantissaBuffer,
+ UsefulBufC *pMantissa,
+ bool *pbMantissaIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetAndTell(pMe, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ MantissaBuffer,
+ pMantissa,
+ pbMantissaIsNegative,
+ pnExponent);
+}
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaRawInMapN(QCBORDecodeContext *pMe,
+ const int64_t nLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckN(pMe, nLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+
+/*
+ * Public function, see header qcbor/qcbor_decode.h file
+ */
+void
+QCBORDecode_GetTBigFloatBigMantissaRawInMapSZ(QCBORDecodeContext *pMe,
+ const char *szLabel,
+ const uint8_t uTagRequirement,
+ const UsefulBuf BufferForMantissa,
+ UsefulBufC *pMantissa,
+ bool *pbIsNegative,
+ int64_t *pnExponent)
+{
+ QCBORItem Item;
+ size_t uOffset;
+
+ QCBORDecode_Private_GetItemInMapNoCheckSZ(pMe, szLabel, QCBOR_TYPE_ANY, &Item, &uOffset);
+ QCBORDecode_Private_ExpBigMantissaRawMain(pMe,
+ uTagRequirement,
+ CBOR_TAG_BIGFLOAT,
+ uOffset,
+ &Item,
+ BufferForMantissa,
+ pMantissa,
+ pbIsNegative,
+ pnExponent);
+}
+
+#endif /* ! QCBOR_DISABLE_EXP_AND_MANTISSA */
diff --git a/src/qcbor_tag_decode.c b/src/qcbor_tag_decode.c
index 33e8dba..31f9c03 100644
--- a/src/qcbor_tag_decode.c
+++ b/src/qcbor_tag_decode.c
@@ -7,9 +7,11 @@
*
* See BSD-3-Clause license in README.md
*
- * Created on 9/5/24
+ * Created on 9/5/24 from qcbode_decode.c
* ========================================================================== */
+// TODO: qcbor_tag_decode.c or tag_decode.c
+
#include "qcbor/qcbor_tag_decode.h"
#include <math.h> /* For isnan() */
diff --git a/test/float_tests.c b/test/float_tests.c
index 98ebc3d..294be55 100644
--- a/test/float_tests.c
+++ b/test/float_tests.c
@@ -16,6 +16,7 @@
#include "qcbor/qcbor_encode.h"
#include "qcbor/qcbor_decode.h"
#include "qcbor/qcbor_spiffy_decode.h"
+#include "qcbor/qcbor_number_decode.h"
#include <math.h> /* For INFINITY and NAN and isnan() */
diff --git a/test/qcbor_decode_tests.c b/test/qcbor_decode_tests.c
index 0fabc4f..99d2643 100644
--- a/test/qcbor_decode_tests.c
+++ b/test/qcbor_decode_tests.c
@@ -35,6 +35,7 @@
#include "qcbor/qcbor_encode.h"
#include "qcbor/qcbor_decode.h"
#include "qcbor/qcbor_spiffy_decode.h"
+#include "qcbor/qcbor_number_decode.h"
#include "qcbor/qcbor_tag_decode.h"
#include <string.h>
#include <math.h> // for fabs()