save some object code by making AddType7 semi-public
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 08d6a5b..84f3e8a 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -2064,17 +2064,20 @@
@brief Semi-private method to add simple types.
@param[in] pCtx The encoding context to add the simple value to.
- @param[in] uSimple One of CBOR_SIMPLEV_FALSE through _UNDEF
+ @param[in] uSize Minimum encoding size for uNum. Usually 0.
+ @param[in] uNum One of CBOR_SIMPLEV_FALSE through _UNDEF or other.
- CBOR defines encoding for special values "true", "false", "null" and "undef". This
- function can add these values.
+ This is used to add simple types like true and false.
- This function can add simple values that are not defined by CBOR yet. These expansion
+ Call QCBOREncode_AddBool(), QCBOREncode_AddNULL(), QCBOREncode_AddUndef()
+ instead of this.
+
+ This function can add simple values that are not defined by CBOR yet. This expansion
point in CBOR should not be used unless they are standardized.
Error handling is the same as QCBOREncode_AddInt64().
*/
-void QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, uint8_t uSimple);
+void QCBOREncode_AddType7(QCBOREncodeContext *pCtx, size_t uSize, uint64_t uNum);
static void inline QCBOREncode_AddInt64ToMap(QCBOREncodeContext *pCtx, const char *szLabel, int64_t uNum)
@@ -2381,6 +2384,11 @@
}
+static inline void QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, uint64_t uNum)
+{
+ QCBOREncode_AddType7(pCtx, 0, uNum);
+}
+
static inline void QCBOREncode_AddSimpleToMap(QCBOREncodeContext *pCtx, const char *szLabel, uint8_t uSimple)
{
QCBOREncode_AddSZString(pCtx, szLabel);
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index 595f7eb..99eaafd 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -311,29 +311,6 @@
}
-/*
- Internal function for adding floating point and simple
- types to the encoded output.
- */
-static void AppendType7(QCBOREncodeContext *me, size_t uSize, uint64_t uNum)
-{
- if(me->uError == QCBOR_SUCCESS) {
- // This function call takes care of endian swapping for the float / double
- InsertEncodedTypeAndNumber(me,
- CBOR_MAJOR_TYPE_SIMPLE, // The major type for
- // floats and doubles
- uSize, // min size / tells
- // encoder to do it right
- uNum, // Bytes of the floating
- // point number as a uint
- UsefulOutBuf_GetEndPosition(&(me->OutBuf))); // end position for append
-
- me->uError = Nesting_Increment(&(me->nesting), 1);
- }
-}
-
-
-
/*
Public functions for closing arrays and maps. See header qcbor.h
@@ -420,12 +397,29 @@
}
+
+
/*
- Public functions for closing arrays and maps. See header qcbor.h
+ Semi-private function. It is exposed to user of the interface,
+ but they will usually call one of the inline wrappers rather than this.
+
+ See header qcbor.h
*/
-void QCBOREncode_AddSimple(QCBOREncodeContext *pCtx, uint8_t uSimple)
+void QCBOREncode_AddType7(QCBOREncodeContext *me, size_t uSize, uint64_t uNum)
{
- AppendType7(pCtx, 0, uSimple);
+ if(me->uError == QCBOR_SUCCESS) {
+ // This function call takes care of endian swapping for the float / double
+ InsertEncodedTypeAndNumber(me,
+ CBOR_MAJOR_TYPE_SIMPLE, // The major type for
+ // floats and doubles
+ uSize, // min size / tells
+ // encoder to do it right
+ uNum, // Bytes of the floating
+ // point number as a uint
+ UsefulOutBuf_GetEndPosition(&(me->OutBuf))); // end position for append
+
+ me->uError = Nesting_Increment(&(me->nesting), 1);
+ }
}
@@ -436,7 +430,7 @@
{
const IEEE754_union uNum = IEEE754_DoubleToSmallest(dNum);
- AppendType7(me, uNum.uSize, uNum.uValue);
+ QCBOREncode_AddType7(me, uNum.uSize, uNum.uValue);
}