check whether the bit length is fit to given number sign. Redis has bits length limitation to bitfield. Quote: The supported encodings are up to 64 bits for signed integers, and up to 63 bits for unsigned integers. This limitation with unsigned integers is due to the fact that currently the Redis protocol is unable to return 64 bit unsigned integers as replies. see also https://redis.io/commands/b
| 42 | // unsigned integers as replies. |
| 43 | // see also https://redis.io/commands/bitfield/ |
| 44 | static Status CheckSupportedBitLengths(Type type, uint8_t bits) noexcept { |
| 45 | uint8_t max_bits = 64; |
| 46 | if (type == Type::kUnsigned) { |
| 47 | max_bits = 63; |
| 48 | } |
| 49 | if (1 <= bits && bits <= max_bits) { |
| 50 | return Status::OK(); |
| 51 | } |
| 52 | |
| 53 | return {Status::NotOK, "Unsupported new bits length, only i1~i64, u1~u63 are supported."}; |
| 54 | } |
| 55 | |
| 56 | static StatusOr<BitfieldEncoding> Create(Type type, uint8_t bits) noexcept { |
| 57 | Status bits_status(CheckSupportedBitLengths(type, bits)); |
nothing calls this directly
no outgoing calls
no test coverage detected