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

Function lookupStringForBitCommand

src/bitops.cpp:486–499  ·  view source on GitHub ↗

This is an helper function for commands implementations that need to write * bits to a string object. The command creates or pad with zeroes the string * so that the 'maxbit' bit can be addressed. The object is finally * returned. Otherwise if the key holds a wrong type NULL is returned and * an error is sent to the client. */

Source from the content-addressed store, hash-verified

484 * returned. Otherwise if the key holds a wrong type NULL is returned and
485 * an error is sent to the client. */
486robj *lookupStringForBitCommand(client *c, uint64_t maxbit) {
487 size_t byte = maxbit >> 3;
488 robj *o = lookupKeyWrite(c->db,c->argv[1]);
489 if (checkType(c,o,OBJ_STRING)) return NULL;
490
491 if (o == NULL) {
492 o = createObject(OBJ_STRING,sdsnewlen(NULL, byte+1));
493 dbAdd(c->db,c->argv[1],o);
494 } else {
495 o = dbUnshareStringValue(c->db,c->argv[1],o);
496 o->m_ptr = sdsgrowzero(szFromObj(o),byte+1);
497 }
498 return o;
499}
500
501/* Return a pointer to the string object content, and stores its length
502 * in 'len'. The user is required to pass (likely stack allocated) buffer

Callers 2

setbitCommandFunction · 0.85
bitfieldGenericFunction · 0.85

Calls 8

lookupKeyWriteFunction · 0.85
checkTypeFunction · 0.85
createObjectFunction · 0.85
sdsnewlenFunction · 0.85
dbAddFunction · 0.85
dbUnshareStringValueFunction · 0.85
sdsgrowzeroFunction · 0.85
szFromObjFunction · 0.85

Tested by

no test coverage detected