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

Function getbitCommand

src/bitops.cpp:572–596  ·  view source on GitHub ↗

GETBIT key offset */

Source from the content-addressed store, hash-verified

570
571/* GETBIT key offset */
572void getbitCommand(client *c) {
573 robj_roptr o;
574 char llbuf[32];
575 uint64_t bitoffset;
576 size_t byte, bit;
577 size_t bitval = 0;
578
579 if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset,0,0) != C_OK)
580 return;
581
582 if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == nullptr ||
583 checkType(c,o,OBJ_STRING)) return;
584
585 byte = bitoffset >> 3;
586 bit = 7 - (bitoffset & 0x7);
587 if (sdsEncodedObject(o)) {
588 if (byte < sdslen(szFromObj(o)))
589 bitval = ((uint8_t*)ptrFromObj(o))[byte] & (1 << bit);
590 } else {
591 if (byte < (size_t)ll2string(llbuf,sizeof(llbuf),(long)ptrFromObj(o)))
592 bitval = llbuf[byte] & (1 << bit);
593 }
594
595 addReply(c, bitval ? shared.cone : shared.czero);
596}
597
598/* BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */
599void bitopCommand(client *c) {

Callers

nothing calls this directly

Calls 8

getBitOffsetFromArgumentFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
sdslenFunction · 0.85
szFromObjFunction · 0.85
ptrFromObjFunction · 0.85
ll2stringFunction · 0.85
addReplyFunction · 0.85

Tested by

no test coverage detected