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

Macros

#define ga_concat(a, b)   ga_concat(a, (char_u *)b)
 
#define utf_ptr2char(b)   utf_ptr2char((char_u *)b)
 
#define utf_ptr2len(b)   ((size_t)utf_ptr2len((char_u *)b))
 
#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_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_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_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_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_special_var_names []
 Array mapping values from SpecialVarValue enum to names. More...
 
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

#define ENCODE_RAW (   ch)    (ch >= 0x20 && utf_printable(ch))
#define ga_concat (   a,
 
)    ga_concat(a, (char_u *)b)
#define TYPVAL_ENCODE_ALLOW_SPECIALS   false
#define TYPVAL_ENCODE_ALLOW_SPECIALS   true
#define TYPVAL_ENCODE_ALLOW_SPECIALS   true
#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    ga_concat(gap, ((num)? "v:true": "v:false"))
#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)    ga_concat(gap, ((num)? "true": "false"))
#define TYPVAL_ENCODE_CONV_BOOL (   tv,
  num 
)
Value:
do { \
if (num) { \
msgpack_pack_true(packer); \
} else { \
msgpack_pack_false(packer); \
} \
} while (0)
if(len)
Definition: encode.c:222
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)    ga_concat(gap, ": ")
#define TYPVAL_ENCODE_CONV_DICT_AFTER_KEY (   tv,
  dict 
)
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)    ga_concat(gap, ", ")
#define TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS (   tv,
  dict 
)
#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)    ga_append(gap, '}')
#define TYPVAL_ENCODE_CONV_DICT_END (   tv,
  dict 
)
#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)    ga_append(gap, '{')
#define TYPVAL_ENCODE_CONV_DICT_START (   tv,
  dict,
  len 
)    msgpack_pack_map(packer, (size_t)(len))
#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)    ga_concat(gap, "{}")
#define TYPVAL_ENCODE_CONV_EMPTY_DICT (   tv,
  dict 
)    msgpack_pack_map(packer, 0)
#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)    ga_concat(gap, "[]")
#define TYPVAL_ENCODE_CONV_EMPTY_LIST (   tv)    msgpack_pack_array(packer, 0)
#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)
#define TYPVAL_ENCODE_CONV_EXT_STRING (   tv,
  buf,
  len,
  type 
)
Value:
do { \
EMSG(_("E474: Unable to convert EXT string to JSON")); \
} while (0)
#define _(x)
Definition: gettext.h:20
xfree(tofree)
char *const buf
Definition: encode.c:231
return
Definition: eval.c:15807
#define EMSG(s)
Definition: message.h:40
return FAIL
Definition: eval.c:1058
#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)
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23938
int len
Definition: helpers.c:1461
char *const buf
Definition: encode.c:231
err type
Definition: helpers.c:1470
#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)
Value:
do { \
const float_T flt_ = (flt); \
switch (xfpclassify(flt_)) { \
case FP_NAN: { \
ga_concat(gap, (char_u *) "str2float('nan')"); \
break; \
} \
case FP_INFINITE: { \
if (flt_ < 0) { \
ga_append(gap, '-'); \
} \
ga_concat(gap, (char_u *) "str2float('inf')"); \
break; \
} \
default: { \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \
ga_concat(gap, (char_u *) numbuf); \
} \
} \
} while (0)
int xfpclassify(double d)
Definition: math.c:18
if(len)
Definition: encode.c:222
Definition: vim.h:27
switch(from->v_type)
Definition: eval.c:21117
void ga_append(garray_T *gap, char c)
Definition: garray.c:225
char_u numbuf[NUMBUFLEN]
Definition: eval.c:23061
double float_T
Type used for VimL VAR_FLOAT values.
Definition: typval.h:30
unsigned char char_u
Definition: types.h:11
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#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")); \
} \
case FP_INFINITE: { \
EMSG(_("E474: Unable to represent infinity in JSON")); \
} \
default: { \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%g", flt_); \
ga_concat(gap, (char_u *) numbuf); \
break; \
} \
} \
} while (0)
#define _(x)
Definition: gettext.h:20
int xfpclassify(double d)
Definition: math.c:18
Definition: vim.h:27
switch(from->v_type)
Definition: eval.c:21117
char_u numbuf[NUMBUFLEN]
Definition: eval.c:23061
return
Definition: eval.c:15807
#define EMSG(s)
Definition: message.h:40
double float_T
Type used for VimL VAR_FLOAT values.
Definition: typval.h:30
return FAIL
Definition: eval.c:1058
unsigned char char_u
Definition: types.h:11
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#define TYPVAL_ENCODE_CONV_FLOAT (   tv,
  flt 
)    msgpack_pack_double(packer, (double)(flt))
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)
Value:
do { \
if (len != 0) { \
ga_concat(gap, ", "); \
} \
} while (0)
if(len)
Definition: encode.c:222
int len
Definition: helpers.c:1461
#define ga_concat(a, b)
Definition: encode.c:32
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_ARGS (   tv,
  len 
)
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)
Value:
do { \
if ((ptrdiff_t)len != -1) { \
ga_concat(gap, ", "); \
} \
} while (0)
if(len)
Definition: encode.c:222
int len
Definition: helpers.c:1461
#define ga_concat(a, b)
Definition: encode.c:32
#define TYPVAL_ENCODE_CONV_FUNC_BEFORE_SELF (   tv,
  len 
)
#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)    ga_append(gap, ')')
#define TYPVAL_ENCODE_CONV_FUNC_END (   tv)
#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_T tv
Definition: typval.c:1544
if(len)
Definition: encode.c:222
void internal_error(char *where)
Give an "Internal error" message.
Definition: message.c:815
return NULL
Definition: eval.c:23938
#define ga_concat(a, b)
Definition: encode.c:32
#define TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
Definition: encode.c:868
#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)
#define _(x)
Definition: gettext.h:20
#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)
#define _(x)
Definition: gettext.h:20
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)    TYPVAL_ENCODE_CONV_DICT_BETWEEN_ITEMS(tv, NULL)
#define TYPVAL_ENCODE_CONV_LIST_BETWEEN_ITEMS (   tv)
#define TYPVAL_ENCODE_CONV_LIST_END (   tv)    ga_append(gap, ']')
#define TYPVAL_ENCODE_CONV_LIST_END (   tv)
#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)    ga_append(gap, '[')
#define TYPVAL_ENCODE_CONV_LIST_START (   tv,
  len 
)    msgpack_pack_array(packer, (size_t)(len))
#define TYPVAL_ENCODE_CONV_NIL (   tv)    ga_concat(gap, "v:null")
#define TYPVAL_ENCODE_CONV_NIL (   tv)    ga_concat(gap, "null")
#define TYPVAL_ENCODE_CONV_NIL (   tv)    msgpack_pack_nil(packer)
#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)
Value:
do { \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRId64, (int64_t) (num)); \
ga_concat(gap, numbuf); \
} while (0)
Definition: vim.h:27
char_u numbuf[NUMBUFLEN]
Definition: eval.c:23061
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#define TYPVAL_ENCODE_CONV_NUMBER (   tv,
  num 
)    msgpack_pack_int64(packer, (int64_t)(num))
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)
#define TYPVAL_ENCODE_CONV_REAL_DICT_AFTER_START (   tv,
  dict,
  mpsv 
)
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)
#define TYPVAL_ENCODE_CONV_REAL_LIST_AFTER_START (   tv,
  mpsv 
)
#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)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
Definition: vim.h:27
#define kv_size(v)
Definition: kvec.h:68
Structure representing current VimL to messagepack conversion state.
Definition: typval_encode.h:34
Convert list_T *list.
Definition: typval_encode.h:20
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1217
#define kv_A(v, i)
Definition: kvec.h:66
Convert dict_T *dictionary.
Definition: typval_encode.h:19
#define EMSG(s)
Definition: message.h:40
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#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]); \
} while (0)
if(len)
Definition: encode.c:222
Definition: vim.h:27
#define kv_size(v)
Definition: kvec.h:68
Structure representing current VimL to messagepack conversion state.
Definition: typval_encode.h:34
return OK
Definition: eval.c:1061
Convert list_T *list.
Definition: typval_encode.h:20
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1217
#define kv_A(v, i)
Definition: kvec.h:66
Convert dict_T *dictionary.
Definition: typval_encode.h:19
return
Definition: eval.c:15807
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#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)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
#define EMSG(s)
Definition: message.h:40
#define TYPVAL_ENCODE_CONV_RECURSE (   val,
  conv_type 
)
Value:
return conv_error(_("E5005: Unable to dump %s: " \
"container references itself in %s"), \
mpstack, objname)
#define _(x)
Definition: gettext.h:20
#define TYPVAL_ENCODE_CONV_STR_STRING (   tv,
  buf,
  len 
)    TYPVAL_ENCODE_CONV_STRING(tv, buf, len)
#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)
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23938
int len
Definition: helpers.c:1461
char *const buf
Definition: encode.c:231
#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)
if(len)
Definition: encode.c:222
void ga_grow(garray_T *gap, int n)
Definition: garray.c:77
return NULL
Definition: eval.c:23938
int len
Definition: helpers.c:1461
size_t memcnt(const void *data, char c, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
Definition: memory.c:288
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1217
char *const buf
Definition: encode.c:231
void ga_append(garray_T *gap, char c)
Definition: garray.c:225
#define ga_concat(a, b)
Definition: encode.c:32
#define TYPVAL_ENCODE_CONV_STRING (   tv,
  buf,
  len 
)
Value:
do { \
if (convert_to_json_string(gap, (const char *) (buf), (len)) != OK) { \
} \
} while (0)
if(len)
Definition: encode.c:222
int len
Definition: helpers.c:1461
return OK
Definition: eval.c:1061
char *const buf
Definition: encode.c:231
return
Definition: eval.c:15807
return FAIL
Definition: eval.c:1058
#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)
if(len)
Definition: encode.c:222
return NULL
Definition: eval.c:23938
int len
Definition: helpers.c:1461
char *const buf
Definition: encode.c:231
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)
Value:
do { \
vim_snprintf(numbuf, ARRAY_SIZE(numbuf), "%" PRIu64, (num)); \
ga_concat(gap, numbuf); \
} while (0)
Definition: vim.h:27
char_u numbuf[NUMBUFLEN]
Definition: eval.c:23061
int vim_snprintf(char *str, size_t str_m, const char *fmt,...) FUNC_ATTR_PRINTF(3
#define ga_concat(a, b)
Definition: encode.c:32
#define ARRAY_SIZE(arr)
Definition: macros.h:141
#define TYPVAL_ENCODE_CONV_UNSIGNED_NUMBER (   tv,
  num 
)    msgpack_pack_uint64(packer, (num))
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
#define TYPVAL_ENCODE_FIRST_ARG_NAME   gap
#define TYPVAL_ENCODE_FIRST_ARG_NAME   packer
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   garray_T *const
#define TYPVAL_ENCODE_FIRST_ARG_TYPE   msgpack_packer *const
#define TYPVAL_ENCODE_NAME   string
#define TYPVAL_ENCODE_NAME   echo
#define TYPVAL_ENCODE_NAME   json
#define TYPVAL_ENCODE_NAME   msgpack
#define TYPVAL_ENCODE_SCOPE   static
#define TYPVAL_ENCODE_SCOPE
#define TYPVAL_ENCODE_SCOPE   static
#define TYPVAL_ENCODE_SCOPE
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)
Value:
do { \
EMSG(_("E474: Invalid key in special dictionary")); \
goto label; \
} \
} while (0)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
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:711
#define EMSG(s)
Definition: message.h:40
#define TYPVAL_ENCODE_SPECIAL_DICT_KEY_CHECK (   label,
  key 
)
#define utf_char2len (   b)    ((size_t)utf_char2len(b))
#define utf_ptr2char (   b)    utf_ptr2char((char_u *)b)
#define utf_ptr2len (   b)    ((size_t)utf_ptr2len((char_u *)b))

Function Documentation

assert ( len  = =read_bytes)
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.
int encode_list_write ( void *const  data,
const char *const  buf,
const size_t  len 
)

Msgpack callback for writing to readfile()-style 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 successfull, but there are more bytes to read.
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.
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.
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.
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 ( len  = = 0)
if ( encode_read_from_list &,,,&read_bytes!  = OK)
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

char* const buf = xmalloc(len)
const char* const encode_special_var_names[]
Initial value:
= {
[kSpecialVarNull] = "null",
[kSpecialVarTrue] = "true",
[kSpecialVarFalse] = "false",
}
v:true
Definition: typval.h:97
v:null
Definition: typval.h:98
v:false
Definition: typval.h:96

Array mapping values from SpecialVarValue enum to names.

bool FUNC_ATTR_WARN_UNUSED_RESULT
Initial value:
{
size_t len = 0
int len
Definition: helpers.c:1461
ListReaderState lrstate = encode_init_lrstate(list)
size_t read_bytes
* ret_buf = buf
* ret_len = len
return true