Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 28a8d7c39 -> 826fd665f


cborattr; add routine that takes mbuf and attributes and decodes the
data from that mbuf.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5711060f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5711060f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5711060f

Branch: refs/heads/develop
Commit: 5711060f07e5f5714eb8bdd97d34e94bac929a34
Parents: 15b7d4f
Author: Marko Kiiskila <[email protected]>
Authored: Fri Jan 6 11:21:26 2017 -0800
Committer: Marko Kiiskila <[email protected]>
Committed: Fri Jan 6 15:02:59 2017 -0800

----------------------------------------------------------------------
 encoding/cborattr/include/cborattr/cborattr.h |  3 +++
 encoding/cborattr/src/cborattr.c              | 29 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5711060f/encoding/cborattr/include/cborattr/cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/include/cborattr/cborattr.h 
b/encoding/cborattr/include/cborattr/cborattr.h
index 478c68d..7142df6 100644
--- a/encoding/cborattr/include/cborattr/cborattr.h
+++ b/encoding/cborattr/include/cborattr/cborattr.h
@@ -147,6 +147,9 @@ int cbor_read_array(struct CborValue *, const struct 
cbor_array_t *);
 
 int cbor_read_flat_attrs(const uint8_t *data, int len,
                          const struct cbor_attr_t *attrs);
+struct os_mbuf;
+int cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
+                         const struct cbor_attr_t *attrs);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5711060f/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index 6329753..e78c8f9 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -20,6 +20,7 @@
 #include <cborattr/cborattr.h>
 #include <tinycbor/cbor.h>
 #include <tinycbor/cbor_buf_reader.h>
+#include <tinycbor/cbor_mbuf_reader.h>
 
 /* this maps a CborType to a matching CborAtter Type. The mapping is not
  * one-to-one because of signedness of integers
@@ -386,3 +387,31 @@ cbor_read_flat_attrs(const uint8_t *data, int len,
     }
     return cbor_read_object(&value, attrs);
 }
+
+/*
+ * Read in cbor key/values from os_mbuf pointed by m, and fill them
+ * into attrs.
+ *
+ * @param m            Pointer to os_mbuf containing cbor encoded data
+ * @param off          Offset into mbuf where cbor data begins
+ * @param len          Number of bytes to decode
+ * @param attrs                Array of cbor objects to look for.
+ *
+ * @return             0 on success; non-zero on failure.
+ */
+int
+cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
+                     const struct cbor_attr_t *attrs)
+{
+    struct cbor_mbuf_reader cmr;
+    struct CborParser parser;
+    struct CborValue value;
+    CborError err;
+
+    cbor_mbuf_reader_init(&cmr, m, off);
+    err = cbor_parser_init(&cmr.r, 0, &parser, &value);
+    if (err != CborNoError) {
+        return -1;
+    }
+    return cbor_read_object(&value, attrs);
+}

Reply via email to