feat(msgpack): convert Blobs to BIN strings

This commit is contained in:
Sean Dewar 2021-08-02 19:27:52 +01:00
parent ab82369c8e
commit af6f454f5c
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
3 changed files with 17 additions and 3 deletions

View File

@ -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

View File

@ -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))

View File

@ -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)