summaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-12 22:47:31 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-12 22:47:31 +0100
commit6e5ea8d2a995b32bbc5972edc4f827b959f2702f (patch)
treeb1ad7d6a83f53220227122719d5eb97dd32ff1e6 /src/json.c
parente3c74d249ac36404d8af25f74baf335d143b30e3 (diff)
downloadvim-git-6e5ea8d2a995b32bbc5972edc4f827b959f2702f.tar.gz
patch 8.1.0735: cannot handle binary datav8.1.0735
Problem: Cannot handle binary data. Solution: Add the Blob type. (Yasuhiro Matsumoto, closes #3638)
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index d9da10d35..d8ccfe8fb 100644
--- a/src/json.c
+++ b/src/json.c
@@ -195,8 +195,10 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
{
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 *val, int copyID, int options)
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)