Loads an integer-encoded object with the specified encoding type "enctype". * The returned value changes according to the flags, see * rdbGenericLoadStringObject() for more info. */
| 276 | * The returned value changes according to the flags, see |
| 277 | * rdbGenericLoadStringObject() for more info. */ |
| 278 | void *rdbLoadIntegerObject(rio *rdb, int enctype, int flags, size_t *lenptr) { |
| 279 | int plain = flags & RDB_LOAD_PLAIN; |
| 280 | int sds = flags & RDB_LOAD_SDS; |
| 281 | int encode = flags & RDB_LOAD_ENC; |
| 282 | unsigned char enc[4]; |
| 283 | long long val; |
| 284 | |
| 285 | if (enctype == RDB_ENC_INT8) { |
| 286 | if (rioRead(rdb,enc,1) == 0) return NULL; |
| 287 | val = (signed char)enc[0]; |
| 288 | } else if (enctype == RDB_ENC_INT16) { |
| 289 | uint16_t v; |
| 290 | if (rioRead(rdb,enc,2) == 0) return NULL; |
| 291 | v = enc[0]|(enc[1]<<8); |
| 292 | val = (int16_t)v; |
| 293 | } else if (enctype == RDB_ENC_INT32) { |
| 294 | uint32_t v; |
| 295 | if (rioRead(rdb,enc,4) == 0) return NULL; |
| 296 | v = enc[0]|(enc[1]<<8)|(enc[2]<<16)|(enc[3]<<24); |
| 297 | val = (int32_t)v; |
| 298 | } else { |
| 299 | rdbReportCorruptRDB("Unknown RDB integer encoding type %d",enctype); |
| 300 | return NULL; /* Never reached. */ |
| 301 | } |
| 302 | if (plain || sds) { |
| 303 | char buf[LONG_STR_SIZE], *p; |
| 304 | int len = ll2string(buf,sizeof(buf),val); |
| 305 | if (lenptr) *lenptr = len; |
| 306 | p = plain ? zmalloc(len) : sdsnewlen(SDS_NOINIT,len); |
| 307 | memcpy(p,buf,len); |
| 308 | return p; |
| 309 | } else if (encode) { |
| 310 | return createStringObjectFromLongLongForValue(val); |
| 311 | } else { |
| 312 | return createObject(OBJ_STRING,sdsfromlonglong(val)); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | /* String objects in the form "2391" "-100" without any space and with a |
| 317 | * range of values that can fit in an 8, 16 or 32 bit signed value can be |
no test coverage detected