Skip to content

Commit

Permalink
feat(msgpack): convert Blobs to BIN strings
Browse files Browse the repository at this point in the history
  • Loading branch information
seandewar committed Sep 15, 2021
1 parent ab82369 commit af6f454
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions runtime/doc/eval.txt
Expand Up @@ -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()*
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/nvim/eval/encode.c
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions test/functional/eval/msgpack_functions_spec.lua
Expand Up @@ -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": []}')
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit af6f454

Please sign in to comment.