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

Function rdbSaveLzfStringObject

src/rdb.cpp:365–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363}
364
365ssize_t rdbSaveLzfStringObject(rio *rdb, const unsigned char *s, size_t len) {
366 char rgbuf[2048];
367 size_t comprlen, outlen;
368 void *out = rgbuf;
369
370 /* We require at least four bytes compression for this to be worth it */
371 if (len <= 4) return 0;
372 outlen = len-4;
373 if (outlen >= sizeof(rgbuf))
374 if ((out = zmalloc(outlen+1, MALLOC_LOCAL)) == NULL) return 0;
375 comprlen = lzf_compress(s, len, out, outlen);
376 if (comprlen == 0) {
377 if (out != rgbuf)
378 zfree(out);
379 return 0;
380 }
381 ssize_t nwritten = rdbSaveLzfBlob(rdb, out, comprlen, len);
382 if (out != rgbuf)
383 zfree(out);
384 return nwritten;
385}
386
387/* Load an LZF compressed string in RDB format. The returned value
388 * changes according to 'flags'. For more info check the

Callers 1

rdbSaveRawStringFunction · 0.85

Calls 4

zmallocFunction · 0.85
lzf_compressFunction · 0.85
zfreeFunction · 0.85
rdbSaveLzfBlobFunction · 0.85

Tested by

no test coverage detected