Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Saves an encoded length. The first two bits in the first byte are used to
- * hold the encoding type. See the REDIS_RDB_* definitions for more information
- * on the types of encoding. */
- int rdbSaveLen(rio *rdb, uint32_t len) {
- unsigned char buf[2];
- size_t nwritten;
- if (len < (1<<6)) {
- /* Save a 6 bit len */
- buf[0] = (len&0xFF)|(REDIS_RDB_6BITLEN<<6);
- if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
- nwritten = 1;
- } else if (len < (1<<14)) {
- /* Save a 14 bit len */
- buf[0] = ((len>>8)&0xFF)|(REDIS_RDB_14BITLEN<<6);
- buf[1] = len&0xFF;
- if (rdbWriteRaw(rdb,buf,2) == -1) return -1;
- nwritten = 2;
- } else {
- /* Save a 32 bit len */
- buf[0] = (REDIS_RDB_32BITLEN<<6);
- if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
- len = htonl(len);
- if (rdbWriteRaw(rdb,&len,4) == -1) return -1;
- nwritten = 1+4;
- }
- return nwritten;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement