cn-create: add cn_cbor_float_create
diff --git a/include/cn-cbor/cn-cbor.h b/include/cn-cbor/cn-cbor.h
index cde9dfc..187a55c 100644
--- a/include/cn-cbor/cn-cbor.h
+++ b/include/cn-cbor/cn-cbor.h
@@ -53,6 +53,8 @@
CN_CBOR_SIMPLE,
/** Doubles, floats, and half-floats */
CN_CBOR_DOUBLE,
+ /** Floats, and half-floats */
+ CN_CBOR_FLOAT,
/** An error has occurred */
CN_CBOR_INVALID
} cn_cbor_type;
@@ -92,6 +94,8 @@
unsigned long uint;
/** CN_CBOR_DOUBLE */
double dbl;
+ /** CN_CBOR_FLOAT */
+ float f;
/** for use during parsing */
unsigned long count;
} v; /* TBD: optimize immediate */
@@ -327,6 +331,18 @@
#ifndef CBOR_NO_FLOAT
/**
+ * Create a CBOR float.
+ *
+ * @param[in] value the value of the float
+ * @param[in] CBOR_CONTEXT Allocation context (only if USE_CBOR_CONTEXT is defined)
+ * @param[out] errp Error, if NULL is returned
+ * @return The created object, or NULL on error
+ */
+cn_cbor* cn_cbor_float_create(float value
+ CBOR_CONTEXT,
+ cn_cbor_errback *errp);
+
+/**
* Create a CBOR double.
*
* @param[in] value the value of the double
diff --git a/src/cn-create.c b/src/cn-create.c
index 84a6ee9..4ddce3b 100644
--- a/src/cn-create.c
+++ b/src/cn-create.c
@@ -74,6 +74,19 @@
}
#ifndef CBOR_NO_FLOAT
+cn_cbor* cn_cbor_float_create(float value
+ CBOR_CONTEXT,
+ cn_cbor_errback *errp)
+{
+ cn_cbor* ret;
+ INIT_CB(ret);
+
+ ret->type = CN_CBOR_FLOAT;
+ ret->v.f = value;
+
+ return ret;
+}
+
cn_cbor* cn_cbor_double_create(double value
CBOR_CONTEXT,
cn_cbor_errback *errp)
diff --git a/src/cn-encoder.c b/src/cn-encoder.c
index 8593b39..d8a4d49 100644
--- a/src/cn-encoder.c
+++ b/src/cn-encoder.c
@@ -276,6 +276,11 @@
CHECK(_write_double(ws, cb->v.dbl));
#endif /* CBOR_NO_FLOAT */
break;
+ case CN_CBOR_FLOAT:
+#ifndef CBOR_NO_FLOAT
+ CHECK(_write_double(ws, cb->v.f));
+#endif /* CBOR_NO_FLOAT */
+ break;
case CN_CBOR_INVALID:
ws->offset = -1;