MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / process_json_conv

Function process_json_conv

lua/sp.c:4088–4124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4086} json_conv;
4087
4088static int process_json_conv(Lua L, json_conv *conv)
4089{
4090 const char *key, *value;
4091 switch (luabb_type(L, -2)) {
4092 case DBTYPES_LSTRING:
4093 case DBTYPES_CSTRING:
4094 key = luabb_tostring(L, -2);
4095 if (strcmp(key, "invalid_utf8") == 0) {
4096 value = luabb_tostring(L, -1);
4097 if (value == NULL) {
4098 return -1;
4099 } else if (strcmp(value, "fail") == 0) {
4100 conv->flag |= CONV_FLAG_UTF8_NIL;
4101 return 0;
4102 } else if (strcmp(value, "truncate") == 0) {
4103 conv->flag |= CONV_FLAG_UTF8_TRUNCATE;
4104 return 0;
4105 } else if (strcmp(value, "hex") == 0) {
4106 conv->flag |= CONV_FLAG_UTF8_HEX;
4107 return 0;
4108 } else {
4109 return -2;
4110 }
4111 } else if (strcmp(key, "type_annotate") == 0) {
4112 if (luabb_type(L, -1) == DBTYPES_LBOOLEAN) {
4113 if (lua_toboolean(L, -2)) {
4114 conv->flag |= CONV_FLAG_ANNOTATE;
4115 }
4116 return 0;
4117 } else {
4118 return -3;
4119 }
4120 }
4121 default:
4122 return -4;
4123 }
4124}
4125
4126static cson_value *table_to_cson(Lua, int, json_conv *);
4127static int db_table_to_json(Lua L)

Callers 1

db_table_to_jsonFunction · 0.85

Calls 3

luabb_typeFunction · 0.85
luabb_tostringFunction · 0.85
lua_tobooleanFunction · 0.85

Tested by

no test coverage detected