This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 0ef8a3607bd476ffee53605a380e11ad98132e58
Author: Szymon Janc <[email protected]>
AuthorDate: Fri Oct 9 10:46:33 2026 +0200

    encoding/tinycbor7: Add upstream TinyCBOR 7.0 package
    
    In-tree TinyCBOR is an old fork (based on 0.4) with Mynewt specific
    reader/writer API. This adds new package that uses upstream TinyCBOR 7.0
    from external repository and provides Mynewt extensions:
    
     - syscfg for TinyCBOR configuration (float and half-float support,
       max recursion level, pretty and validation APIs)
     - Mynewt CBOR readers (struct cbor_reader) for data that is not
       available in single contiguous buffer (mbuf chain, log entry).
       Reading position is kept in iterator, so unlike TinyCBOR reader API,
       iterators are independent from each other.
     - mbuf helpers (cbor_mbuf_value_advance(), cbor_mbuf_value_copy_*() and
       cbor_mbuf_value_calculate_string_length()) that handle strings that
       are not contiguous in mbuf chain; TinyCBOR accesses strings by
       pointer, also when skipping them
     - mbuf and counting writers (struct cbor_writer)
     - cbor_encode_byte_iovec() and indefinite length strings encoding
    
    Only required TinyCBOR source files are built. Half-float, pretty
    printing and validation sources are built only if enabled in syscfg.
    CBOR to JSON conversion is not supported.
    
    Package is added next to existing tinycbor package so that users can be
    converted before old package is removed. It will be renamed to tinycbor
    afterwards.
    
    Assisted-by: Claude:claude-opus-5-5
---
 encoding/tinycbor7/include/cbor_cfg.h              |  78 +++++++++
 encoding/tinycbor7/include/tinycbor-export.h       |  25 +++
 encoding/tinycbor7/include/tinycbor-version.h      |  25 +++
 encoding/tinycbor7/include/tinycbor7/cbor.h        |  27 +++
 .../tinycbor7/include/tinycbor7/cbor_cnt_writer.h  |  53 ++++++
 .../tinycbor7/include/tinycbor7/cbor_mbuf_reader.h |  96 +++++++++++
 .../tinycbor7/include/tinycbor7/cbor_mbuf_writer.h |  53 ++++++
 encoding/tinycbor7/include/tinycbor7/cbor_mynewt.h | 113 ++++++++++++
 encoding/tinycbor7/include/tinycbor7/cbor_reader.h | 100 +++++++++++
 encoding/tinycbor7/pkg.yml                         |  67 ++++++++
 encoding/tinycbor7/src/cbor_cnt_writer.c           |  37 ++++
 encoding/tinycbor7/src/cbor_mbuf_reader.c          | 180 +++++++++++++++++++
 encoding/tinycbor7/src/cbor_mbuf_writer.c          |  42 +++++
 encoding/tinycbor7/src/cbor_mynewt.c               | 150 ++++++++++++++++
 encoding/tinycbor7/src/cbor_reader.c               | 191 +++++++++++++++++++++
 encoding/tinycbor7/src/cbor_reader_priv.h          |  38 ++++
 encoding/tinycbor7/syscfg.yml                      |  48 ++++++
 17 files changed, 1323 insertions(+)

diff --git a/encoding/tinycbor7/include/cbor_cfg.h 
b/encoding/tinycbor7/include/cbor_cfg.h
new file mode 100644
index 000000000..85c3fafca
--- /dev/null
+++ b/encoding/tinycbor7/include/cbor_cfg.h
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * TinyCBOR configuration for Mynewt. This file is included by TinyCBOR cbor.h
+ * if CBOR_EXTERNAL_CFG is defined.
+ */
+
+#ifndef H_TINYCBOR_CBOR_CFG_
+#define H_TINYCBOR_CBOR_CFG_
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include "syscfg/syscfg.h"
+
+#if !MYNEWT_VAL(TINYCBOR_FLOAT_SUPPORT)
+#define CBOR_NO_FLOATING_POINT
+#endif
+
+#if !MYNEWT_VAL(TINYCBOR_HALF_FLOAT_SUPPORT)
+#define CBOR_NO_HALF_FLOAT_TYPE
+#endif
+
+#define CBOR_PARSER_MAX_RECURSIONS MYNEWT_VAL(TINYCBOR_PARSER_MAX_RECURSIONS)
+
+#if !MYNEWT_VAL(TINYCBOR_PRETTY_API)
+#define CBOR_NO_PRETTY_API
+#endif
+
+#if !MYNEWT_VAL(TINYCBOR_VALIDATION_API)
+#define CBOR_NO_VALIDATION_API
+#endif
+
+/*
+ * Parser with external source (cbor_parser_init_reader()) is used with Mynewt
+ * readers only (see tinycbor7/cbor_reader.h). TinyCBOR reader API keeps 
reading
+ * position in reader, shared by all iterators, while Mynewt users expect
+ * iterators to be independent (e.g. copy of iterator can be advanced without
+ * affecting original). To achieve that TinyCBOR reader functions are replaced
+ * with functions that use iterator token as offset into source data. Those
+ * functions are only used for TinyCBOR internal helpers with iterator named
+ * 'it'.
+ */
+struct CborValue;
+
+bool cbor_reader_can_read_bytes(const struct CborValue *it, size_t len);
+void *cbor_reader_read_bytes(const struct CborValue *it, void *dst,
+                             size_t offset, size_t len);
+int cbor_reader_transfer_string(struct CborValue *it, const void **ptr,
+                                size_t offset, size_t len);
+
+#define CBOR_PARSER_CAN_READ_BYTES_FUNCTION(token, len)                       \
+    cbor_reader_can_read_bytes(it, len)
+#define CBOR_PARSER_READ_BYTES_FUNCTION(token, dst, offset, len)              \
+    cbor_reader_read_bytes(it, dst, offset, len)
+#define CBOR_PARSER_ADVANCE_BYTES_FUNCTION(token, len)                        \
+    ((token) = (void *)((uintptr_t)(token) + (len)))
+#define CBOR_PARSER_TRANSFER_STRING_FUNCTION(token, ptr, offset, len)         \
+    cbor_reader_transfer_string(it, ptr, offset, len)
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor-export.h 
b/encoding/tinycbor7/include/tinycbor-export.h
new file mode 100644
index 000000000..10d8370ab
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor-export.h
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Replaces header generated by TinyCBOR build system.
+ */
+#ifndef CBOR_API
+#define CBOR_API
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor-version.h 
b/encoding/tinycbor7/include/tinycbor-version.h
new file mode 100644
index 000000000..d701cc009
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor-version.h
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Replaces header generated by TinyCBOR build system.
+ */
+#define TINYCBOR_VERSION_MAJOR 7
+#define TINYCBOR_VERSION_MINOR 0
+#define TINYCBOR_VERSION_PATCH 0
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor.h 
b/encoding/tinycbor7/include/tinycbor7/cbor.h
new file mode 100644
index 000000000..bfd020c81
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor.h
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_TINYCBOR_CBOR_
+#define H_TINYCBOR_CBOR_
+
+/* TinyCBOR main header, provided by @tinycbor repository */
+#include <cbor.h>
+#include "tinycbor7/cbor_mynewt.h"
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor_cnt_writer.h 
b/encoding/tinycbor7/include/tinycbor7/cbor_cnt_writer.h
new file mode 100644
index 000000000..49c791212
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor_cnt_writer.h
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_TINYCBOR_CBOR_CNT_WRITER_
+#define H_TINYCBOR_CBOR_CNT_WRITER_
+
+#include <tinycbor7/cbor.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * CBOR writer that only counts encoded bytes, can be used to check encoded
+ * data length before encoding it to destination.
+ */
+struct cbor_cnt_writer {
+    struct cbor_writer enc;
+};
+
+/**
+ * Initializes counting writer. Encoder is initialized with
+ * cbor_writer_encoder_init(&writer->enc, encoder).
+ *
+ * @param cb            Writer to initialize.
+ */
+void cbor_cnt_writer_init(struct cbor_cnt_writer *cb);
+
+/** Write function for cbor_encoder_init_writer() */
+CborError cbor_cnt_writer(void *token, const void *data, size_t len,
+                          CborEncoderAppendType append);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_reader.h 
b/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_reader.h
new file mode 100644
index 000000000..3e15b19ae
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_reader.h
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_TINYCBOR_CBOR_MBUF_READER_
+#define H_TINYCBOR_CBOR_MBUF_READER_
+
+#include "os/mynewt.h"
+#include <tinycbor7/cbor.h>
+#include <tinycbor7/cbor_reader.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** CBOR reader for data in mbuf chain */
+struct cbor_mbuf_reader {
+    struct cbor_reader r;
+    /** Offset of CBOR data in mbuf chain */
+    int init_off;
+    struct os_mbuf *m;
+};
+
+/**
+ * Initializes mbuf reader. Parser is initialized with
+ * cbor_reader_parser_init(&reader->r, ...).
+ *
+ * @param cb            Reader to initialize.
+ * @param m             Packet header mbuf containing CBOR data.
+ * @param initial_offset    Offset of CBOR data in mbuf chain.
+ */
+void cbor_mbuf_reader_init(struct cbor_mbuf_reader *cb, struct os_mbuf *m,
+                           int initial_offset);
+
+/**
+ * Advances iterator to next element, see cbor_value_advance(). Works for
+ * strings that are not contiguous in mbuf chain (cbor_value_advance() needs
+ * strings to be contiguous to skip them).
+ *
+ * Can be used with values from any parser, for parsers not using Mynewt
+ * CBOR reader TinyCBOR function is used.
+ */
+CborError cbor_mbuf_value_advance(CborValue *it);
+
+/**
+ * Copies byte string pointed to by value to buffer, see
+ * cbor_value_copy_byte_string(). Works for strings that are not contiguous in
+ * mbuf chain.
+ *
+ * Can be used with values from any parser, for parsers not using Mynewt
+ * CBOR reader TinyCBOR string function is used.
+ */
+CborError cbor_mbuf_value_copy_byte_string(const CborValue *value, uint8_t 
*buffer,
+                                           size_t *buflen, CborValue *next);
+
+/**
+ * Copies text string pointed to by value to buffer, see
+ * cbor_value_copy_text_string(). Works for strings that are not contiguous in
+ * mbuf chain.
+ *
+ * Can be used with values from any parser, for parsers not using Mynewt
+ * CBOR reader TinyCBOR string function is used.
+ */
+CborError cbor_mbuf_value_copy_text_string(const CborValue *value, char 
*buffer,
+                                           size_t *buflen, CborValue *next);
+
+/**
+ * Calculates length of string pointed to by value, see
+ * cbor_value_calculate_string_length(). Works for strings that are not
+ * contiguous in mbuf chain.
+ *
+ * Can be used with values from any parser, for parsers not using Mynewt
+ * CBOR reader TinyCBOR string function is used.
+ */
+CborError cbor_mbuf_value_calculate_string_length(const CborValue *value, 
size_t *len);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_writer.h 
b/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_writer.h
new file mode 100644
index 000000000..4015d6dd1
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor_mbuf_writer.h
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_TINYCBOR_CBOR_MBUF_WRITER_
+#define H_TINYCBOR_CBOR_MBUF_WRITER_
+
+#include "os/mynewt.h"
+#include <tinycbor7/cbor.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** CBOR writer appending encoded data to mbuf chain */
+struct cbor_mbuf_writer {
+    struct cbor_writer enc;
+    struct os_mbuf *m;
+};
+
+/**
+ * Initializes mbuf writer. Encoder is initialized with
+ * cbor_writer_encoder_init(&writer->enc, encoder).
+ *
+ * @param cb            Writer to initialize.
+ * @param m             Mbuf to append encoded data to.
+ */
+void cbor_mbuf_writer_init(struct cbor_mbuf_writer *cb, struct os_mbuf *m);
+
+/** Write function for cbor_encoder_init_writer() */
+CborError cbor_mbuf_writer(void *token, const void *data, size_t len,
+                           CborEncoderAppendType append);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor_mynewt.h 
b/encoding/tinycbor7/include/tinycbor7/cbor_mynewt.h
new file mode 100644
index 000000000..deabffe7c
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor_mynewt.h
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Mynewt extensions to TinyCBOR encoder API.
+ */
+
+#ifndef H_TINYCBOR_CBOR_MYNEWT_
+#define H_TINYCBOR_CBOR_MYNEWT_
+
+#include <stddef.h>
+#include <cbor.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Base of Mynewt CBOR writers. Encoder using writer is initialized with
+ * cbor_writer_encoder_init() or with cbor_encoder_init_writer() with writer
+ * as token.
+ */
+struct cbor_writer {
+    /** Write function */
+    CborEncoderWriteFunction write;
+    /** Number of bytes written so far */
+    size_t bytes_written;
+};
+
+/**
+ * Initializes encoder to use Mynewt CBOR writer.
+ *
+ * @param writer        Initialized writer.
+ * @param encoder       Encoder to initialize.
+ */
+void cbor_writer_encoder_init(struct cbor_writer *writer, CborEncoder 
*encoder);
+
+/**
+ * Returns number of bytes written by encoder using Mynewt CBOR writer.
+ *
+ * @param encoder       Encoder (or container encoder) using Mynewt CBOR
+ *                      writer.
+ *
+ * @return              Number of bytes written.
+ */
+size_t cbor_encode_bytes_written(const CborEncoder *encoder);
+
+/** Data chunk used by cbor_encode_byte_iovec() */
+struct cbor_iovec {
+    void *iov_base;
+    size_t iov_len;
+};
+
+/**
+ * Encodes byte string with data provided as array of chunks. Encoded string
+ * has definite length equal to sum of chunks lengths.
+ *
+ * @param encoder       Encoder.
+ * @param iov           Array of data chunks.
+ * @param iov_len       Number of data chunks.
+ *
+ * @return              CborNoError on success, other value on error.
+ */
+CborError cbor_encode_byte_iovec(CborEncoder *encoder,
+                                 const struct cbor_iovec iov[], int iov_len);
+
+/**
+ * Creates indefinite length byte string. Chunks are encoded with
+ * cbor_encode_byte_string() on string encoder and string is closed with
+ * cbor_encoder_close_container().
+ *
+ * @param encoder       Encoder.
+ * @param string_encoder    String encoder to initialize.
+ *
+ * @return              CborNoError on success, other value on error.
+ */
+CborError cbor_encoder_create_indef_byte_string(CborEncoder *encoder,
+                                                CborEncoder *string_encoder);
+
+/**
+ * Creates indefinite length text string. Chunks are encoded with
+ * cbor_encode_text_string() on string encoder and string is closed with
+ * cbor_encoder_close_container().
+ *
+ * @param encoder       Encoder.
+ * @param string_encoder    String encoder to initialize.
+ *
+ * @return              CborNoError on success, other value on error.
+ */
+CborError cbor_encoder_create_indef_text_string(CborEncoder *encoder,
+                                                CborEncoder *string_encoder);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/encoding/tinycbor7/include/tinycbor7/cbor_reader.h 
b/encoding/tinycbor7/include/tinycbor7/cbor_reader.h
new file mode 100644
index 000000000..fbd2ce21c
--- /dev/null
+++ b/encoding/tinycbor7/include/tinycbor7/cbor_reader.h
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*
+ * Mynewt CBOR readers.
+ *
+ * Mynewt readers allow parsing CBOR data that is not available as single
+ * contiguous buffer (e.g. data in mbuf chain or in flash). Unlike TinyCBOR
+ * reader API, reading position is kept in iterator so iterators are
+ * independent from each other.
+ *
+ * TinyCBOR accesses strings by pointer, also when only skipping them, so
+ * TinyCBOR functions that read or skip strings (e.g.
+ * cbor_value_copy_text_string(), cbor_value_advance(),
+ * cbor_value_map_find_value(), cbor_value_validate(),
+ * cbor_value_to_pretty()) fail with CborErrorIO for strings that are not
+ * contiguous in source data, unless reader has scratch buffer big enough to
+ * hold such string. Use cbor_mbuf_value_advance(),
+ * cbor_mbuf_value_copy_text_string() and related helpers to handle strings
+ * regardless of source data layout.
+ */
+
+#ifndef H_TINYCBOR_CBOR_READER_
+#define H_TINYCBOR_CBOR_READER_
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <cbor.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct cbor_reader;
+
+/** Mynewt CBOR reader operations, offsets are relative to start of data */
+struct cbor_reader_ops {
+    /** Checks if len bytes are available at offset */
+    bool (*can_read)(const struct cbor_reader *reader, size_t offset, size_t 
len);
+    /** Copies len bytes at offset to dst, returns dst or NULL on failure */
+    void *(*read)(const struct cbor_reader *reader, void *dst, size_t offset,
+                  size_t len);
+    /**
+     * Returns pointer to len contiguous bytes at offset or NULL if data is not
+     * contiguous (optional, may be NULL).
+     */
+    const void *(*get_ptr)(const struct cbor_reader *reader, size_t offset, 
size_t len);
+};
+
+/** Base of Mynewt CBOR readers */
+struct cbor_reader {
+    const struct cbor_reader_ops *ops;
+
+    /**
+     * Optional scratch buffer used to provide strings that are not
+     * contiguous in source data to TinyCBOR string functions.
+     */
+    uint8_t *scratch;
+    size_t scratch_size;
+
+    /* Used internally by string helpers */
+    uint8_t *xfer_buf;
+    size_t xfer_buf_len;
+    bool xfer_active;
+};
+
+/**
+ * Initializes parser for data provided by Mynewt CBOR reader.
+ *
+ * @param reader        Initialized reader, must remain valid while parsing.
+ * @param parser        Parser to initialize.
+ * @param it            Iterator to first element.
+ *
+ * @return              CborNoError on success, other value on error.
+ */
+CborError cbor_reader_parser_init(struct cbor_reader *reader,
+                                  CborParser *parser, CborValue *it);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/encoding/tinycbor7/pkg.yml b/encoding/tinycbor7/pkg.yml
new file mode 100644
index 000000000..ff77a4255
--- /dev/null
+++ b/encoding/tinycbor7/pkg.yml
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+pkg.name: encoding/tinycbor7
+pkg.description: CBOR encoding/decoding library (Intel TinyCBOR) with Mynewt 
extensions
+pkg.author: "Apache Mynewt <[email protected]>"
+pkg.homepage: "https://github.com/intel/tinycbor";
+pkg.keywords:
+    - cbor
+pkg.type: sdk
+
+pkg.deps:
+    - "@apache-mynewt-core/kernel/os"
+
+pkg.cflags:
+    - -DCBOR_EXTERNAL_CFG
+
+pkg.include_dirs:
+    - "include"
+    - "@tinycbor/src"
+
+pkg.source_files:
+    - "@tinycbor/src/cborencoder.c"
+    - "@tinycbor/src/cborencoder_close_container_checked.c"
+    - "@tinycbor/src/cborerrorstrings.c"
+    - "@tinycbor/src/cborparser.c"
+    - "@tinycbor/src/cborparser_dup_string.c"
+    - "src/cbor_cnt_writer.c"
+    - "src/cbor_mbuf_reader.c"
+    - "src/cbor_mbuf_writer.c"
+    - "src/cbor_mynewt.c"
+    - "src/cbor_reader.c"
+
+pkg.source_files.TINYCBOR_HALF_FLOAT_SUPPORT:
+    - "@tinycbor/src/cborencoder_float.c"
+    - "@tinycbor/src/cborparser_float.c"
+
+pkg.source_files.TINYCBOR_PRETTY_API:
+    - "@tinycbor/src/cborpretty.c"
+    - "@tinycbor/src/cborpretty_stdio.c"
+
+pkg.source_files.TINYCBOR_VALIDATION_API:
+    - "@tinycbor/src/cborvalidation.c"
+
+repository.tinycbor:
+    type: github
+    vers: v7.0-commit
+    branch: main
+    user: intel
+    repo: tinycbor
diff --git a/encoding/tinycbor7/src/cbor_cnt_writer.c 
b/encoding/tinycbor7/src/cbor_cnt_writer.c
new file mode 100644
index 000000000..4ca0eb11f
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_cnt_writer.c
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <tinycbor7/cbor_cnt_writer.h>
+
+void
+cbor_cnt_writer_init(struct cbor_cnt_writer *cb)
+{
+    cb->enc.write = cbor_cnt_writer;
+    cb->enc.bytes_written = 0;
+}
+
+CborError
+cbor_cnt_writer(void *token, const void *data, size_t len, 
CborEncoderAppendType append)
+{
+    struct cbor_cnt_writer *cb = token;
+
+    cb->enc.bytes_written += len;
+
+    return CborNoError;
+}
diff --git a/encoding/tinycbor7/src/cbor_mbuf_reader.c 
b/encoding/tinycbor7/src/cbor_mbuf_reader.c
new file mode 100644
index 000000000..44672d8d7
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_mbuf_reader.c
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <tinycbor7/cbor_mbuf_reader.h>
+#include "cbor_reader_priv.h"
+
+static size_t
+cbor_mbuf_reader_len(const struct cbor_mbuf_reader *cb)
+{
+    return OS_MBUF_PKTLEN(cb->m) - cb->init_off;
+}
+
+static bool
+cbor_mbuf_reader_can_read(const struct cbor_reader *r, size_t offset, size_t 
len)
+{
+    const struct cbor_mbuf_reader *cb = (const struct cbor_mbuf_reader *)r;
+    size_t avail = cbor_mbuf_reader_len(cb);
+
+    return offset <= avail && len <= avail - offset;
+}
+
+static void *
+cbor_mbuf_reader_read(const struct cbor_reader *r, void *dst, size_t offset, 
size_t len)
+{
+    const struct cbor_mbuf_reader *cb = (const struct cbor_mbuf_reader *)r;
+
+    if (!cbor_mbuf_reader_can_read(r, offset, len)) {
+        return NULL;
+    }
+
+    if (os_mbuf_copydata(cb->m, cb->init_off + offset, len, dst)) {
+        return NULL;
+    }
+
+    return dst;
+}
+
+static const void *
+cbor_mbuf_reader_get_ptr(const struct cbor_reader *r, size_t offset, size_t 
len)
+{
+    const struct cbor_mbuf_reader *cb = (const struct cbor_mbuf_reader *)r;
+    struct os_mbuf *om;
+    uint16_t om_off;
+
+    if (!cbor_mbuf_reader_can_read(r, offset, len)) {
+        return NULL;
+    }
+
+    om = os_mbuf_off(cb->m, cb->init_off + offset, &om_off);
+    if (!om || om->om_len - om_off < len) {
+        return NULL;
+    }
+
+    return om->om_data + om_off;
+}
+
+static const struct cbor_reader_ops cbor_mbuf_reader_ops = {
+    .can_read = cbor_mbuf_reader_can_read,
+    .read = cbor_mbuf_reader_read,
+    .get_ptr = cbor_mbuf_reader_get_ptr,
+};
+
+void
+cbor_mbuf_reader_init(struct cbor_mbuf_reader *cb, struct os_mbuf *m, int 
initial_offset)
+{
+    assert(OS_MBUF_IS_PKTHDR(m));
+
+    memset(cb, 0, sizeof(*cb));
+    cb->r.ops = &cbor_mbuf_reader_ops;
+    cb->m = m;
+    cb->init_off = initial_offset;
+}
+
+static CborError
+cbor_mbuf_value_advance_nested(CborValue *it, int nesting)
+{
+    CborValue recursed;
+    CborError err;
+    size_t len;
+
+    if (cbor_value_is_byte_string(it) || cbor_value_is_text_string(it)) {
+        len = SIZE_MAX;
+        return cbor_reader_copy_string(it, NULL, &len, it);
+    }
+
+    if (!cbor_value_is_container(it)) {
+        return cbor_value_advance(it);
+    }
+
+    if (nesting == 0) {
+        return CborErrorNestingTooDeep;
+    }
+
+    err = cbor_value_enter_container(it, &recursed);
+    if (err) {
+        return err;
+    }
+
+    while (!cbor_value_at_end(&recursed)) {
+        err = cbor_mbuf_value_advance_nested(&recursed, nesting - 1);
+        if (err) {
+            return err;
+        }
+    }
+
+    return cbor_value_leave_container(it, &recursed);
+}
+
+CborError
+cbor_mbuf_value_advance(CborValue *it)
+{
+    if (!cbor_reader_is_used(it)) {
+        return cbor_value_advance(it);
+    }
+
+    if (!it->remaining) {
+        return CborErrorAdvancePastEOF;
+    }
+
+    return cbor_mbuf_value_advance_nested(
+        it, MYNEWT_VAL(TINYCBOR_PARSER_MAX_RECURSIONS));
+}
+
+CborError
+cbor_mbuf_value_copy_byte_string(const CborValue *value, uint8_t *buffer,
+                                 size_t *buflen, CborValue *next)
+{
+    if (!cbor_reader_is_used(value)) {
+        return cbor_value_copy_byte_string(value, buffer, buflen, next);
+    }
+
+    if (!cbor_value_is_byte_string(value)) {
+        return CborErrorIllegalType;
+    }
+
+    return cbor_reader_copy_string(value, buffer, buflen, next);
+}
+
+CborError
+cbor_mbuf_value_copy_text_string(const CborValue *value, char *buffer,
+                                 size_t *buflen, CborValue *next)
+{
+    if (!cbor_reader_is_used(value)) {
+        return cbor_value_copy_text_string(value, buffer, buflen, next);
+    }
+
+    if (!cbor_value_is_text_string(value)) {
+        return CborErrorIllegalType;
+    }
+
+    return cbor_reader_copy_string(value, buffer, buflen, next);
+}
+
+CborError
+cbor_mbuf_value_calculate_string_length(const CborValue *value, size_t *len)
+{
+    if (!cbor_reader_is_used(value)) {
+        return cbor_value_calculate_string_length(value, len);
+    }
+
+    *len = SIZE_MAX;
+    return cbor_reader_copy_string(value, NULL, len, NULL);
+}
diff --git a/encoding/tinycbor7/src/cbor_mbuf_writer.c 
b/encoding/tinycbor7/src/cbor_mbuf_writer.c
new file mode 100644
index 000000000..4882c880b
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_mbuf_writer.c
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <tinycbor7/cbor_mbuf_writer.h>
+
+void
+cbor_mbuf_writer_init(struct cbor_mbuf_writer *cb, struct os_mbuf *m)
+{
+    cb->enc.write = cbor_mbuf_writer;
+    cb->enc.bytes_written = 0;
+    cb->m = m;
+}
+
+CborError
+cbor_mbuf_writer(void *token, const void *data, size_t len, 
CborEncoderAppendType append)
+{
+    struct cbor_mbuf_writer *cb = token;
+
+    if (len > UINT16_MAX || os_mbuf_append(cb->m, data, len)) {
+        return CborErrorOutOfMemory;
+    }
+
+    cb->enc.bytes_written += len;
+
+    return CborNoError;
+}
diff --git a/encoding/tinycbor7/src/cbor_mynewt.c 
b/encoding/tinycbor7/src/cbor_mynewt.c
new file mode 100644
index 000000000..9c4e3e1dd
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_mynewt.c
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <tinycbor7/cbor.h>
+
+#define CBOR_MAJOR_TYPE_BYTE_STRING (2 << 5)
+#define CBOR_MAJOR_TYPE_TEXT_STRING (3 << 5)
+#define CBOR_INDEFINITE_LENGTH      (31)
+
+void
+cbor_writer_encoder_init(struct cbor_writer *writer, CborEncoder *encoder)
+{
+    cbor_encoder_init_writer(encoder, writer->write, writer);
+}
+
+size_t
+cbor_encode_bytes_written(const CborEncoder *encoder)
+{
+    const struct cbor_writer *writer;
+
+    assert(encoder->flags & CborIteratorFlag_WriterFunction);
+
+    /* Writer token is stored in encoder end pointer */
+    writer = (const struct cbor_writer *)(const void *)encoder->end;
+
+    return writer->bytes_written;
+}
+
+/* Counts item in encoder as done by TinyCBOR for encoded values */
+static void
+cbor_encoder_count_item(CborEncoder *encoder)
+{
+    if (encoder->remaining) {
+        encoder->remaining--;
+    }
+}
+
+static size_t
+cbor_encode_header(uint8_t *buf, uint8_t major_type, uint64_t val)
+{
+    size_t len;
+    size_t i;
+
+    if (val < 24) {
+        buf[0] = major_type | (uint8_t)val;
+        return 1;
+    }
+
+    if (val <= UINT8_MAX) {
+        buf[0] = major_type | 24;
+        len = 1;
+    } else if (val <= UINT16_MAX) {
+        buf[0] = major_type | 25;
+        len = 2;
+    } else if (val <= UINT32_MAX) {
+        buf[0] = major_type | 26;
+        len = 4;
+    } else {
+        buf[0] = major_type | 27;
+        len = 8;
+    }
+
+    for (i = 0; i < len; i++) {
+        buf[len - i] = (uint8_t)(val >> (8 * i));
+    }
+
+    return len + 1;
+}
+
+CborError
+cbor_encode_byte_iovec(CborEncoder *encoder, const struct cbor_iovec iov[], 
int iov_len)
+{
+    uint8_t hdr[9];
+    uint64_t len = 0;
+    CborError err;
+    size_t hdr_len;
+    int i;
+
+    for (i = 0; i < iov_len; i++) {
+        len += iov[i].iov_len;
+    }
+
+    hdr_len = cbor_encode_header(hdr, CBOR_MAJOR_TYPE_BYTE_STRING, len);
+
+    err = cbor_encode_raw(encoder, hdr, hdr_len);
+    for (i = 0; i < iov_len && !err; i++) {
+        err = cbor_encode_raw(encoder, iov[i].iov_base, iov[i].iov_len);
+    }
+
+    if (err && err != CborErrorOutOfMemory) {
+        return err;
+    }
+
+    cbor_encoder_count_item(encoder);
+
+    return err;
+}
+
+/*
+ * Creates indefinite length string container in the same way TinyCBOR creates
+ * indefinite length array or map, so that cbor_encoder_close_container() can
+ * be used to close it.
+ */
+static CborError
+cbor_encoder_create_indef_string(CborEncoder *encoder,
+                                 CborEncoder *string_encoder, uint8_t 
major_type)
+{
+    uint8_t hdr = major_type | CBOR_INDEFINITE_LENGTH;
+
+    string_encoder->data = encoder->data;
+    string_encoder->end = encoder->end;
+    string_encoder->remaining = 0;
+    string_encoder->flags = CborIteratorFlag_UnknownLength |
+                            (encoder->flags & CborIteratorFlag_WriterFunction);
+
+    cbor_encoder_count_item(encoder);
+
+    return cbor_encode_raw(string_encoder, &hdr, 1);
+}
+
+CborError
+cbor_encoder_create_indef_byte_string(CborEncoder *encoder, CborEncoder 
*string_encoder)
+{
+    return cbor_encoder_create_indef_string(encoder, string_encoder,
+                                            CBOR_MAJOR_TYPE_BYTE_STRING);
+}
+
+CborError
+cbor_encoder_create_indef_text_string(CborEncoder *encoder, CborEncoder 
*string_encoder)
+{
+    return cbor_encoder_create_indef_string(encoder, string_encoder,
+                                            CBOR_MAJOR_TYPE_TEXT_STRING);
+}
diff --git a/encoding/tinycbor7/src/cbor_reader.c 
b/encoding/tinycbor7/src/cbor_reader.c
new file mode 100644
index 000000000..7083d10fd
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_reader.c
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <assert.h>
+#include <tinycbor7/cbor.h>
+#include <tinycbor7/cbor_reader.h>
+#include "cbor_reader_priv.h"
+
+static struct cbor_reader *
+cbor_reader_get(const CborValue *it)
+{
+    /* Mynewt reader is passed to TinyCBOR as parser operations */
+    return (struct cbor_reader *)(uintptr_t)it->parser->source.ops;
+}
+
+static size_t
+cbor_reader_pos(const CborValue *it)
+{
+    return (size_t)(uintptr_t)it->source.token;
+}
+
+bool
+cbor_reader_can_read_bytes(const struct CborValue *it, size_t len)
+{
+    const struct cbor_reader *reader = cbor_reader_get(it);
+
+    return reader->ops->can_read(reader, cbor_reader_pos(it), len);
+}
+
+void *
+cbor_reader_read_bytes(const struct CborValue *it, void *dst, size_t offset, 
size_t len)
+{
+    const struct cbor_reader *reader = cbor_reader_get(it);
+
+    return reader->ops->read(reader, dst, cbor_reader_pos(it) + offset, len);
+}
+
+int
+cbor_reader_transfer_string(struct CborValue *it, const void **ptr,
+                            size_t offset, size_t len)
+{
+    struct cbor_reader *reader = cbor_reader_get(it);
+    const void *data = NULL;
+    size_t off;
+
+    off = cbor_reader_pos(it) + offset;
+    if (len > SIZE_MAX - off || !reader->ops->can_read(reader, off, len)) {
+        return CborErrorUnexpectedEOF;
+    }
+
+    if (reader->xfer_active) {
+        /* String is copied by string helper, see cbor_reader_copy_string() */
+        if (reader->xfer_buf && len <= reader->xfer_buf_len) {
+            data = reader->ops->read(reader, reader->xfer_buf, off, len);
+            if (!data) {
+                return CborErrorIO;
+            }
+            reader->xfer_buf += len;
+            reader->xfer_buf_len -= len;
+        } else {
+            /* Doesn't fit, only calculate length from now on */
+            reader->xfer_buf = NULL;
+        }
+    } else {
+        if (reader->ops->get_ptr) {
+            data = reader->ops->get_ptr(reader, off, len);
+        }
+        if (!data && reader->scratch && len <= reader->scratch_size) {
+            data = reader->ops->read(reader, reader->scratch, off, len);
+        }
+        if (!data) {
+            return CborErrorIO;
+        }
+    }
+
+    *ptr = data;
+    it->source.token = (void *)(uintptr_t)(off + len);
+
+    return CborNoError;
+}
+
+CborError
+cbor_reader_parser_init(struct cbor_reader *reader, CborParser *parser, 
CborValue *it)
+{
+    reader->xfer_active = false;
+
+    return cbor_parser_init_reader(
+        (const struct CborParserOperations *)(const void *)reader, parser, it, 
NULL);
+}
+
+static CborError
+cbor_reader_get_chunk(CborValue *it, size_t *len)
+{
+    const void *ptr;
+
+    if (cbor_value_is_text_string(it)) {
+        return cbor_value_get_text_string_chunk(it, (const char **)&ptr, len, 
it);
+    }
+
+    return cbor_value_get_byte_string_chunk(it, (const uint8_t **)&ptr, len, 
it);
+}
+
+CborError
+cbor_reader_copy_string(const CborValue *value, void *buffer, size_t *buflen,
+                        CborValue *next)
+{
+    struct cbor_reader *reader;
+    size_t total = 0;
+    size_t chunk_len;
+    CborValue it;
+    CborError err;
+    bool fits;
+
+    if (!cbor_value_is_byte_string(value) && 
!cbor_value_is_text_string(value)) {
+        return CborErrorIllegalType;
+    }
+
+    reader = cbor_reader_get(value);
+    it = *value;
+
+    err = cbor_value_begin_string_iteration(&it);
+    if (err) {
+        return err;
+    }
+
+    reader->xfer_buf = buffer;
+    reader->xfer_buf_len = buffer ? *buflen : 0;
+    reader->xfer_active = true;
+
+    while (1) {
+        err = cbor_reader_get_chunk(&it, &chunk_len);
+        if (err == CborErrorNoMoreStringChunks) {
+            err = CborNoError;
+            break;
+        }
+        if (err) {
+            break;
+        }
+
+        if (chunk_len > SIZE_MAX - total) {
+            err = CborErrorDataTooLarge;
+            break;
+        }
+        total += chunk_len;
+    }
+
+    fits = buffer && reader->xfer_buf;
+    reader->xfer_active = false;
+    reader->xfer_buf = NULL;
+
+    if (err) {
+        return err;
+    }
+
+    /* NUL terminate if there is space, as TinyCBOR does */
+    if (fits && *buflen > total) {
+        ((uint8_t *)buffer)[total] = '\0';
+    }
+
+    err = cbor_value_finish_string_iteration(&it);
+    if (err) {
+        return err;
+    }
+
+    *buflen = total;
+    if (next) {
+        *next = it;
+    }
+
+    if (buffer && !fits) {
+        return CborErrorOutOfMemory;
+    }
+
+    return CborNoError;
+}
diff --git a/encoding/tinycbor7/src/cbor_reader_priv.h 
b/encoding/tinycbor7/src/cbor_reader_priv.h
new file mode 100644
index 000000000..7cb17f5ab
--- /dev/null
+++ b/encoding/tinycbor7/src/cbor_reader_priv.h
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_TINYCBOR_CBOR_READER_PRIV_
+#define H_TINYCBOR_CBOR_READER_PRIV_
+
+#include <tinycbor7/cbor.h>
+
+/*
+ * Copies (or calculates length of if buffer is NULL) string from value parsed
+ * with Mynewt CBOR reader, regardless of string layout in source data.
+ */
+CborError cbor_reader_copy_string(const CborValue *value, void *buffer,
+                                  size_t *buflen, CborValue *next);
+
+static inline bool
+cbor_reader_is_used(const CborValue *value)
+{
+    return value->parser->flags & CborParserFlag_ExternalSource;
+}
+
+#endif
diff --git a/encoding/tinycbor7/syscfg.yml b/encoding/tinycbor7/syscfg.yml
new file mode 100644
index 000000000..6fd628143
--- /dev/null
+++ b/encoding/tinycbor7/syscfg.yml
@@ -0,0 +1,48 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+syscfg.defs:
+    TINYCBOR_FLOAT_SUPPORT:
+        description: >
+            Enable support for encoding and decoding floating point values
+            (float and double).
+        value: 'MYNEWT_VAL_FLOAT_USER'
+    TINYCBOR_HALF_FLOAT_SUPPORT:
+        description: >
+            Enable support for encoding and decoding half-precision floating
+            point values.
+        value: 0
+        restrictions:
+            - 'TINYCBOR_FLOAT_SUPPORT if 1'
+    TINYCBOR_PARSER_MAX_RECURSIONS:
+        description: >
+            Maximum nesting level of containers supported by recursive parser
+            functions (validation, pretty printing).
+        value: 32
+    TINYCBOR_PRETTY_API:
+        description: >
+            Enable API for converting CBOR to human readable diagnostic
+            notation (cbor_value_to_pretty() and related functions).
+        value: 1
+    TINYCBOR_VALIDATION_API:
+        description: >
+            Enable API for validating CBOR stream (cbor_value_validate() and
+            related functions).
+        value: 1

Reply via email to