GETBIT key offset */
| 570 | |
| 571 | /* GETBIT key offset */ |
| 572 | void 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 */ |
| 599 | void bitopCommand(client *c) { |
nothing calls this directly
no test coverage detected