diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-06-25 15:33:47 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2024-06-27 11:04:04 +0200 |
commit | bda63d5b97dfb333de6f4bd757dbb978906062a2 (patch) | |
tree | 65b2460064f42b39e33bf7bc7507f973b907dd37 /runtime/autoload/msgpack.vim | |
parent | 9e436251de0329b1479365ff162d87ef18d6d14c (diff) | |
download | rneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.tar.gz rneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.tar.bz2 rneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.zip |
refactor(typval)!: remove distinction of binary and nonbinary strings
This is a breaking change which will make refactor of typval and shada
code a lot easier. In particular, code that would use or check for
v:msgpack_types.binary in the wild would be broken. This appears to be
rarely used in existing plugins.
Also some cases where v:msgpack_type.string would be used to represent a
binary string of "string" type, we use a BLOB instead, which is
vimscripts native type for binary blobs, and already was used for BIN
formats when necessary.
msgpackdump(msgpackparse(data)) no longer preserves the distinction
of BIN and STR strings. This is very common behavior for
language-specific msgpack bindings. Nvim uses msgpack as a tool to
serialize its data. Nvim is not a tool to bit-perfectly manipulate
arbitrary msgpack data out in the wild.
The changed tests should indicate how behavior changes in various edge
cases.
Diffstat (limited to 'runtime/autoload/msgpack.vim')
-rw-r--r-- | runtime/autoload/msgpack.vim | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/runtime/autoload/msgpack.vim b/runtime/autoload/msgpack.vim index 18dcd1e6a6..fb438def4f 100644 --- a/runtime/autoload/msgpack.vim +++ b/runtime/autoload/msgpack.vim @@ -361,7 +361,7 @@ endfunction let s:MSGPACK_STANDARD_TYPES = { \type(0): 'integer', \type(0.0): 'float', - \type(''): 'binary', + \type(''): 'string', \type([]): 'array', \type({}): 'map', \type(v:true): 'boolean', @@ -412,9 +412,15 @@ endfunction "" " Dump |msgpack-special-dict| that represents a string. If any additional " parameter is given then it dumps binary string. -function s:msgpack_dump_string(v, ...) abort - let ret = [a:0 ? '"' : '="'] - for v in a:v._VAL +function s:msgpack_dump_string(v) abort + if type(a:v) == type({}) + let val = a:v + else + let val = {'_VAL': split(a:v, "\n", 1)} + end + + let ret = ['"'] + for v in val._VAL call add( \ret, \substitute( @@ -427,16 +433,6 @@ function s:msgpack_dump_string(v, ...) abort endfunction "" -" Dump binary string. -function s:msgpack_dump_binary(v) abort - if type(a:v) == type({}) - return s:msgpack_dump_string(a:v, 1) - else - return s:msgpack_dump_string({'_VAL': split(a:v, "\n", 1)}, 1) - endif -endfunction - -"" " Dump array value. function s:msgpack_dump_array(v) abort let val = type(a:v) == type({}) ? a:v._VAL : a:v @@ -449,7 +445,7 @@ function s:msgpack_dump_map(v) abort let ret = ['{'] if msgpack#special_type(a:v) is 0 for [k, v] in items(a:v) - let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n", 1)}), + let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n")}), \': ', \msgpack#string(v), \', '] @@ -479,7 +475,7 @@ endfunction " Dump extension value. function s:msgpack_dump_ext(v) abort return printf('+(%i)%s', a:v._VAL[0], - \s:msgpack_dump_string({'_VAL': a:v._VAL[1]}, 1)) + \s:msgpack_dump_string({'_VAL': a:v._VAL[1]})) endfunction "" @@ -619,9 +615,7 @@ function msgpack#eval(s, special_objs) abort throw '"-invalid:Invalid string: ' . s endif call add(expr, '{''_TYPE'': v:msgpack_types.') - if empty(match[1]) - call add(expr, 'binary') - elseif match[1] is# '=' + if empty(match[1]) || match[1] is# '=' call add(expr, 'string') else call add(expr, 'ext') @@ -772,7 +766,7 @@ function msgpack#equal(a, b) let a = aspecial is 0 ? a:a : a:a._VAL let b = bspecial is 0 ? a:b : a:b._VAL return msgpack#equal(a, b) - elseif atype is# 'binary' + elseif atype is# 'string' let a = (aspecial is 0 ? split(a:a, "\n", 1) : a:a._VAL) let b = (bspecial is 0 ? split(a:b, "\n", 1) : a:b._VAL) return a ==# b @@ -787,13 +781,17 @@ function msgpack#equal(a, b) " Non-special mapping cannot have non-string keys return 0 endif - if (empty(k._VAL) - \|| k._VAL ==# [""] - \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1'))) - " Non-special mapping cannot have zero byte in key or an empty key - return 0 + if type(k) == type({}) + if (empty(k._VAL) + \|| k._VAL ==# [""] + \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1'))) + " Non-special mapping cannot have zero byte in key or an empty key + return 0 + endif + let kstr = join(k._VAL, "\n") + else + let kstr = k endif - let kstr = join(k._VAL, "\n") if !has_key(akeys, kstr) " Protects from both missing and duplicate keys return 0 |