Big commit of fixes for tags
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index 19dc22b..b5492be 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -219,6 +219,11 @@
array, map or other.
@anchor Tags-Overview
+
+
+
+
+
Any CBOR data item can be tagged to add semantics, define a new data
type or such. Some tags are fully standardized and some are just
registered. Others are not registered and used in a proprietary way.
@@ -346,6 +351,16 @@
#define QCBOR_HEAD_BUFFER_SIZE (sizeof(uint64_t) + 2)
+/**
+ Output the full CBOR tag. See @Tags-Overview.
+ */
+#define QCBOR_ENCODE_AS_TAG 0
+
+/**
+ Output only the 'borrowed' content format for the relevant tag. See @Tags-Overview.
+ */
+#define QCBOR_ENCODE_AS_BORROWED 1
+
/**
QCBOREncodeContext is the data type that holds context for all the
@@ -634,6 +649,7 @@
@brief Add an epoch-based date.
@param[in] pCtx The encoding context to add the date to.
+ @param[in] uTag Either @ref QCBOR_ENCODE_AS_TAG or @ref QCBOR_ENCODE_AS_BORROWED.
@param[in] date Number of seconds since 1970-01-01T00:00Z in UTC time.
As per RFC 7049 this is similar to UNIX/Linux/POSIX dates. This is
@@ -659,6 +675,13 @@
Error handling is the same as QCBOREncode_AddInt64().
*/
+static void QCBOREncode_AddTDateEpoch(QCBOREncodeContext *pCtx, uint8_t uTag, int64_t date);
+
+static void QCBOREncode_AddTDateEpochToMap(QCBOREncodeContext *pCtx, const char *szLabel, uint8_t uTag, int64_t date);
+
+static void QCBOREncode_AddTDateEpochToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, uint8_t uTag, int64_t date);
+
+
static void QCBOREncode_AddDateEpoch(QCBOREncodeContext *pCtx, int64_t date);
static void QCBOREncode_AddDateEpochToMap(QCBOREncodeContext *pCtx, const char *szLabel, int64_t date);
@@ -1746,27 +1769,46 @@
}
+
+static inline void QCBOREncode_AddTDateEpoch(QCBOREncodeContext *pCtx, uint8_t uTag, int64_t date)
+{
+ if(uTag == QCBOR_ENCODE_AS_TAG) {
+ QCBOREncode_AddTag(pCtx, CBOR_TAG_DATE_EPOCH);
+ }
+ QCBOREncode_AddInt64(pCtx, date);
+}
+
+static inline void QCBOREncode_AddTDateEpochToMap(QCBOREncodeContext *pCtx, const char *szLabel, uint8_t uTag, int64_t date)
+{
+ QCBOREncode_AddSZString(pCtx, szLabel);
+ QCBOREncode_AddTDateEpoch(pCtx, uTag, date);
+}
+
+static inline void QCBOREncode_AddTDateEpochToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, uint8_t uTag, int64_t date)
+{
+ QCBOREncode_AddInt64(pCtx, nLabel);
+ QCBOREncode_AddTDateEpoch(pCtx, uTag, date);
+}
+
static inline void QCBOREncode_AddDateEpoch(QCBOREncodeContext *pCtx, int64_t date)
{
- QCBOREncode_AddTag(pCtx, CBOR_TAG_DATE_EPOCH);
- QCBOREncode_AddInt64(pCtx, date);
+ QCBOREncode_AddTDateEpoch(pCtx, QCBOR_ENCODE_AS_TAG, date);
}
static inline void QCBOREncode_AddDateEpochToMap(QCBOREncodeContext *pCtx, const char *szLabel, int64_t date)
{
QCBOREncode_AddSZString(pCtx, szLabel);
- QCBOREncode_AddTag(pCtx, CBOR_TAG_DATE_EPOCH);
- QCBOREncode_AddInt64(pCtx, date);
+ QCBOREncode_AddDateEpoch(pCtx, date);
}
static inline void QCBOREncode_AddDateEpochToMapN(QCBOREncodeContext *pCtx, int64_t nLabel, int64_t date)
{
QCBOREncode_AddInt64(pCtx, nLabel);
- QCBOREncode_AddTag(pCtx, CBOR_TAG_DATE_EPOCH);
- QCBOREncode_AddInt64(pCtx, date);
+ QCBOREncode_AddDateEpoch(pCtx, date);
}
+
static inline void QCBOREncode_AddBytes(QCBOREncodeContext *pCtx, UsefulBufC Bytes)
{
QCBOREncode_AddBuffer(pCtx, CBOR_MAJOR_TYPE_BYTE_STRING, Bytes);