Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
15453:cdee6e827112 | 15454:1d2b5c016f17 |
---|---|
193 static int | 193 static int |
194 json_encode_item(garray_T *gap, typval_T *val, int copyID, int options) | 194 json_encode_item(garray_T *gap, typval_T *val, int copyID, int options) |
195 { | 195 { |
196 char_u numbuf[NUMBUFLEN]; | 196 char_u numbuf[NUMBUFLEN]; |
197 char_u *res; | 197 char_u *res; |
198 blob_T *b; | |
198 list_T *l; | 199 list_T *l; |
199 dict_T *d; | 200 dict_T *d; |
201 int i; | |
200 | 202 |
201 switch (val->v_type) | 203 switch (val->v_type) |
202 { | 204 { |
203 case VAR_SPECIAL: | 205 case VAR_SPECIAL: |
204 switch (val->vval.v_number) | 206 switch (val->vval.v_number) |
230 case VAR_JOB: | 232 case VAR_JOB: |
231 case VAR_CHANNEL: | 233 case VAR_CHANNEL: |
232 /* no JSON equivalent TODO: better error */ | 234 /* no JSON equivalent TODO: better error */ |
233 EMSG(_(e_invarg)); | 235 EMSG(_(e_invarg)); |
234 return FAIL; | 236 return FAIL; |
237 | |
238 case VAR_BLOB: | |
239 b = val->vval.v_blob; | |
240 if (b == NULL || b->bv_ga.ga_len == 0) | |
241 ga_concat(gap, (char_u *)"[]"); | |
242 else | |
243 { | |
244 ga_append(gap, '['); | |
245 for (i = 0; i < b->bv_ga.ga_len; i++) | |
246 { | |
247 if (i > 0) | |
248 ga_concat(gap, (char_u *)","); | |
249 vim_snprintf((char *)numbuf, NUMBUFLEN, "%d", | |
250 (int)blob_get(b, i)); | |
251 ga_concat(gap, numbuf); | |
252 } | |
253 ga_append(gap, ']'); | |
254 } | |
255 break; | |
235 | 256 |
236 case VAR_LIST: | 257 case VAR_LIST: |
237 l = val->vval.v_list; | 258 l = val->vval.v_list; |
238 if (l == NULL) | 259 if (l == NULL) |
239 ga_concat(gap, (char_u *)"[]"); | 260 ga_concat(gap, (char_u *)"[]"); |