aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Dupont <vincent@otakeys.com>2018-02-22 12:37:20 +0100
committerVincent Dupont <vincent@otakeys.com>2018-02-26 16:26:23 +0100
commit2703d2d101deae1815d26fb26fb676902d27a58e (patch)
tree4816af94e69771da4574a324aa851f600ab351df
parent2693645bdd064332d08f7f5fd33cb79f824edabd (diff)
downloadcn-cbor-2703d2d101deae1815d26fb26fb676902d27a58e.tar.gz
cn-create: add cn_cbor_double_create
-rw-r--r--include/cn-cbor/cn-cbor.h15
-rw-r--r--src/cn-create.c15
2 files changed, 30 insertions, 0 deletions
diff --git a/include/cn-cbor/cn-cbor.h b/include/cn-cbor/cn-cbor.h
index bf71af8..cde9dfc 100644
--- a/include/cn-cbor/cn-cbor.h
+++ b/include/cn-cbor/cn-cbor.h
@@ -1,3 +1,4 @@
+
/**
* \file
* \brief
@@ -324,6 +325,20 @@ cn_cbor* cn_cbor_int_create(int64_t value
CBOR_CONTEXT,
cn_cbor_errback *errp);
+#ifndef CBOR_NO_FLOAT
+/**
+ * Create a CBOR double.
+ *
+ * @param[in] value the value of the double
+ * @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_double_create(double value
+ CBOR_CONTEXT,
+ cn_cbor_errback *errp);
+#endif /* CBOR_NO_FLOAT */
+
/**
* Put a CBOR object into a map with a CBOR object key. Duplicate checks are NOT
* currently performed.
diff --git a/src/cn-create.c b/src/cn-create.c
index bc448e9..84a6ee9 100644
--- a/src/cn-create.c
+++ b/src/cn-create.c
@@ -73,6 +73,21 @@ cn_cbor* cn_cbor_int_create(int64_t value
return ret;
}
+#ifndef CBOR_NO_FLOAT
+cn_cbor* cn_cbor_double_create(double value
+ CBOR_CONTEXT,
+ cn_cbor_errback *errp)
+{
+ cn_cbor* ret;
+ INIT_CB(ret);
+
+ ret->type = CN_CBOR_DOUBLE;
+ ret->v.dbl = value;
+
+ return ret;
+}
+#endif /* CBOR_NO_FLOAT */
+
static bool _append_kv(cn_cbor *cb_map, cn_cbor *key, cn_cbor *val)
{
//Connect key and value and insert them into the map.