[mynewt-mcumgr] 07/42: cborattr library
This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git commit 06d963b12f0ec3c9e747d107b6021473974d9105 Author: Christopher CollinsAuthorDate: Wed Jan 17 17:13:14 2018 -0800 cborattr library This is used for parsing incoming mcumgr requests. Destructures mcumgr packets and populates corresponding field variables. This comes from Apache Mynewt. --- cborattr/CMakeLists.txt| 7 + cborattr/include/cborattr/cborattr.h | 153 cborattr/pkg.yml | 29 ++ cborattr/src/cborattr.c| 423 + cborattr/syscfg.yml| 24 ++ cborattr/test/pkg.yml | 30 ++ cborattr/test/src/test_cborattr.c | 49 +++ cborattr/test/src/test_cborattr.h | 57 +++ cborattr/test/src/test_cborattr_utils.c| 35 ++ cborattr/test/src/testcases/cborattr_decode1.c | 83 .../src/testcases/cborattr_decode_bool_array.c | 101 + .../test/src/testcases/cborattr_decode_int_array.c | 143 +++ .../test/src/testcases/cborattr_decode_obj_array.c | 109 ++ .../test/src/testcases/cborattr_decode_object.c| 198 ++ .../src/testcases/cborattr_decode_object_array.c | 126 ++ .../test/src/testcases/cborattr_decode_partial.c | 47 +++ .../test/src/testcases/cborattr_decode_simple.c| 123 ++ .../src/testcases/cborattr_decode_string_array.c | 135 +++ .../src/testcases/cborattr_decode_substring_key.c | 111 ++ .../src/testcases/cborattr_decode_unnamed_array.c | 99 + 20 files changed, 2082 insertions(+) diff --git a/cborattr/CMakeLists.txt b/cborattr/CMakeLists.txt new file mode 100644 index 000..2f22bd0 --- /dev/null +++ b/cborattr/CMakeLists.txt @@ -0,0 +1,7 @@ +target_include_directories(MCUMGR INTERFACE +include +) + +zephyr_library_sources( +cborattr/src/cborattr.c +) diff --git a/cborattr/include/cborattr/cborattr.h b/cborattr/include/cborattr/cborattr.h new file mode 100644 index 000..1cc14b3 --- /dev/null +++ b/cborattr/include/cborattr/cborattr.h @@ -0,0 +1,153 @@ +/* + * 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 CBORATTR_H +#define CBORATTR_H + +#include +#include +#include +#include +#include +#include "cbor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* This library wraps the tinycbor decoder with a attribute based decoder + * suitable for decoding a binary version of json. Specifically, the + * contents of the cbor contains pairs of attributes. where the attribute + * is a key/value pair. keys are always text strings, but values can be + * many different things (enumerated below) */ + +typedef enum CborAttrType { +CborAttrIntegerType = 1, +CborAttrUnsignedIntegerType, +CborAttrByteStringType, +CborAttrTextStringType, +CborAttrBooleanType, +CborAttrFloatType, +CborAttrDoubleType, +CborAttrArrayType, +CborAttrObjectType, +CborAttrStructObjectType, +CborAttrNullType, +} CborAttrType; + +struct cbor_attr_t; + +struct cbor_enum_t { +char *name; +long long int value; +}; + +struct cbor_array_t { +CborAttrType element_type; +union { +struct { +const struct cbor_attr_t *subtype; +char *base; +size_t stride; +} objects; +struct { +char **ptrs; +char *store; +int storelen; +} strings; +struct { +long long int *store; +} integers; +struct { +long long unsigned int *store; +} uintegers; +struct { +double *store; +} reals; +struct { +bool *store; +} booleans; +} arr; +int *count; +int maxlen; +}; + +struct cbor_attr_t { +char *attribute; +CborAttrType type; +union { +long long int *integer; +long long unsigned int *uinteger; +double *real; +float *fval; +
[mynewt-mcumgr] 07/42: cborattr library
This is an automated email from the ASF dual-hosted git repository. ccollins pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-mcumgr.git commit 1636f65725542693ed1d2941b58c6d6485ff055b Author: Christopher CollinsAuthorDate: Wed Jan 17 17:13:14 2018 -0800 cborattr library This is used for parsing incoming mcumgr requests. Destructures mcumgr packets and populates corresponding field variables. This comes from Apache Mynewt. --- cborattr/CMakeLists.txt| 7 + cborattr/include/cborattr/cborattr.h | 153 cborattr/pkg.yml | 29 ++ cborattr/src/cborattr.c| 423 + cborattr/syscfg.yml| 24 ++ cborattr/test/pkg.yml | 30 ++ cborattr/test/src/test_cborattr.c | 49 +++ cborattr/test/src/test_cborattr.h | 57 +++ cborattr/test/src/test_cborattr_utils.c| 35 ++ cborattr/test/src/testcases/cborattr_decode1.c | 83 .../src/testcases/cborattr_decode_bool_array.c | 101 + .../test/src/testcases/cborattr_decode_int_array.c | 143 +++ .../test/src/testcases/cborattr_decode_obj_array.c | 109 ++ .../test/src/testcases/cborattr_decode_object.c| 198 ++ .../src/testcases/cborattr_decode_object_array.c | 126 ++ .../test/src/testcases/cborattr_decode_partial.c | 47 +++ .../test/src/testcases/cborattr_decode_simple.c| 123 ++ .../src/testcases/cborattr_decode_string_array.c | 135 +++ .../src/testcases/cborattr_decode_substring_key.c | 111 ++ .../src/testcases/cborattr_decode_unnamed_array.c | 99 + 20 files changed, 2082 insertions(+) diff --git a/cborattr/CMakeLists.txt b/cborattr/CMakeLists.txt new file mode 100644 index 000..2f22bd0 --- /dev/null +++ b/cborattr/CMakeLists.txt @@ -0,0 +1,7 @@ +target_include_directories(MCUMGR INTERFACE +include +) + +zephyr_library_sources( +cborattr/src/cborattr.c +) diff --git a/cborattr/include/cborattr/cborattr.h b/cborattr/include/cborattr/cborattr.h new file mode 100644 index 000..1cc14b3 --- /dev/null +++ b/cborattr/include/cborattr/cborattr.h @@ -0,0 +1,153 @@ +/* + * 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 CBORATTR_H +#define CBORATTR_H + +#include +#include +#include +#include +#include +#include "cbor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* This library wraps the tinycbor decoder with a attribute based decoder + * suitable for decoding a binary version of json. Specifically, the + * contents of the cbor contains pairs of attributes. where the attribute + * is a key/value pair. keys are always text strings, but values can be + * many different things (enumerated below) */ + +typedef enum CborAttrType { +CborAttrIntegerType = 1, +CborAttrUnsignedIntegerType, +CborAttrByteStringType, +CborAttrTextStringType, +CborAttrBooleanType, +CborAttrFloatType, +CborAttrDoubleType, +CborAttrArrayType, +CborAttrObjectType, +CborAttrStructObjectType, +CborAttrNullType, +} CborAttrType; + +struct cbor_attr_t; + +struct cbor_enum_t { +char *name; +long long int value; +}; + +struct cbor_array_t { +CborAttrType element_type; +union { +struct { +const struct cbor_attr_t *subtype; +char *base; +size_t stride; +} objects; +struct { +char **ptrs; +char *store; +int storelen; +} strings; +struct { +long long int *store; +} integers; +struct { +long long unsigned int *store; +} uintegers; +struct { +double *store; +} reals; +struct { +bool *store; +} booleans; +} arr; +int *count; +int maxlen; +}; + +struct cbor_attr_t { +char *attribute; +CborAttrType type; +union { +long long int *integer; +long long unsigned int *uinteger; +double *real; +float *fval; +