From 801759b155dd7d3e6c15096fc8613ae17fbf5e24 Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Mon, 14 May 2018 13:43:40 +0300 Subject: [PATCH] Add cn_cbor_create(type) for convenience --- include/cn-cbor/cn-cbor.h | 12 ++++++++++++ src/cn-create.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/cn-cbor/cn-cbor.h b/include/cn-cbor/cn-cbor.h index 187a55c..0c74dbd 100644 --- a/include/cn-cbor/cn-cbor.h +++ b/include/cn-cbor/cn-cbor.h @@ -277,6 +277,18 @@ ssize_t cn_cbor_encoder_write(uint8_t *buf, size_t buf_size, const cn_cbor *cb); +/** + * Create a CBOR object. + * + * @param[in] type the type of the object + * @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_create(cn_cbor_type type + CBOR_CONTEXT, + cn_cbor_errback *errp); + /** * Create a CBOR map. * diff --git a/src/cn-create.c b/src/cn-create.c index 4ddce3b..a365624 100644 --- a/src/cn-create.c +++ b/src/cn-create.c @@ -16,6 +16,18 @@ extern "C" { (v) = CN_CALLOC_CONTEXT(); \ if (!(v)) { if (errp) {errp->err = CN_CBOR_ERR_OUT_OF_MEMORY;} return NULL; } +cn_cbor* cn_cbor_create(cn_cbor_type type + CBOR_CONTEXT, + cn_cbor_errback *errp) +{ + cn_cbor* ret; + INIT_CB(ret); + + ret->type = type; + + return ret; +} + cn_cbor* cn_cbor_map_create(CBOR_CONTEXT_COMMA cn_cbor_errback *errp) { cn_cbor* ret;