Finalize testing of dates; some date bug fixes
diff --git a/inc/qcbor/qcbor_common.h b/inc/qcbor/qcbor_common.h
index 137906a..7a7a132 100644
--- a/inc/qcbor/qcbor_common.h
+++ b/inc/qcbor/qcbor_common.h
@@ -215,11 +215,12 @@
/** The encode or decode completely correctly. */
QCBOR_SUCCESS = 0,
+#define QCBOR_ERR_FIRST_NOT_WELL_FORMED 1 /* QCBOR_ERR_BAD_TYPE_7 */
+
/** During decoding, the CBOR is not valid, primarily a simple type
is encoded in a prohibited way. */
QCBOR_ERR_BAD_TYPE_7 = 1,
-#define QCBOR_ERR_FIRST_NOT_WELL_FORMED QCBOR_ERR_BAD_TYPE_7
/** Returned by QCBORDecode_Finish() if all the inputs bytes have
not been consumed. */
diff --git a/inc/qcbor/qcbor_decode.h b/inc/qcbor/qcbor_decode.h
index bbcf2cd..be6bc1a 100644
--- a/inc/qcbor/qcbor_decode.h
+++ b/inc/qcbor/qcbor_decode.h
@@ -340,7 +340,7 @@
float fnum;
/** The value for @c uDataType @ref QCBOR_TYPE_DATE_EPOCH.
Floating-point dates that are NaN, +Inifinity or -Inifinity
- decode with the @ref QCBOR_ERR_DATE_OVERFLOW error. */
+ result in the @ref QCBOR_ERR_DATE_OVERFLOW error. */
struct {
int64_t nSeconds;
double fSecondsFraction;
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index adda824..19dc22b 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -265,26 +265,25 @@
representation of the double or float that preserves precision. Zero,
NaN and infinity are always output as a half-precision, each taking
just 2 bytes. This reduces the number of bytes needed to encode
- doubles and floats, especially if the zero, NaN and infinity are
+ double and single-precision, especially if zero, NaN and infinity are
frequently used.
- To avoid use of preferred serialization in the standard configuration when encoding, use
- QCBOREncode_AddDoubleNoPreferred() or
+ To avoid use of preferred serialization in the standard configuration
+ when encoding, use QCBOREncode_AddDoubleNoPreferred() or
QCBOREncode_AddFloatNoPreferred().
This implementation of preferred floating-point serialization and
half-precision does not depend on the CPU having floating-point HW or
the compiler bringing in a (sometimes large) library to compensate
- for lack of CPU support. The implementation uses shifts and masks
- rather than floating-point functions. It does however add object
- code.
+ for lack of CPU support. This implementation uses shifts and masks
+ rather than floating-point functions.
- To reduce object code, define QCBOR_DISABLE_PREFERRED_FLOAT. This
- will eliminate all support for preferred serialization and
- half-precision. An error will be returned when attempting to decode
- half-precision. A float will always be encoded and decoded as 32-bits
- and a double will always be encoded and decoded as 64 bits. This
- will reduce object code by about 900 bytes.
+ To reduce overall object code by about 900 bytes, define
+ QCBOR_DISABLE_PREFERRED_FLOAT. This will eliminate all support for
+ preferred serialization and half-precision. An error will be returned
+ when attempting to decode half-precision. A float will always be
+ encoded and decoded as 32-bits and a double will always be encoded
+ and decoded as 64 bits.
Note that even if QCBOR_DISABLE_PREFERRED_FLOAT is not defined all
the float-point encoding object code can be avoided by never calling
@@ -294,21 +293,20 @@
On CPUs that have no floating-point hardware,
QCBOR_DISABLE_FLOAT_HW_USE should be defined in most cases. If it is
not, then the compiler will bring in possibly large software
- libraries to compensate or QCBOR will not compile. Defining
+ libraries to compensate. Defining
QCBOR_DISABLE_FLOAT_HW_USE reduces object code size on CPUs with
- floating-point hardware by a tiny amount.
+ floating-point hardware by a tiny amount and eliminates the need for <math.h>
- When QCBOR_DISABLE_FLOAT_HW_USE is defined, trying to
- decoding floating point dates will give error @ref QCBOR_ERR_FLOAT_DATE_DISABLED and decoded
- single-precision
- numbers will be returned as @ref QCBOR_TYPE_FLOAT instead of converting them to
- double as usual.
-
+ When QCBOR_DISABLE_FLOAT_HW_USE is defined, trying to decoding
+ floating-point dates will give error @ref
+ QCBOR_ERR_FLOAT_DATE_DISABLED and decoded single-precision numbers
+ will be returned as @ref QCBOR_TYPE_FLOAT instead of converting them
+ to double as usual.
If both QCBOR_DISABLE_FLOAT_HW_USE and QCBOR_DISABLE_PREFERRED_FLOAT
- are defined, then the only thing QCBOR can do is encode/decode a
- C float type as 32-bits and a C double type as 64-bits. Floating-point epoch dates
- will be unsupported.
+ are defined, then the only thing QCBOR can do is encode/decode a C
+ float type as 32-bits and a C double type as 64-bits. Floating-point
+ epoch dates will be unsupported.
Summary Limits of this implementation:
- The entire encoded CBOR must fit into contiguous memory.
diff --git a/inc/qcbor/qcbor_spiffy_decode.h b/inc/qcbor/qcbor_spiffy_decode.h
index 2b4ded7..449a28e 100644
--- a/inc/qcbor/qcbor_spiffy_decode.h
+++ b/inc/qcbor/qcbor_spiffy_decode.h
@@ -85,9 +85,7 @@
cleaner decoding code. In some cases the only error check that may be
necessary is the return code from QCBORDecode_Finish().
- The only error check needed is in the Finish call.
-
- On error, a decoder internal error state is set. The error can be
+ The internal error can be
retrived with QCBORDecode_GetError(). Any further attempts to get
specific data types will do nothing so it is safe for code to get
many items without checking the error on each one as long as there is
@@ -108,6 +106,10 @@
another. In such designs, GetNext has to be used and the internal
error checking can't be relied upon.
+ Error reporting when searching maps is not accurate for
+ some errors. They are report as not found rather
+ than overflow and such.
+
----
GetNext will always try to get something. The other Get functions
@@ -643,17 +645,25 @@
@param[in] uTagRequirement One of @c QCBOR_TAG_REQUIREMENT_XXX.
@param[out] pnTime The decoded epoch date.
- This will handle floating-point dates, but always returns them as an int64_t
+ This will handle floating-point dates, but always returns them as an @c int64_t
discarding the fractional part. Use QCBORDecode_GetNext() instead of this to get the
fractional part.
+ Floating-point dates that are plus infinity, minus infinity or NaN (not-a-number) will
+ result in the @ref QCBOR_ERR_DATE_OVERFLOW error. If the QCBOR library
+ is compiled with floating-point disabled, @ref QCBOR_ERR_HW_FLOAT_DISABLED
+ is set. If compiled with preferred float disabled, half-precision dates will result
+ in the @ref QCBOR_ERR_HALF_PRECISION_DISABLED error.
+
See @ref Decode-Errors for discussion on how error handling works.
See @ref Tag-Matcing for discussion on tag requirements.
+
+ See also QCBOREncode_AddDateEpoch() and @ref QCBORItem.
*/
void QCBORDecode_GetEpochDate(QCBORDecodeContext *pCtx,
- uint8_t uTagRequirement,
- int64_t *pnTime);
+ uint8_t uTagRequirement,
+ int64_t *pnTime);
void QCBORDecode_GetEpochDateInMapN(QCBORDecodeContext *pCtx,
int64_t nLabel,
@@ -1077,43 +1087,42 @@
The next item in the CBOR input must be map or this sets an error.
- This puts the decoder in bounded mode which narrows
- decoding to the map entered and enables
- getting items by label. Note that all items
- in the map must be well-formed and valid to be
- able to search it by label because a full traversal
- is done for each search. If not, the search will
- retun an error for the item that is not well-formed
- and valid. This may not be the item with the label
- that is the subject of the search.
+ This puts the decoder in bounded mode which narrows decoding to the
+ map entered and enables getting items by label.
- Nested maps can be decoded like this by entering
- each map in turn.
+ All items in the map must be well-formed to be able to search it by
+ label because a full traversal is done for each search. If not, the
+ search will retun an error for the item that is not well-formed.
+ This will be the first non-well-formed item which may not be the item
+ with the label that is the target of the search.
- Call QCBORDecode_ExitMap() to exit the current map
- decoding level. When all map decoding layers are exited
- then bounded mode is fully exited.
+ Nested maps can be decoded like this by entering each map in turn.
+
+ Call QCBORDecode_ExitMap() to exit the current map decoding
+ level. When all map decoding layers are exited then bounded mode is
+ fully exited.
While in bounded mode, QCBORDecode_GetNext() works as usual on the
- map and the in-order traversal cursor
- is maintained. It starts out at the first item in the map just entered. Attempts to get items off the end of the
- map will give error @ref QCBOR_ERR_NO_MORE_ITEMS rather going to the next
- item after the map as it would when not in bounded
+ map and the in-order traversal cursor is maintained. It starts out at
+ the first item in the map just entered. Attempts to get items off the
+ end of the map will give error @ref QCBOR_ERR_NO_MORE_ITEMS rather
+ going to the next item after the map as it would when not in bounded
mode.
- Exiting leaves the pre-order cursor at the
- data item following the last entry in the map or at the end of the input CBOR if there nothing after the map.
+ Exiting leaves the pre-order cursor at the data item following the
+ last entry in the map or at the end of the input CBOR if there
+ nothing after the map.
- Entering and Exiting a map is a way to skip over
- an entire map and its contents. After QCBORDecode_ExitMap(),
- the pre-order traversal cursor will be at the
- first item after the map.
+ Entering and Exiting a map is a way to skip over an entire map and
+ its contents. After QCBORDecode_ExitMap(), the pre-order traversal
+ cursor will be at the first item after the map.
See @ref Decode-Errors for discussion on how error handling works.
See also QCBORDecode_EnterArray() and QCBORDecode_EnterBstrWrapped().
- Entering and exiting any nested combination of maps, arrays and bstr-wrapped
- CBOR is supported up to the maximum of @ref QCBOR_MAX_ARRAY_NESTING.
+ Entering and exiting any nested combination of maps, arrays and
+ bstr-wrapped CBOR is supported up to the maximum of @ref
+ QCBOR_MAX_ARRAY_NESTING.
*/
static void QCBORDecode_EnterMap(QCBORDecodeContext *pCtx);