andrzej-kaczmarek commented on a change in pull request #1135: log: Add better 
support for long log entries in nmgr
URL: https://github.com/apache/mynewt-core/pull/1135#discussion_r190738242
 
 

 ##########
 File path: sys/log/full/src/log_nmgr.c
 ##########
 @@ -159,21 +129,41 @@ log_nmgr_encode_entry(struct log *log, struct log_offset 
*log_offset,
     case LOG_ETYPE_CBOR:
         g_err |= cbor_encode_text_stringz(&rsp, "type");
         g_err |= cbor_encode_text_stringz(&rsp, "cbor");
-        /* Just encode something short and CBOR stream will be inserted here 
later */
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        g_err |= cbor_encode_undefined(&rsp);
-        rsp_len += dlen;
         break;
-    case LOG_ETYPE_STRING:
     case LOG_ETYPE_BINARY:
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "bin");
+        break;
+    case LOG_ETYPE_STRING:
     default:
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        g_err |= cbor_encode_text_stringz(&rsp, data);
+        /* no need for type here */
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "str");
         break;
     }
+
+    g_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.
+     */
+    g_err |= cbor_encoder_create_indef_byte_string(&rsp, &str_encoder);
+    for (off = sizeof(ueh); (off < len) && !g_err; ) {
+        rc = log_read(log, dptr, data, off, sizeof(data));
+        if (rc < 0) {
+            g_err |= 1;
+            break;
+        }
+        g_err |= cbor_encode_byte_string(&str_encoder, data, rc);
+        off += rc;
+    }
+    g_err |= cbor_encoder_close_container(&rsp, &str_encoder);
 #else
     g_err |= cbor_encode_text_stringz(&rsp, "msg");
-    g_err |= cbor_encode_text_stringz(&rsp, data);
+    g_err |= cbor_encode_byte_string(&rsp, data, strlen((char *)data));
 
 Review comment:
   I just checked that `newtmgr` handles byte strings in v3 just fine so I just 
changed v2 to byte strings without much thinking about it. But I agree, let's 
keep v2 untouched - I'll change it back to text string.

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


With regards,
Apache Git Services

Reply via email to