aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/encode.c
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-02 18:59:55 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-15 21:19:29 +0100
commitab82369c8eb1bf6a58f848e7cb3fb3275d13ed8b (patch)
tree8472fd5ecf6f23e2cfe60f0293e8f126e2e6aa67 /src/nvim/eval/encode.c
parent312c783d81544df7ab3342f4b3316ced931e89b8 (diff)
downloadrneovim-ab82369c8eb1bf6a58f848e7cb3fb3275d13ed8b.tar.gz
rneovim-ab82369c8eb1bf6a58f848e7cb3fb3275d13ed8b.tar.bz2
rneovim-ab82369c8eb1bf6a58f848e7cb3fb3275d13ed8b.zip
feat(json): convert Blobs to array of byte values
Similiar to how Vim does it, but to be consistent with how Nvim encodes lists, add a space after every comma.
Diffstat (limited to 'src/nvim/eval/encode.c')
-rw-r--r--src/nvim/eval/encode.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c
index 45927db0ac..35a97d4f50 100644
--- a/src/nvim/eval/encode.c
+++ b/src/nvim/eval/encode.c
@@ -729,7 +729,25 @@ static inline int convert_to_json_string(garray_T *const gap,
#undef TYPVAL_ENCODE_CONV_BLOB
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
- abort() /* TODO(seandewar) */ \
+ do { \
+ const blob_T *const blob_ = (blob); \
+ const int len_ = (len); \
+ if (len_ == 0) { \
+ ga_concat(gap, "[]"); \
+ } else { \
+ ga_append(gap, '['); \
+ char numbuf[NUMBUFLEN]; \
+ for (int i_ = 0; i_ < len_; i_++) { \
+ if (i_ > 0) { \
+ ga_concat(gap, ", "); \
+ } \
+ vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "%d", \
+ (int)tv_blob_get(blob_, i_)); \
+ ga_concat(gap, numbuf); \
+ } \
+ ga_append(gap, ']'); \
+ } \
+ } while (0)
#undef TYPVAL_ENCODE_CONV_FUNC_START
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \