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

Function rdbLoadLenByRef

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

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

Source from the content-addressed store, hash-verified

200 *
201 * The function returns -1 on error, 0 on success. */
202int rdbLoadLenByRef(rio *rdb, int *isencoded, uint64_t *lenptr) {
203 unsigned char buf[2];
204 int type;
205
206 if (isencoded) *isencoded = 0;
207 if (rioRead(rdb,buf,1) == 0) return -1;
208 type = (buf[0]&0xC0)>>6;
209 if (type == RDB_ENCVAL) {
210 /* Read a 6 bit encoding type. */
211 if (isencoded) *isencoded = 1;
212 *lenptr = buf[0]&0x3F;
213 } else if (type == RDB_6BITLEN) {
214 /* Read a 6 bit len. */
215 *lenptr = buf[0]&0x3F;
216 } else if (type == RDB_14BITLEN) {
217 /* Read a 14 bit len. */
218 if (rioRead(rdb,buf+1,1) == 0) return -1;
219 *lenptr = ((buf[0]&0x3F)<<8)|buf[1];
220 } else if (buf[0] == RDB_32BITLEN) {
221 /* Read a 32 bit len. */
222 uint32_t len;
223 if (rioRead(rdb,&len,4) == 0) return -1;
224 *lenptr = ntohl(len);
225 } else if (buf[0] == RDB_64BITLEN) {
226 /* Read a 64 bit len. */
227 uint64_t len;
228 if (rioRead(rdb,&len,8) == 0) return -1;
229 *lenptr = ntohu64(len);
230 } else {
231 rdbReportCorruptRDB(
232 "Unknown length encoding %d in rdbLoadLen()",type);
233 return -1; /* Never reached. */
234 }
235 return 0;
236}
237
238/* This is like rdbLoadLenByRef() but directly returns the value read
239 * from the RDB stream, signaling an error by returning RDB_LENERR

Callers 3

rdbLoadLenFunction · 0.85
rdbLoadCheckModuleValueFunction · 0.85
RM_LoadUnsignedFunction · 0.85

Calls 1

rioReadFunction · 0.85

Tested by

no test coverage detected