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

Function json_encode

deps/lua/src/lua_cjson.c:703–732  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

701}
702
703static int json_encode(lua_State *l)
704{
705 json_config_t *cfg = json_fetch_config(l);
706 strbuf_t local_encode_buf;
707 strbuf_t *encode_buf;
708 char *json;
709 int len;
710
711 luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument");
712
713 if (!cfg->encode_keep_buffer) {
714 /* Use private buffer */
715 encode_buf = &local_encode_buf;
716 strbuf_init(encode_buf, 0);
717 } else {
718 /* Reuse existing buffer */
719 encode_buf = &cfg->encode_buf;
720 strbuf_reset(encode_buf);
721 }
722
723 json_append_data(l, cfg, 0, encode_buf);
724 json = strbuf_string(encode_buf, &len);
725
726 lua_pushlstring(l, json, len);
727
728 if (!cfg->encode_keep_buffer)
729 strbuf_free(encode_buf);
730
731 return 1;
732}
733
734/* ===== DECODING ===== */
735

Callers

nothing calls this directly

Calls 8

json_fetch_configFunction · 0.85
lua_gettopFunction · 0.85
strbuf_initFunction · 0.85
strbuf_resetFunction · 0.85
json_append_dataFunction · 0.85
strbuf_stringFunction · 0.85
lua_pushlstringFunction · 0.85
strbuf_freeFunction · 0.85

Tested by

no test coverage detected