cn-create: add cn_cbor_double_create
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 @@ 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 @@ 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.