diff src/json.c @ 15454:1d2b5c016f17 v8.1.0735

patch 8.1.0735: cannot handle binary data commit https://github.com/vim/vim/commit/6e5ea8d2a995b32bbc5972edc4f827b959f2702f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 12 22:47:31 2019 +0100 patch 8.1.0735: cannot handle binary data Problem: Cannot handle binary data. Solution: Add the Blob type. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/3638)
author Bram Moolenaar <Bram@vim.org>
date Sat, 12 Jan 2019 23:00:06 +0100
parents 8ac454818352
children 55ccc2d353bd
line wrap: on
line diff
--- a/src/json.c
+++ b/src/json.c
@@ -195,8 +195,10 @@ json_encode_item(garray_T *gap, typval_T
 {
     char_u	numbuf[NUMBUFLEN];
     char_u	*res;
+    blob_T	*b;
     list_T	*l;
     dict_T	*d;
+    int		i;
 
     switch (val->v_type)
     {
@@ -233,6 +235,25 @@ json_encode_item(garray_T *gap, typval_T
 	    EMSG(_(e_invarg));
 	    return FAIL;
 
+	case VAR_BLOB:
+	    b = val->vval.v_blob;
+	    if (b == NULL || b->bv_ga.ga_len == 0)
+		ga_concat(gap, (char_u *)"[]");
+	    else
+	    {
+		ga_append(gap, '[');
+		for (i = 0; i < b->bv_ga.ga_len; i++)
+		{
+		    if (i > 0)
+			ga_concat(gap, (char_u *)",");
+		    vim_snprintf((char *)numbuf, NUMBUFLEN, "%d",
+			    (int)blob_get(b, i));
+		    ga_concat(gap, numbuf);
+		}
+		ga_append(gap, ']');
+	    }
+	    break;
+
 	case VAR_LIST:
 	    l = val->vval.v_list;
 	    if (l == NULL)