Data Structures | Macros | Functions
decode.c File Reference
#include <stddef.h>
#include <msgpack.h>
#include "nvim/eval/typval.h"
#include "nvim/eval.h"
#include "nvim/eval/encode.h"
#include "nvim/ascii.h"
#include "nvim/macros.h"
#include "nvim/message.h"
#include "nvim/globals.h"
#include "nvim/charset.h"
#include "nvim/lib/kvec.h"
#include "nvim/vim.h"

Data Structures

struct  ContainerStackItem
 Helper structure for container_struct. More...
 
struct  ValuesStackItem
 Helper structure for values struct. More...
 

Macros

#define DICT_LEN(dict)   (dict)->dv_hashtab.ht_used
 
#define LENP(p, e)   ((int) ((e) - (p))), (p)
 
#define OBJ(obj_tv, is_sp_string, didcomma_, didcolon_)
 
#define POP(obj_tv, is_sp_string)
 
#define PUT_FST_IN_PAIR(fst_in_pair, str_end)
 
#define POP(obj_tv, is_sp_string)
 

Functions

typedef kvec_t (ValuesStackItem)
 Vector containing values not yet saved in any container. More...
 
list_Tdecode_create_map_special_dict (typval_T *const ret_tv, const ptrdiff_t len) FUNC_ATTR_NONNULL_ALL
 
typval_T decode_string (const char *const s, const size_t len, const TriState hasnul, const bool binary, const bool s_allocated) FUNC_ATTR_WARN_UNUSED_RESULT
 
int json_decode_string (const char *const buf, const size_t buf_len, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 
int msgpack_to_vim (const msgpack_object mobj, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
 Convert msgpack object to a VimL one. More...
 

Macro Definition Documentation

#define DICT_LEN (   dict)    (dict)->dv_hashtab.ht_used
#define LENP (   p,
 
)    ((int) ((e) - (p))), (p)
#define OBJ (   obj_tv,
  is_sp_string,
  didcomma_,
  didcolon_ 
)
Value:
.is_special_string = (is_sp_string), \
.val = (obj_tv), \
.didcomma = (didcomma_), \
.didcolon = (didcolon_), \
})
Helper structure for values struct.
Definition: decode.c:31
#define POP (   obj_tv,
  is_sp_string 
)
Value:
do { \
if (json_decoder_pop(OBJ(obj_tv, is_sp_string, *didcomma, *didcolon), \
stack, container_stack, \
&p, next_map_special, didcomma, didcolon) \
== FAIL) { \
goto parse_json_string_fail; \
} \
if (*next_map_special) { \
goto parse_json_string_ret; \
} \
} while (0)
if(len)
Definition: encode.c:226
#define FAIL
Definition: vim.h:93
char_u * p
Definition: eval.c:2042
#define OBJ(obj_tv, is_sp_string, didcomma_, didcolon_)
Definition: decode.c:200
#define POP (   obj_tv,
  is_sp_string 
)
Value:
do { \
if (json_decoder_pop(OBJ(obj_tv, is_sp_string, didcomma, didcolon), \
&stack, &container_stack, \
&p, &next_map_special, &didcomma, &didcolon) \
== FAIL) { \
goto json_decode_string_fail; \
} \
if (next_map_special) { \
goto json_decode_string_cycle_start; \
} \
} while (0)
if(len)
Definition: encode.c:226
#define FAIL
Definition: vim.h:93
char_u * p
Definition: eval.c:2042
#define OBJ(obj_tv, is_sp_string, didcomma_, didcolon_)
Definition: decode.c:200
#define PUT_FST_IN_PAIR (   fst_in_pair,
  str_end 
)
Value:
do { \
if (fst_in_pair != 0) { \
str_end += utf_char2bytes(fst_in_pair, (char_u *) str_end); \
fst_in_pair = 0; \
} \
} while (0)
if(len)
Definition: encode.c:226
unsigned char char_u
Definition: types.h:11
int utf_char2bytes(const int c, char_u *const buf)
Definition: mbyte.c:958

Function Documentation

list_T* decode_create_map_special_dict ( typval_T *const  ret_tv,
const ptrdiff_t  len 
)

Create a new special dictionary that ought to represent a MAP

Parameters
[out]ret_tvAddress where new special dictionary is saved.
[in]lenExpected number of items to be populated before list becomes accessible from VimL. It is still valid to underpopulate a list, value only controls how many elements will be allocated in advance.
See also
ListLenSpecials.
Returns
[allocated] list which should contain key-value pairs. Return value may be safely ignored.
typval_T decode_string ( const char *const  s,
const size_t  len,
const TriState  hasnul,
const bool  binary,
const bool  s_allocated 
)

Convert char* string to typval_T

Depending on whether string has (no) NUL bytes, it may use a special dictionary or decode string to VAR_STRING.

Parameters
[in]sString to decode.
[in]lenString length.
[in]hasnulWhether string has NUL byte, not or it was not yet determined.
[in]binaryIf true, save special string type as kMPBinary, otherwise kMPString.
[in]s_allocatedIf true, then s was allocated and can be saved in a returned structure. If it is not saved there, it will be freed.
Returns
Decoded string.
int json_decode_string ( const char *const  buf,
const size_t  buf_len,
typval_T *const  rettv 
)

Convert JSON string into VimL object

Parameters
[in]bufString to convert. UTF-8 encoding is assumed.
[in]buf_lenLength of the string.
[out]rettvLocation where to save results.
Returns
OK in case of success, FAIL otherwise.
typedef kvec_t ( ValuesStackItem  )

Vector containing values not yet saved in any container.

int msgpack_to_vim ( const msgpack_object  mobj,
typval_T *const  rettv 
)

Convert msgpack object to a VimL one.