You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/12/13 18:15:44 UTC

[2/4] incubator-mynewt-core git commit: cborattr; add helper routine cbor_read_flat_attrs(). This takes as argument pointer to beginning of cbor encoded data, and decodes it into an array of cbor_attr_t's.

cborattr; add helper routine cbor_read_flat_attrs().
This takes as argument pointer to beginning of cbor encoded data,
and decodes it into an array of cbor_attr_t's.


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/13613065
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/13613065
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/13613065

Branch: refs/heads/develop
Commit: 13613065a2d8e4cbfb7074303a8001e6b6a04027
Parents: c78e39b
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Tue Dec 13 10:07:02 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Tue Dec 13 10:15:21 2016 -0800

----------------------------------------------------------------------
 encoding/cborattr/include/cborattr/cborattr.h |  2 ++
 encoding/cborattr/src/cborattr.c              | 28 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13613065/encoding/cborattr/include/cborattr/cborattr.h
----------------------------------------------------------------------
diff --git a/encoding/cborattr/include/cborattr/cborattr.h b/encoding/cborattr/include/cborattr/cborattr.h
index d3ca2fa..d7f0e03 100644
--- a/encoding/cborattr/include/cborattr/cborattr.h
+++ b/encoding/cborattr/include/cborattr/cborattr.h
@@ -121,6 +121,8 @@ struct cbor_attr_t {
 int cbor_read_object(struct CborValue *, const struct cbor_attr_t *);
 int cbor_read_array(struct CborParser *, const struct cbor_array_t *);
 
+int cbor_read_flat_attrs(const uint8_t *data, int len,
+                         const struct cbor_attr_t *attrs);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/13613065/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index a7ca9c0..4101646 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -19,6 +19,7 @@
 
 #include <cborattr/cborattr.h>
 #include <tinycbor/cbor.h>
+#include <tinycbor/cbor_buf_reader.h>
 
 /* this maps a CborType to a matching CborAtter Type. The mapping is not
  * one-to-one because of signedness of integers
@@ -265,3 +266,30 @@ cbor_read_object(struct CborValue *value, const struct cbor_attr_t *attrs)
     st = cbor_internal_read_object(value, attrs, NULL, 0);
     return st;
 }
+
+/*
+ * Read in cbor key/values from flat buffer pointed by data, and fill them
+ * into attrs.
+ *
+ * @param data		Pointer to beginning of cbor encoded data
+ * @param len		Number of bytes in the buffer
+ * @param attrs		Array of cbor objects to look for.
+ *
+ * @return		0 on success; non-zero on failure.
+ */
+int
+cbor_read_flat_attrs(const uint8_t *data, int len,
+                     const struct cbor_attr_t *attrs)
+{
+    struct cbor_buf_reader reader;
+    struct CborParser parser;
+    struct CborValue value;
+    CborError err;
+
+    cbor_buf_reader_init(&reader, data, len);
+    err = cbor_parser_init(&reader.r, 0, &parser, &value);
+    if (err != CborNoError) {
+        return -1;
+    }
+    return cbor_read_object(&value, attrs);
+}