forked from aniani/vim
patch 8.1.0735: cannot handle binary data
Problem: Cannot handle binary data. Solution: Add the Blob type. (Yasuhiro Matsumoto, closes #3638)
This commit is contained in:
21
src/json.c
21
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)
|
||||
|
Reference in New Issue
Block a user