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

Function writeNestedHashAsJson

src/t_nhash.cpp:292–336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290}
291
292sds writeNestedHashAsJson(sds output, robj_roptr o) {
293 if (o->type == OBJ_STRING) {
294 output = writeJsonValue(output, (sds)szFromObj(o));
295 } else if (o->type == OBJ_LIST) {
296 unsigned char *zl = (unsigned char*)ptrFromObj(o);
297 output = sdscat(output, "[");
298 unsigned char *p = ziplistIndex(zl, ZIPLIST_HEAD);
299 bool fFirst = true;
300 while (p != nullptr) {
301 unsigned char *str;
302 unsigned int len;
303 long long lval;
304 if (ziplistGet(p, &str, &len, &lval)) {
305 char rgT[128];
306 if (str == nullptr) {
307 len = ll2string(rgT, 128, lval);
308 str = (unsigned char*)rgT;
309 }
310 if (!fFirst)
311 output = sdscat(output, ",");
312 fFirst = false;
313 output = writeJsonValue(output, (const char*)str, len);
314 }
315 p = ziplistNext(zl, p);
316 }
317 output = sdscat(output, "]");
318 } else {
319 output = sdscat(output, "{");
320 dictIterator *di = dictGetIterator((dict*)ptrFromObj(o));
321 dictEntry *de;
322 bool fFirst = true;
323 while ((de = dictNext(di))) {
324 robj_roptr oT = (robj*)dictGetVal(de);
325 if (!fFirst)
326 output = sdscat(output, ",");
327 fFirst = false;
328 output = writeJsonValue(output, (sds)dictGetKey(de));
329 output = sdscat(output, " : ");
330 output = writeNestedHashAsJson(output, oT);
331 }
332 dictReleaseIterator(di);
333 output = sdscat(output, "}");
334 }
335 return output;
336}
337
338void nhsetCommand(client *c) {
339 if (c->argc < 3)

Callers 1

nhgetCommandFunction · 0.85

Calls 11

writeJsonValueFunction · 0.85
szFromObjFunction · 0.85
ptrFromObjFunction · 0.85
sdscatFunction · 0.85
ziplistIndexFunction · 0.85
ziplistGetFunction · 0.85
ll2stringFunction · 0.85
ziplistNextFunction · 0.85
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected