Load an encoded length. If the loaded length is a normal length as stored * with rdbSaveLen(), the read length is set to '*lenptr'. If instead the * loaded length describes a special encoding that follows, then '*isencoded' * is set to 1 and the encoding format is stored at '*lenptr'. * * See the RDB_ENC_* definitions in rdb.h for more information on special * encodings. * * The function r
| 205 | * |
| 206 | * The function returns -1 on error, 0 on success. */ |
| 207 | int rdbLoadLenByRef(rio *rdb, int *isencoded, uint64_t *lenptr) { |
| 208 | unsigned char buf[2]; |
| 209 | int type; |
| 210 | |
| 211 | if (isencoded) *isencoded = 0; |
| 212 | if (rioRead(rdb,buf,1) == 0) return -1; |
| 213 | type = (buf[0]&0xC0)>>6; |
| 214 | if (type == RDB_ENCVAL) { |
| 215 | /* Read a 6 bit encoding type. */ |
| 216 | if (isencoded) *isencoded = 1; |
| 217 | *lenptr = buf[0]&0x3F; |
| 218 | } else if (type == RDB_6BITLEN) { |
| 219 | /* Read a 6 bit len. */ |
| 220 | *lenptr = buf[0]&0x3F; |
| 221 | } else if (type == RDB_14BITLEN) { |
| 222 | /* Read a 14 bit len. */ |
| 223 | if (rioRead(rdb,buf+1,1) == 0) return -1; |
| 224 | *lenptr = ((buf[0]&0x3F)<<8)|buf[1]; |
| 225 | } else if (buf[0] == RDB_32BITLEN) { |
| 226 | /* Read a 32 bit len. */ |
| 227 | uint32_t len; |
| 228 | if (rioRead(rdb,&len,4) == 0) return -1; |
| 229 | *lenptr = ntohl(len); |
| 230 | } else if (buf[0] == RDB_64BITLEN) { |
| 231 | /* Read a 64 bit len. */ |
| 232 | uint64_t len; |
| 233 | if (rioRead(rdb,&len,8) == 0) return -1; |
| 234 | *lenptr = ntohu64(len); |
| 235 | } else { |
| 236 | rdbReportCorruptRDB( |
| 237 | "Unknown length encoding %d in rdbLoadLen()",type); |
| 238 | return -1; /* Never reached. */ |
| 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | /* This is like rdbLoadLenByRef() but directly returns the value read |
| 244 | * from the RDB stream, signaling an error by returning RDB_LENERR |
no test coverage detected