This is a wrapper function for lpGet() to directly get an integer value * from the listpack (that may store numbers as a string), converting * the string if needed. * The 'valid" argument is an optional output parameter to get an indication * if the record was valid, when this parameter is NULL, the function will * fail with an assertion. */
| 272 | * if the record was valid, when this parameter is NULL, the function will |
| 273 | * fail with an assertion. */ |
| 274 | static inline int64_t lpGetIntegerIfValid(unsigned char *ele, int *valid) { |
| 275 | int64_t v; |
| 276 | unsigned char *e = lpGet(ele,&v,NULL); |
| 277 | if (e == NULL) { |
| 278 | if (valid) |
| 279 | *valid = 1; |
| 280 | return v; |
| 281 | } |
| 282 | /* The following code path should never be used for how listpacks work: |
| 283 | * they should always be able to store an int64_t value in integer |
| 284 | * encoded form. However the implementation may change. */ |
| 285 | long long ll; |
| 286 | int ret = string2ll((char*)e,v,&ll); |
| 287 | if (valid) |
| 288 | *valid = ret; |
| 289 | else |
| 290 | serverAssert(ret != 0); |
| 291 | v = ll; |
| 292 | return v; |
| 293 | } |
| 294 | |
| 295 | #define lpGetInteger(ele) lpGetIntegerIfValid(ele, NULL) |
| 296 |
no test coverage detected