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_r330781385
 
 

 ##########
 File path: cmd/log_mgmt/src/log_mgmt.c
 ##########
 @@ -63,36 +65,74 @@ static int
 log_mgmt_encode_entry(CborEncoder *enc, const struct log_mgmt_entry *entry,
                       size_t *out_len)
 {
-    CborEncoder entry_enc;
-    CborError err;
+    CborError err = CborNoError;
+    CborEncoder rsp;
+    CborEncoder str_encoder;
+    uint16_t len;
+    int off;
+
+    len = cbor_encode_bytes_written(enc);
+
+    err |= cbor_encoder_create_map(enc, &rsp, CborIndefiniteLength);
+
+    switch (entry->type) {
+    case LOG_MGMT_ETYPE_CBOR:
+        err |= cbor_encode_text_stringz(&rsp, "type");
+        err |= cbor_encode_text_stringz(&rsp, "cbor");
+        break;
+    case LOG_MGMT_ETYPE_BINARY:
+        err |= cbor_encode_text_stringz(&rsp, "type");
+        err |= cbor_encode_text_stringz(&rsp, "bin");
+        break;
+    case LOG_MGMT_ETYPE_STRING:
+        err |= cbor_encode_text_stringz(&rsp, "type");
+        err |= cbor_encode_text_stringz(&rsp, "str");
+        break;
+    default:
+        cbor_encoder_close_container(&rsp, &str_encoder);
+        return MGMT_ERR_ECORRUPT;
+    }
 
-    err = 0;
-    err |= cbor_encoder_create_map(enc, &entry_enc, 5);
-    err |= cbor_encode_text_stringz(&entry_enc, "msg");
-    err |= cbor_encode_byte_string(&entry_enc, entry->data, entry->len);
-    err |= cbor_encode_text_stringz(&entry_enc, "ts");
-    err |= cbor_encode_int(&entry_enc, entry->ts);
-    err |= cbor_encode_text_stringz(&entry_enc, "level");
-    err |= cbor_encode_uint(&entry_enc, entry->level);
-    err |= cbor_encode_text_stringz(&entry_enc, "index");
-    err |= cbor_encode_uint(&entry_enc, entry->index);
-    err |= cbor_encode_text_stringz(&entry_enc, "module");
-    err |= cbor_encode_uint(&entry_enc, entry->module);
-    err |= cbor_encoder_close_container(enc, &entry_enc);
+    err |= cbor_encode_text_stringz(&rsp, "msg");
+
+    /*
+     * Write entry data as byte string. Since this may not fit into single
+     * chunk of data we will write as indefinite-length byte string which is
+     * basically a indefinite-length container with definite-length strings
+     * inside.
+     */
+    err |= cbor_encoder_create_indef_byte_string(&rsp, &str_encoder);
+    for (off = 0; off < entry->len && !err; ) {
+        err |= cbor_encode_byte_string(&str_encoder, entry->data, entry->len);
+        off += entry->len;
+    }
 
 Review comment:
   This code has changed now, I found another issue which was lingering. so, I 
am going to mark it as 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