SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Saves an encoded length. The first two bits in the first byte are used to
  2.  * hold the encoding type. See the REDIS_RDB_* definitions for more information
  3.  * on the types of encoding. */
  4. int rdbSaveLen(rio *rdb, uint32_t len) {
  5.     unsigned char buf[2];
  6.     size_t nwritten;
  7.  
  8.     if (len < (1<<6)) {
  9.         /* Save a 6 bit len */
  10.         buf[0] = (len&0xFF)|(REDIS_RDB_6BITLEN<<6);
  11.         if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
  12.         nwritten = 1;
  13.     } else if (len < (1<<14)) {
  14.         /* Save a 14 bit len */
  15.         buf[0] = ((len>>8)&0xFF)|(REDIS_RDB_14BITLEN<<6);
  16.         buf[1] = len&0xFF;
  17.         if (rdbWriteRaw(rdb,buf,2) == -1) return -1;
  18.         nwritten = 2;
  19.     } else {
  20.         /* Save a 32 bit len */
  21.         buf[0] = (REDIS_RDB_32BITLEN<<6);
  22.         if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
  23.         len = htonl(len);
  24.         if (rdbWriteRaw(rdb,&len,4) == -1) return -1;
  25.         nwritten = 1+4;
  26.     }
  27.     return nwritten;
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top