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

Function cson_push_value_annotated

lua/sp.c:5381–5468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5379static const char *json_value = "value";
5380
5381static int cson_push_value_annotated(Lua L, cson_value *val)
5382{
5383 cson_object *o = cson_value_get_object(val);
5384 cson_value *t = cson_object_get(o, json_type);
5385 cson_value *v = cson_object_get(o, json_value);
5386 if (t == NULL || v == NULL || !cson_value_is_string(t)) return -1;
5387 char const *type = cson_value_get_cstr(t);
5388 if (cson_value_is_null(v)) {
5389 return cson_push_null(L, type);
5390 } else if (strcmp(type, "object") == 0 || strcmp(type, "array") == 0) {
5391 lua_newtable(L);
5392 return cson_to_table_annotated(L, val, 1);
5393 } else if (strcmp(type, "string") == 0) {
5394 if (!cson_value_is_string(v)) return -1;
5395 lua_pushstring(L, cson_value_get_cstr(v));
5396 } else if (strcmp(type, "cstring") == 0) {
5397 if (!cson_value_is_string(v)) return -1;
5398 luabb_pushcstring(L, cson_value_get_cstr(v));
5399 } else if (strcmp(type, "hexstring") == 0) {
5400 if (!cson_value_is_string(v)) return -1;
5401 const char *s = cson_value_get_cstr(v);
5402 size_t l = strlen(s);
5403 if (l % 2 != 0) return -1;
5404 uint8_t *b = malloc(l / 2);
5405 luabb_fromhex(b, (uint8_t *)s, l);
5406 luabb_pushcstring_dl(L, s);
5407 } else if (strcmp(type, "integer") == 0) {
5408 if (!cson_value_is_integer(v)) return -1;
5409 int64_t i = cson_value_get_integer(v);
5410 luabb_pushinteger(L, i);
5411 } else if (strcmp(type, "double") == 0) {
5412 if (!cson_value_is_double(v)) return -1;
5413 double d = cson_value_get_double(v);
5414 luabb_pushreal(L, d);
5415 } else if (strcmp(type, "number") == 0) {
5416 if (cson_value_is_integer(v)) {
5417 int64_t i = cson_value_get_integer(v);
5418 luabb_pushinteger(L, i);
5419 } else if (cson_value_is_double(v)) {
5420 double d = cson_value_get_double(v);
5421 lua_pushnumber(L, d);
5422 } else {
5423 return -1;
5424 }
5425 } else if (strcmp(type, "bool") == 0) {
5426 if (!cson_value_is_bool(v)) return -1;
5427 lua_pushboolean(L, cson_value_get_bool(v));
5428 } else if (strcmp(type, "blob") == 0) {
5429 if (!cson_value_is_string(v)) return -1;
5430 const char *s = cson_value_get_cstr(v);
5431 size_t l = strlen(s);
5432 uint8_t *b = malloc(l / 2);
5433 luabb_fromhex(b, (uint8_t *)s, l);
5434 blob_t x = {.data = b, .length = l / 2};
5435 luabb_pushblob_dl(L, &x);
5436 } else if (strcmp(type, "datetime") == 0) {
5437 if (!cson_value_is_string(v)) return -1;
5438 datetime_t d;

Callers 1

cson_to_table_annotatedFunction · 0.85

Calls 15

cson_value_get_objectFunction · 0.85
cson_object_getFunction · 0.85
cson_value_is_stringFunction · 0.85
cson_value_get_cstrFunction · 0.85
cson_value_is_nullFunction · 0.85
cson_push_nullFunction · 0.85
cson_to_table_annotatedFunction · 0.85
lua_pushstringFunction · 0.85
luabb_pushcstringFunction · 0.85
mallocFunction · 0.85
luabb_fromhexFunction · 0.85
luabb_pushcstring_dlFunction · 0.85

Tested by

no test coverage detected