diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-02 19:27:52 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-15 21:19:30 +0100 |
commit | af6f454f5c3349821b20bd2f0d846f7ae7343e2e (patch) | |
tree | 5d1a8e10ee22c45f3b85e37cb6ec86030bd68f29 | |
parent | ab82369c8eb1bf6a58f848e7cb3fb3275d13ed8b (diff) | |
download | rneovim-af6f454f5c3349821b20bd2f0d846f7ae7343e2e.tar.gz rneovim-af6f454f5c3349821b20bd2f0d846f7ae7343e2e.tar.bz2 rneovim-af6f454f5c3349821b20bd2f0d846f7ae7343e2e.zip |
feat(msgpack): convert Blobs to BIN strings
-rw-r--r-- | runtime/doc/eval.txt | 4 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 8 | ||||
-rw-r--r-- | test/functional/eval/msgpack_functions_spec.lua | 8 |
3 files changed, 17 insertions, 3 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 165d48eb42..e7820f5313 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -6692,7 +6692,7 @@ msgpackdump({list}) *msgpackdump()* 1. |Funcref|s cannot be dumped. 2. Containers that reference themselves cannot be dumped. 3. Dictionary keys are always dumped as STR strings. - 4. Other strings are always dumped as BIN strings. + 4. Other strings and |Blob|s are always dumped as BIN strings. 5. Points 3. and 4. do not apply to |msgpack-special-dict|s. msgpackparse({list}) *msgpackparse()* @@ -6706,7 +6706,7 @@ msgpackparse({list}) *msgpackparse()* Limitations: 1. Mapping ordering is not preserved unless messagepack - mapping is dumped using generic mapping + mapping is dumped using generic mapping (|msgpack-special-map|). 2. Since the parser aims to preserve all data untouched (except for 1.) some strings are parsed to diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 35a97d4f50..b6b37fce84 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -950,7 +950,13 @@ char *encode_tv2json(typval_T *tv, size_t *len) } while (0) #define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \ - abort() /* TODO(seandewar) */ \ + do { \ + const size_t len_ = (size_t)(len); \ + msgpack_pack_bin(packer, len_); \ + if (len_ > 0) { \ + msgpack_pack_bin_body(packer, (blob)->bv_ga.ga_data, len_); \ + } \ + } while (0) #define TYPVAL_ENCODE_CONV_NUMBER(tv, num) \ msgpack_pack_int64(packer, (int64_t)(num)) diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index a8a413f68b..90e3ccc0e4 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -517,6 +517,10 @@ describe('msgpackdump() function', function() eq({"\196\004Test"}, eval('msgpackdump(obj)')) end) + it('dumps blob as BIN 8', function() + eq({'\196\005Bl\nb!'}, eval('msgpackdump([0z426c006221])')) + end) + it('can dump generic mapping with generic mapping keys and values', function() command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []}') @@ -716,6 +720,10 @@ describe('msgpackdump() function', function() eq({'\160'}, eval('msgpackdump([{"_TYPE": v:msgpack_types.string, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}])')) end) + it('can dump NULL blob', function() + eq({'\196\n'}, eval('msgpackdump([v:_null_blob])')) + end) + it('can dump NULL list', function() eq({'\144'}, eval('msgpackdump([v:_null_list])')) end) |