vrahane commented on a change in pull request #27: Update mynewt port of mcumgr 
and various fixes
URL: https://github.com/apache/mynewt-mcumgr/pull/27#discussion_r330782085
 
 

 ##########
 File path: cborattr/src/cborattr.c
 ##########
 @@ -421,4 +437,181 @@ cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, 
uint16_t len,
     }
     return cbor_read_object(&value, attrs);
 }
+
+static int
+cbor_write_arr_val(struct CborEncoder *enc,
+                   const struct cbor_out_arr_val_t *arr)
+{
+    struct CborEncoder arr_enc;
+    size_t i;
+    int rc;
+
+    rc = cbor_encoder_create_array(enc, &arr_enc, arr->len);
+    if (rc != 0) {
+        return SYS_ENOMEM;
+    }
+
+    for (i = 0; i < arr->len; i++) {
+        rc = cbor_write_val(&arr_enc, &arr->elems[i]);
+        if (rc != 0) {
+            return SYS_ENOMEM;
+        }
+    }
+
+    rc = cbor_encoder_close_container(enc, &arr_enc);
+    if (rc != 0) {
+        return SYS_ENOMEM;
+    }
+
+    return 0;
+}
+
+static int
+cbor_write_val(struct CborEncoder *enc, const struct cbor_out_val_t *val)
+{
+    int len;
+    int rc;
+
+    switch (val->type) {
+    case CborAttrNullType:
+        rc = cbor_encode_null(enc);
+        break;
+
+    case CborAttrBooleanType:
+        rc = cbor_encode_boolean(enc, val->boolean);
+        break;
+
+    case CborAttrIntegerType:
+        rc = cbor_encode_int(enc, val->integer);
+        break;
+
+    case CborAttrUnsignedIntegerType:
+        rc = cbor_encode_uint(enc, val->uinteger);
+        break;
+
+#if FLOAT_SUPPORT
+    case CborAttrFloatType:
+        rc = cbor_encode_float(enc, val->fval);
+        break;
+
+    case CborAttrDoubleType:
+        rc = cbor_encode_double(enc, val->real);
+        break;
+#endif
+
+    case CborAttrByteStringType:
+        if (val->bytestring.data == NULL &&
+            val->bytestring.len != 0) {
+
+            return SYS_EINVAL;
+        }
+
+        rc = cbor_encode_byte_string(enc, val->bytestring.data,
+                                     val->bytestring.len);
+        break;
+
+    case CborAttrTextStringType:
+        if (val->string == NULL) {
+            len = 0;
+        } else {
+            len = strlen(val->string);
+        }
+        rc = cbor_encode_text_string(enc, val->string, len);
+        break;
+
+    case CborAttrObjectType:
+        rc = cbor_write_object(enc, val->obj);
+        break;
+
+    case CborAttrArrayType:
+        rc = cbor_write_arr_val(enc, &val->array);
+        break;
+
+    default:
+        return SYS_ENOTSUP;
+    }
+
+    if (rc != 0) {
+        return SYS_ENOMEM;
+    }
+
+    return 0;
+}
+
+static int
+cbor_write_attr(struct CborEncoder *enc, const struct cbor_out_attr_t *attr)
+{
+    int len;
+    int rc;
+
+    if (attr->omit) {
+        return 0;
+    }
+
+    len = strlen(attr->attribute);
+    rc = cbor_encode_text_string(enc, attr->attribute, len);
 
 Review comment:
   done

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to