Macros | Functions | Variables
encode.c File Reference
#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <msgpack.h>
#include <stddef.h>
#include "nvim/ascii.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/typval_encode.h"
#include "nvim/garray.h"
#include "nvim/lib/kvec.h"
#include "nvim/macros.h"
#include "nvim/mbyte.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/vim.h"
#include "nvim/eval/typval_encode.c.h"

Macros

#define utf_char2len(b)   ((size_t)utf_char2len(b))
 
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len)   TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type)
 
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len)
 
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num)
 
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt)
 
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_END(tv)   ga_append(gap, ')')
 
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv)   ga_concat(gap, "[]")
 
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len)   ga_append(gap, '[')
 
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
 
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict)   ga_concat(gap, "{}")
 
#define TYPVAL_ENCODE_CONV_NIL(tv)   ga_concat(gap, "v:null")
 
#define TYPVAL_ENCODE_CONV_BOOL(tv, num)   ga_concat(gap, ((num)? "v:true": "v:false"))
 
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num)
 
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len)   ga_append(gap, '{')
 
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv)
 
#define TYPVAL_ENCODE_CONV_DICT_END(tv, dict)   ga_append(gap, '}')
 
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(tv, dict)   ga_concat(gap, ": ")
 
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)   ga_concat(gap, ", ")
 
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key)
 
#define TYPVAL_ENCODE_CONV_LIST_END(tv)   ga_append(gap, ']')
 
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv)   TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, NULL)
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)
 
#define TYPVAL_ENCODE_ALLOW_SPECIALS   false
 
#define TYPVAL_ENCODE_SCOPE   static
 
#define TYPVAL_ENCODE_NAME   string
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)
 
#define TYPVAL_ENCODE_SCOPE
 
#define TYPVAL_ENCODE_NAME   echo
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)
 
#define TYPVAL_ENCODE_ALLOW_SPECIALS   true
 
#define TYPVAL_ENCODE_CONV_NIL(tv)   ga_concat(gap, "null")
 
#define TYPVAL_ENCODE_CONV_BOOL(tv, num)   ga_concat(gap, ((num)? "true": "false"))
 
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num)
 
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt)
 
#define ENCODE_RAW(ch)   (ch >= 0x20 && utf_printable(ch))
 
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type)
 
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun)
 
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key)
 
#define TYPVAL_ENCODE_SCOPE   static
 
#define TYPVAL_ENCODE_NAME   json
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
 
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_STR_STRING(tv, buf, len)
 
#define TYPVAL_ENCODE_CONV_EXT_STRING(tv, buf, len, type)
 
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len)
 
#define TYPVAL_ENCODE_CONV_NUMBER(tv, num)   msgpack_pack_int64(packer, (int64_t)(num))
 
#define TYPVAL_ENCODE_CONV_FLOAT(tv, flt)   msgpack_pack_double(packer, (double)(flt))
 
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF(tv, len)
 
#define TYPVAL_ENCODE_CONV_FUNC_END(tv)
 
#define TYPVAL_ENCODE_CONV_EMPTY_LIST(tv)   msgpack_pack_array(packer, 0)
 
#define TYPVAL_ENCODE_CONV_LIST_START(tv, len)   msgpack_pack_array(packer, (size_t)(len))
 
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START(tv, mpsv)
 
#define TYPVAL_ENCODE_CONV_EMPTY_DICT(tv, dict)   msgpack_pack_map(packer, 0)
 
#define TYPVAL_ENCODE_CONV_NIL(tv)   msgpack_pack_nil(packer)
 
#define TYPVAL_ENCODE_CONV_BOOL(tv, num)
 
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER(tv, num)   msgpack_pack_uint64(packer, (num))
 
#define TYPVAL_ENCODE_CONV_DICT_START(tv, dict, len)   msgpack_pack_map(packer, (size_t)(len))
 
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START(tv, dict, mpsv)
 
#define TYPVAL_ENCODE_CONV_DICT_END(tv, dict)
 
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY(tv, dict)
 
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, dict)
 
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK(label, key)
 
#define TYPVAL_ENCODE_CONV_LIST_END(tv)
 
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS(tv)
 
#define TYPVAL_ENCODE_CONV_RECURSE(val, conv_type)
 
#define TYPVAL_ENCODE_ALLOW_SPECIALS   true
 
#define TYPVAL_ENCODE_SCOPE
 
#define TYPVAL_ENCODE_NAME   msgpack
 
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   msgpack_packer *const
 
#define TYPVAL_ENCODE_FIRST_ARG_NAME   packer
 

Functions

int encode_blob_write (void *const data, const char *const buf, const size_t len) FUNC_ATTR_NONNULL_ARG(1)
 Msgpack callback for writing to a Blob. More...
 
int encode_list_write (void *const data, const char *const buf, const size_t len) FUNC_ATTR_NONNULL_ARG(1)
 Msgpack callback for writing to readfile()-style list. More...
 
bool encode_vim_list_to_buf (const list_T *const list, size_t *const ret_len, char **const ret_buf) FUNC_ATTR_NONNULL_ARG(2
 
 TV_LIST_ITER_CONST (list, li, { if(TV_LIST_ITEM_TV(li) ->v_type !=VAR_STRING) { return false;} len++;if(TV_LIST_ITEM_TV(li) ->vval.v_string !=NULL) { len+=STRLEN(TV_LIST_ITEM_TV(li) ->vval.v_string);} })
 
 if (len)
 
 if (encode_read_from_list(&lrstate, buf, len, &read_bytes) !=OK)
 
 assert (len==read_bytes)
 
int encode_read_from_list (ListReaderState *const state, char *const buf, const size_t nbuf, size_t *const read_bytes) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
bool encode_check_json_key (const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
 
char * encode_tv2string (typval_T *tv, size_t *len) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC
 
char * encode_tv2echo (typval_T *tv, size_t *len) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC
 
char * encode_tv2json (typval_T *tv, size_t *len) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC
 

Variables

const char *const encode_bool_var_names []
 Array mapping values from SpecialVarValue enum to names. More...
 
const char *const encode_special_var_names []
 
bool FUNC_ATTR_WARN_UNUSED_RESULT
 
ret_len = len
 
ListReaderState lrstate = encode_init_lrstate(list)
 
char *const buf = xmalloc(len)
 
size_t read_bytes
 
ret_buf = buf
 
return true
 

Detailed Description

File containing functions for encoding and decoding VimL values.

Split out from eval.c.

Macro Definition Documentation

◆ ENCODE_RAW

#define ENCODE_RAW (   ch)    (ch >= 0x20 && utf_printable(ch))

◆ TYPVAL_ENCODE_ALLOW_SPECIALS [1/3]

#define TYPVAL_ENCODE_ALLOW_SPECIALS   false

◆ TYPVAL_ENCODE_ALLOW_SPECIALS [2/3]

#define TYPVAL_ENCODE_ALLOW_SPECIALS   true

◆ TYPVAL_ENCODE_ALLOW_SPECIALS [3/3]

#define TYPVAL_ENCODE_ALLOW_SPECIALS   true

◆ TYPVAL_ENCODE_CONV_BLOB [1/3]

#define TYPVAL_ENCODE_CONV_BLOB (   tv,
  blob,
  len 
)
Value:
do { \
const blob_T *const blob_ = (blob); \
const int len_ = (len); \
if (len_ == 0) { \
ga_concat(gap, "0z"); \
} else { \
/* 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 && (i_ & 3) == 0) { \
ga_append(gap, '.'); \
} \
vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "%02X", \
(int)tv_blob_get(blob_, i_)); \
ga_concat(gap, numbuf); \
} \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_BLOB [2/3]

#define TYPVAL_ENCODE_CONV_BLOB (   tv,
  blob,
  len 
)
Value:
do { \
const blob_T *const blob_ = (blob); \
const int len_ = (len); \
if (len_ == 0) { \
ga_concat(gap, "[]"); \
} else { \
ga_append(gap, '['); \
char numbuf[NUMBUFLEN]; \
for (int i_ = 0; i_ < len_; i_++) { \
if (i_ > 0) { \
ga_concat(gap, ", "); \
} \
vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "%d", \
(int)tv_blob_get(blob_, i_)); \
ga_concat(gap, numbuf); \
} \
ga_append(gap, ']'); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_BLOB [3/3]

#define TYPVAL_ENCODE_CONV_BLOB (   tv,
  blob,
  len 
)
Value:
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)

◆ TYPVAL_ENCODE_CONV_BOOL [1/3]

#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    ga_concat(gap, ((num)? "v:true": "v:false"))

◆ TYPVAL_ENCODE_CONV_BOOL [2/3]

#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    ga_concat(gap, ((num)? "true": "false"))

◆ TYPVAL_ENCODE_CONV_BOOL [3/3]

#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)
Value:
do { \
if (num) { \
msgpack_pack_true(packer); \
} else { \
msgpack_pack_false(packer); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_DICT_AFTER_KEY [1/2]

#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)    ga_concat(gap, ": ")

◆ TYPVAL_ENCODE_CONV_DICT_AFTER_KEY [2/2]

#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)

◆ TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS [1/2]

#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)    ga_concat(gap, ", ")

◆ TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS [2/2]

#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)

◆ TYPVAL_ENCODE_CONV_DICT_END [1/2]

#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)    ga_append(gap, '}')

◆ TYPVAL_ENCODE_CONV_DICT_END [2/2]

#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)

◆ TYPVAL_ENCODE_CONV_DICT_START [1/2]

#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)    ga_append(gap, '{')

◆ TYPVAL_ENCODE_CONV_DICT_START [2/2]

#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)    msgpack_pack_map(packer, (size_t)(len))

◆ TYPVAL_ENCODE_CONV_EMPTY_DICT [1/2]

#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)    ga_concat(gap, "{}")

◆ TYPVAL_ENCODE_CONV_EMPTY_DICT [2/2]

#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)    msgpack_pack_map(packer, 0)

◆ TYPVAL_ENCODE_CONV_EMPTY_LIST [1/2]

#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)    ga_concat(gap, "[]")

◆ TYPVAL_ENCODE_CONV_EMPTY_LIST [2/2]

#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)    msgpack_pack_array(packer, 0)

◆ TYPVAL_ENCODE_CONV_EXT_STRING [1/3]

#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)

◆ TYPVAL_ENCODE_CONV_EXT_STRING [2/3]

#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)
Value:
do { \
xfree(buf); \
emsg(_("E474: Unable to convert EXT string to JSON")); \
return FAIL; \
} while (0)

◆ TYPVAL_ENCODE_CONV_EXT_STRING [3/3]

#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)
Value:
do { \
if (buf == NULL) { \
msgpack_pack_ext(packer, 0, (int8_t)type); \
} else { \
const size_t len_ = (len); \
msgpack_pack_ext(packer, len_, (int8_t)type); \
msgpack_pack_ext_body(packer, buf, len_); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FLOAT [1/3]

#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)
Value:
do { \
const float_T flt_ = (flt); \
switch (xfpclassify(flt_)) { \
case FP_NAN: { \
ga_concat(gap, "str2float('nan')"); \
break; \
} \
case FP_INFINITE: { \
if (flt_ < 0) { \
ga_append(gap, '-'); \
} \
ga_concat(gap, "str2float('inf')"); \
break; \
} \
default: { \
char numbuf[NUMBUFLEN]; \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \
ga_concat(gap, numbuf); \
} \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FLOAT [2/3]

#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)
Value:
do { \
const float_T flt_ = (flt); \
switch (xfpclassify(flt_)) { \
case FP_NAN: { \
emsg(_("E474: Unable to represent NaN value in JSON")); \
return FAIL; \
} \
case FP_INFINITE: { \
emsg(_("E474: Unable to represent infinity in JSON")); \
return FAIL; \
} \
default: { \
char numbuf[NUMBUFLEN]; \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \
ga_concat(gap, numbuf); \
break; \
} \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FLOAT [3/3]

#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)    msgpack_pack_double(packer, (double)(flt))

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS [1/2]

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)
Value:
do { \
if (len != 0) { \
ga_concat(gap, ", "); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS [2/2]

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF [1/2]

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)
Value:
do { \
if ((ptrdiff_t)len != -1) { \
ga_concat(gap, ", "); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF [2/2]

#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)

◆ TYPVAL_ENCODE_CONV_FUNC_END [1/2]

#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)    ga_append(gap, ')')

◆ TYPVAL_ENCODE_CONV_FUNC_END [2/2]

#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)

◆ TYPVAL_ENCODE_CONV_FUNC_START [1/3]

#define TYPVAL_ENCODE_CONV_FUNC_START (   tv,
  fun 
)
Value:
do { \
const char *const fun_ = (const char *)(fun); \
if (fun_ == NULL) { \
internal_error("string(): NULL function name"); \
ga_concat(gap, "function(NULL"); \
} else { \
ga_concat(gap, "function("); \
TYPVAL_ENCODE_CONV_STRING(tv, fun_, strlen(fun_)); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_FUNC_START [2/3]

#define TYPVAL_ENCODE_CONV_FUNC_START (   tv,
  fun 
)
Value:
return conv_error(_("E474: Error while dumping %s, %s: " \
"attempt to dump function reference"), \
mpstack, objname)

◆ TYPVAL_ENCODE_CONV_FUNC_START [3/3]

#define TYPVAL_ENCODE_CONV_FUNC_START (   tv,
  fun 
)
Value:
return conv_error(_("E5004: Error while dumping %s, %s: " \
"attempt to dump function reference"), \
mpstack, objname)

◆ TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS [1/2]

#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)    TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, NULL)

◆ TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS [2/2]

#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)

◆ TYPVAL_ENCODE_CONV_LIST_END [1/2]

#define TYPVAL_ENCODE_CONV_LIST_END (   tv)    ga_append(gap, ']')

◆ TYPVAL_ENCODE_CONV_LIST_END [2/2]

#define TYPVAL_ENCODE_CONV_LIST_END (   tv)

◆ TYPVAL_ENCODE_CONV_LIST_START [1/2]

#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)    ga_append(gap, '[')

◆ TYPVAL_ENCODE_CONV_LIST_START [2/2]

#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)    msgpack_pack_array(packer, (size_t)(len))

◆ TYPVAL_ENCODE_CONV_NIL [1/3]

#define TYPVAL_ENCODE_CONV_NIL (   tv)    ga_concat(gap, "v:null")

◆ TYPVAL_ENCODE_CONV_NIL [2/3]

#define TYPVAL_ENCODE_CONV_NIL (   tv)    ga_concat(gap, "null")

◆ TYPVAL_ENCODE_CONV_NIL [3/3]

#define TYPVAL_ENCODE_CONV_NIL (   tv)    msgpack_pack_nil(packer)

◆ TYPVAL_ENCODE_CONV_NUMBER [1/2]

#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)
Value:
do { \
char numbuf[NUMBUFLEN]; \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRId64, (int64_t)(num)); \
ga_concat(gap, numbuf); \
} while (0)

◆ TYPVAL_ENCODE_CONV_NUMBER [2/2]

#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)    msgpack_pack_int64(packer, (int64_t)(num))

◆ TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START [1/2]

#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START [2/2]

#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START [1/2]

#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START [2/2]

#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)

◆ TYPVAL_ENCODE_CONV_RECURSE [1/4]

#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
Value:
do { \
if (!did_echo_string_emsg) { \
/* Only give this message once for a recursive call to avoid */ \
/* flooding the user with errors. */ \
did_echo_string_emsg = true; \
emsg(_("E724: unable to correctly dump variable " \
"with self-referencing container")); \
} \
char ebuf[NUMBUFLEN + 7]; \
size_t backref = 0; \
for (; backref < kv_size(*mpstack); backref++) { \
const MPConvStackVal mpval = kv_A(*mpstack, backref); \
if (mpval.type == conv_type) { \
if (conv_type == kMPConvDict) { \
if ((void *)mpval.data.d.dict == (void *)(val)) { \
break; \
} \
} else if (conv_type == kMPConvList) { \
if ((void *)mpval.data.l.list == (void *)(val)) { \
break; \
} \
} \
} \
} \
vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{[email protected]%zu}", backref); \
ga_concat(gap, &ebuf[0]); \
} while (0)

◆ TYPVAL_ENCODE_CONV_RECURSE [2/4]

#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
Value:
do { \
char ebuf[NUMBUFLEN + 7]; \
size_t backref = 0; \
for (; backref < kv_size(*mpstack); backref++) { \
const MPConvStackVal mpval = kv_A(*mpstack, backref); \
if (mpval.type == conv_type) { \
if (conv_type == kMPConvDict) { \
if ((void *)mpval.data.d.dict == (void *)val) { \
break; \
} \
} else if (conv_type == kMPConvList) { \
if ((void *)mpval.data.l.list == (void *)val) { \
break; \
} \
} \
} \
} \
if (conv_type == kMPConvDict) { \
vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "{[email protected]%zu}", backref); \
} else { \
vim_snprintf(ebuf, ARRAY_SIZE(ebuf), "[[email protected]%zu]", backref); \
} \
ga_concat(gap, &ebuf[0]); \
return OK; \
} while (0)

◆ TYPVAL_ENCODE_CONV_RECURSE [3/4]

#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
Value:
do { \
if (!did_echo_string_emsg) { \
/* Only give this message once for a recursive call to avoid */ \
/* flooding the user with errors. */ \
did_echo_string_emsg = true; \
emsg(_("E724: unable to correctly dump variable " \
"with self-referencing container")); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_RECURSE [4/4]

#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
Value:
return conv_error(_("E5005: Unable to dump %s: " \
"container references itself in %s"), \
mpstack, objname)

◆ TYPVAL_ENCODE_CONV_STR_STRING [1/2]

#define TYPVAL_ENCODE_CONV_STR_STRING (   tv,
  buf,
  len 
)    TYPVAL_ENCODE_CONV_STRING(tv, buf, len)

◆ TYPVAL_ENCODE_CONV_STR_STRING [2/2]

#define TYPVAL_ENCODE_CONV_STR_STRING (   tv,
  buf,
  len 
)
Value:
do { \
if (buf == NULL) { \
msgpack_pack_str(packer, 0); \
} else { \
const size_t len_ = (len); \
msgpack_pack_str(packer, len_); \
msgpack_pack_str_body(packer, buf, len_); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_STRING [1/3]

#define TYPVAL_ENCODE_CONV_STRING (   tv,
  buf,
  len 
)
Value:
do { \
const char *const buf_ = (const char *)buf; \
if (buf == NULL) { \
ga_concat(gap, "''"); \
} else { \
const size_t len_ = (len); \
ga_grow(gap, (int)(2 + len_ + memcnt(buf_, '\'', len_))); \
ga_append(gap, '\''); \
for (size_t i_ = 0; i_ < len_; i_++) { \
if (buf_[i_] == '\'') { \
ga_append(gap, '\''); \
} \
ga_append(gap, buf_[i_]); \
} \
ga_append(gap, '\''); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_STRING [2/3]

#define TYPVAL_ENCODE_CONV_STRING (   tv,
  buf,
  len 
)
Value:
do { \
if (convert_to_json_string(gap, (const char *)(buf), (len)) != OK) { \
return FAIL; \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_STRING [3/3]

#define TYPVAL_ENCODE_CONV_STRING (   tv,
  buf,
  len 
)
Value:
do { \
if (buf == NULL) { \
msgpack_pack_bin(packer, 0); \
} else { \
const size_t len_ = (len); \
msgpack_pack_bin(packer, len_); \
msgpack_pack_bin_body(packer, buf, len_); \
} \
} while (0)

◆ TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER [1/3]

#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)

◆ TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER [2/3]

#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)
Value:
do { \
char numbuf[NUMBUFLEN]; \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRIu64, (num)); \
ga_concat(gap, numbuf); \
} while (0)

◆ TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER [3/3]

#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)    msgpack_pack_uint64(packer, (num))

◆ TYPVAL_ENCODE_FIRST_ARG_NAME [1/4]

#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap

◆ TYPVAL_ENCODE_FIRST_ARG_NAME [2/4]

#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap

◆ TYPVAL_ENCODE_FIRST_ARG_NAME [3/4]

#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap

◆ TYPVAL_ENCODE_FIRST_ARG_NAME [4/4]

#define TYPVAL_ENCODE_FIRST_ARG_NAME   packer

◆ TYPVAL_ENCODE_FIRST_ARG_TYPE [1/4]

#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const

◆ TYPVAL_ENCODE_FIRST_ARG_TYPE [2/4]

#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const

◆ TYPVAL_ENCODE_FIRST_ARG_TYPE [3/4]

#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const

◆ TYPVAL_ENCODE_FIRST_ARG_TYPE [4/4]

#define TYPVAL_ENCODE_FIRST_ARG_TYPE   msgpack_packer *const

◆ TYPVAL_ENCODE_NAME [1/4]

#define TYPVAL_ENCODE_NAME   string

◆ TYPVAL_ENCODE_NAME [2/4]

#define TYPVAL_ENCODE_NAME   echo

◆ TYPVAL_ENCODE_NAME [3/4]

#define TYPVAL_ENCODE_NAME   json

◆ TYPVAL_ENCODE_NAME [4/4]

#define TYPVAL_ENCODE_NAME   msgpack

◆ TYPVAL_ENCODE_SCOPE [1/4]

#define TYPVAL_ENCODE_SCOPE   static

◆ TYPVAL_ENCODE_SCOPE [2/4]

#define TYPVAL_ENCODE_SCOPE

◆ TYPVAL_ENCODE_SCOPE [3/4]

#define TYPVAL_ENCODE_SCOPE   static

◆ TYPVAL_ENCODE_SCOPE [4/4]

#define TYPVAL_ENCODE_SCOPE

◆ TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK [1/3]

#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)

◆ TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK [2/3]

#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)
Value:
do { \
if (!encode_check_json_key(&key)) { \
emsg(_("E474: Invalid key in special dictionary")); \
goto label; \
} \
} while (0)

◆ TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK [3/3]

#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)

◆ utf_char2len

#define utf_char2len (   b)    ((size_t)utf_char2len(b))

Function Documentation

◆ assert()

assert ( len  = =read_bytes)

◆ encode_blob_write()

int encode_blob_write ( void *const  data,
const char *const  buf,
const size_t  len 
)

Msgpack callback for writing to a Blob.

◆ encode_check_json_key()

bool encode_check_json_key ( const typval_T *const  tv)

Check whether given key can be used in json_encode()

Parameters
[in]tvKey to check.

◆ encode_list_write()

int encode_list_write ( void *const  data,
const char *const  buf,
const size_t  len 
)

Msgpack callback for writing to readfile()-style list.

◆ encode_read_from_list()

int encode_read_from_list ( ListReaderState *const  state,
char *const  buf,
const size_t  nbuf,
size_t *const  read_bytes 
)

Read bytes from list

Parameters
[in,out]stateStructure describing position in list from which reading should start. Is updated to reflect position at which reading ended.
[out]bufBuffer to write to.
[in]nbufBuffer length.
[out]read_bytesIs set to amount of bytes read.
Returns
OK when reading was finished, FAIL in case of error (i.e. list item was not a string), NOTDONE if reading was successful, but there are more bytes to read.

◆ encode_tv2echo()

char* encode_tv2echo ( typval_T tv,
size_t *  len 
)

Return a string with the string representation of a variable. Does not put quotes around strings, as ":echo" displays values.

Parameters
[in]tvtypval_T to convert.
[out]lenLocation where length of the result will be saved.
Returns
String representation of the variable or NULL.

◆ encode_tv2json()

char* encode_tv2json ( typval_T tv,
size_t *  len 
)

Return a string with the string representation of a variable. Puts quotes around strings, so that they can be parsed back by eval().

Parameters
[in]tvtypval_T to convert.
[out]lenLocation where length of the result will be saved.
Returns
String representation of the variable or NULL.

◆ encode_tv2string()

char* encode_tv2string ( typval_T tv,
size_t *  len 
)

Return a string with the string representation of a variable. Puts quotes around strings, so that they can be parsed back by eval().

Parameters
[in]tvtypval_T to convert.
[out]lenLocation where length of the result will be saved.
Returns
String representation of the variable or NULL.

◆ encode_vim_list_to_buf()

bool encode_vim_list_to_buf ( const list_T *const  list,
size_t *const  ret_len,
char **const  ret_buf 
)

Convert readfile()-style list to a char * buffer with length

Parameters
[in]listConverted list.
[out]ret_lenResulting buffer length.
[out]ret_bufAllocated buffer with the result or NULL if ret_len is zero.
Returns
true in case of success, false in case of failure.

◆ if() [1/2]

if ( encode_read_from_list &,,, &read_bytes = OK)

◆ if() [2/2]

if ( len  = = 0)

◆ TV_LIST_ITER_CONST()

TV_LIST_ITER_CONST ( list  ,
li  ,
{ if(TV_LIST_ITEM_TV(li) ->v_type !=VAR_STRING) { return false;} len++;if(TV_LIST_ITEM_TV(li) ->vval.v_string !=NULL) { len+=STRLEN(TV_LIST_ITEM_TV(li) ->vval.v_string);} }   
)

Variable Documentation

◆ buf

char* const buf = xmalloc(len)

◆ encode_bool_var_names

const char* const encode_bool_var_names[]
Initial value:
= {
[kBoolVarTrue] = "true",
[kBoolVarFalse] = "false",
}

Array mapping values from SpecialVarValue enum to names.

◆ encode_special_var_names

const char* const encode_special_var_names[]
Initial value:
= {
[kSpecialVarNull] = "null",
}

◆ FUNC_ATTR_WARN_UNUSED_RESULT

bool FUNC_ATTR_WARN_UNUSED_RESULT
Initial value:
{
size_t len = 0

◆ lrstate

ListReaderState lrstate = encode_init_lrstate(list)

◆ read_bytes

size_t read_bytes

◆ ret_buf

* ret_buf = buf

◆ ret_len

* ret_len = len

◆ true

return true
tv
typval_T tv
Definition: typval.c:1694
_
#define _(x)
Definition: gettext.h:20
numbuf
char_u numbuf[NUMBUFLEN]
Definition: userfunc.c:820
type
err type
Definition: helpers.c:1043
blobvar_S
Structure to hold info about a Blob.
Definition: typval.h:259
MPConvStackVal
Structure representing current VimL to messagepack conversion state.
Definition: typval_encode.h:34
kBoolVarFalse
@ kBoolVarFalse
v:false
Definition: typval.h:98
gap
garray_T * gap
Definition: ex_docmd.c:5155
xfpclassify
int xfpclassify(double d)
Definition: math.c:14
encode_check_json_key
bool encode_check_json_key(const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
Definition: encode.c:755
kv_A
#define kv_A(v, i)
Definition: kvec.h:66
OK
#define OK
Definition: vim.h:90
buf
char *const buf
Definition: encode.c:235
float_T
double float_T
Type used for VimL VAR_FLOAT values.
Definition: typval.h:30
NUMBUFLEN
@ NUMBUFLEN
Definition: vim.h:27
FAIL
return FAIL
Definition: ex_docmd.c:5239
kMPConvList
@ kMPConvList
Convert list_T *list.
Definition: typval_encode.h:20
kv_size
#define kv_size(v)
Definition: kvec.h:68
ARRAY_SIZE
#define ARRAY_SIZE(arr)
Definition: macros.h:122
kMPConvDict
@ kMPConvDict
Convert dict_T *dictionary.
Definition: typval_encode.h:19
kBoolVarTrue
@ kBoolVarTrue
v:true
Definition: typval.h:99
kSpecialVarNull
@ kSpecialVarNull
v:null
Definition: typval.h:104
memcnt
size_t memcnt(const void *data, char c, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
Definition: memory.c:293
NULL
return NULL
Definition: eval.c:10355
len
int len
Definition: helpers.c:1034