MCPcopy Create free account
hub / github.com/F-Stack/f-stack / rdbLoadLzfStringObject

Function rdbLoadLzfStringObject

app/redis-6.2.6/src/rdb.c:381–428  ·  view source on GitHub ↗

Load an LZF compressed string in RDB format. The returned value * changes according to 'flags'. For more info check the * rdbGenericLoadStringObject() function. */

Source from the content-addressed store, hash-verified

379 * changes according to 'flags'. For more info check the
380 * rdbGenericLoadStringObject() function. */
381void *rdbLoadLzfStringObject(rio *rdb, int flags, size_t *lenptr) {
382 int plain = flags & RDB_LOAD_PLAIN;
383 int sds = flags & RDB_LOAD_SDS;
384 uint64_t len, clen;
385 unsigned char *c = NULL;
386 char *val = NULL;
387
388 if ((clen = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL;
389 if ((len = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL;
390 if ((c = ztrymalloc(clen)) == NULL) {
391 serverLog(server.loading? LL_WARNING: LL_VERBOSE, "rdbLoadLzfStringObject failed allocating %llu bytes", (unsigned long long)clen);
392 goto err;
393 }
394
395 /* Allocate our target according to the uncompressed size. */
396 if (plain) {
397 val = ztrymalloc(len);
398 } else {
399 val = sdstrynewlen(SDS_NOINIT,len);
400 }
401 if (!val) {
402 serverLog(server.loading? LL_WARNING: LL_VERBOSE, "rdbLoadLzfStringObject failed allocating %llu bytes", (unsigned long long)len);
403 goto err;
404 }
405
406 if (lenptr) *lenptr = len;
407
408 /* Load the compressed representation and uncompress it to target. */
409 if (rioRead(rdb,c,clen) == 0) goto err;
410 if (lzf_decompress(c,clen,val,len) != len) {
411 rdbReportCorruptRDB("Invalid LZF compressed string");
412 goto err;
413 }
414 zfree(c);
415
416 if (plain || sds) {
417 return val;
418 } else {
419 return createObject(OBJ_STRING,val);
420 }
421err:
422 zfree(c);
423 if (plain)
424 zfree(val);
425 else
426 sdsfree(val);
427 return NULL;
428}
429
430/* Save a string object as [len][data] on disk. If the object is a string
431 * representation of an integer value we try to save it in a special form */

Callers 1

Calls 8

rdbLoadLenFunction · 0.85
ztrymallocFunction · 0.85
sdstrynewlenFunction · 0.85
rioReadFunction · 0.85
lzf_decompressFunction · 0.85
createObjectFunction · 0.85
sdsfreeFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected