aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/encode.c
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2020-12-02 17:24:15 +0000
committerSean Dewar <seandewar@users.noreply.github.com>2021-09-15 22:30:30 +0100
commit6a02ccc2226ab427d7e6243a5b6d3e424557b0fd (patch)
treec13befa39d12386b8c665c4804b2857d5a6dff74 /src/nvim/eval/encode.c
parent0eadd7e5fd4603fef313fd5fb4cced1b7b5f1679 (diff)
downloadrneovim-6a02ccc2226ab427d7e6243a5b6d3e424557b0fd.tar.gz
rneovim-6a02ccc2226ab427d7e6243a5b6d3e424557b0fd.tar.bz2
rneovim-6a02ccc2226ab427d7e6243a5b6d3e424557b0fd.zip
vim-patch:8.1.0765: string format of a Blob can't be parsed back
Problem: String format of a Blob can't be parsed back. Solution: Use 0z format. https://github.com/vim/vim/commit/4131fd5509b283e978e8c6161f09643b64719787
Diffstat (limited to 'src/nvim/eval/encode.c')
-rw-r--r--src/nvim/eval/encode.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c
index b6b37fce84..1c2274c410 100644
--- a/src/nvim/eval/encode.c
+++ b/src/nvim/eval/encode.c
@@ -324,20 +324,22 @@ int encode_read_from_list(ListReaderState *const state, char *const buf,
const blob_T *const blob_ = (blob); \
const int len_ = (len); \
if (len_ == 0) { \
- ga_concat(gap, "[]"); \
+ ga_concat(gap, "0z"); \
} else { \
- ga_grow(gap, 1 + len_ * 5); \
- ga_append(gap, '['); \
+ /* Allocate space for "0z", the two hex chars per byte, and a */ \
+ /* "." separator after every eight hex chars. */ \
+ /* Example: "0z00112233.44556677.8899" */ \
+ ga_grow(gap, 2 + 2 * len_ + (len_ - 1) / 4); \
+ ga_concat(gap, "0z"); \
char numbuf[NUMBUFLEN]; \
for (int i_ = 0; i_ < len_; i_++) { \
- if (i_ > 0) { \
- ga_append(gap, ','); \
+ if (i_ > 0 && (i_ & 3) == 0) { \
+ ga_append(gap, '.'); \
} \
- vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "0x%02X", \
+ vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "%02X", \
(int)tv_blob_get(blob_, i_)); \
ga_concat(gap, numbuf); \
} \
- ga_append(gap, ']'); \
} \
} while (0)