MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / json_append_data

Function json_append_data

deps/lua/src/lua_cjson.c:660–701  ·  view source on GitHub ↗

Serialise Lua data into JSON string. */

Source from the content-addressed store, hash-verified

658
659/* Serialise Lua data into JSON string. */
660static void json_append_data(lua_State *l, json_config_t *cfg,
661 int current_depth, strbuf_t *json)
662{
663 int len;
664
665 switch (lua_type(l, -1)) {
666 case LUA_TSTRING:
667 json_append_string(l, json, -1);
668 break;
669 case LUA_TNUMBER:
670 json_append_number(l, cfg, json, -1);
671 break;
672 case LUA_TBOOLEAN:
673 if (lua_toboolean(l, -1))
674 strbuf_append_mem(json, "true", 4);
675 else
676 strbuf_append_mem(json, "false", 5);
677 break;
678 case LUA_TTABLE:
679 current_depth++;
680 json_check_encode_depth(l, cfg, current_depth, json);
681 len = lua_array_length(l, cfg, json);
682 if (len > 0)
683 json_append_array(l, cfg, current_depth, json, len);
684 else
685 json_append_object(l, cfg, current_depth, json);
686 break;
687 case LUA_TNIL:
688 strbuf_append_mem(json, "null", 4);
689 break;
690 case LUA_TLIGHTUSERDATA:
691 if (lua_touserdata(l, -1) == NULL) {
692 strbuf_append_mem(json, "null", 4);
693 break;
694 }
695 default:
696 /* Remaining types (LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD,
697 * and LUA_TLIGHTUSERDATA) cannot be serialised */
698 json_encode_exception(l, cfg, json, -1, "type not supported");
699 /* never returns */
700 }
701}
702
703static int json_encode(lua_State *l)
704{

Callers 3

json_append_arrayFunction · 0.85
json_append_objectFunction · 0.85
json_encodeFunction · 0.85

Calls 11

lua_typeFunction · 0.85
json_append_stringFunction · 0.85
json_append_numberFunction · 0.85
lua_tobooleanFunction · 0.85
strbuf_append_memFunction · 0.85
json_check_encode_depthFunction · 0.85
lua_array_lengthFunction · 0.85
json_append_arrayFunction · 0.85
json_append_objectFunction · 0.85
lua_touserdataFunction · 0.85
json_encode_exceptionFunction · 0.85

Tested by

no test coverage detected