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

Function rdbLoadIntegerObject

src/rdb.cpp:283–319  ·  view source on GitHub ↗

Loads an integer-encoded object with the specified encoding type "enctype". * The returned value changes according to the flags, see * rdbGenericLoadStringObject() for more info. */

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 7

rioReadFunction · 0.85
ll2stringFunction · 0.85
zmallocFunction · 0.85
sdsnewlenFunction · 0.85
createObjectFunction · 0.85
sdsfromlonglongFunction · 0.85

Tested by

no test coverage detected