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

Function rdbSaveLen

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

Saves an encoded length. The first two bits in the first byte are used to * hold the encoding type. See the RDB_* definitions for more information * on the types of encoding. */

Source from the content-addressed store, hash-verified

157 * hold the encoding type. See the RDB_* definitions for more information
158 * on the types of encoding. */
159int rdbSaveLen(rio *rdb, uint64_t len) {
160 unsigned char buf[2];
161 size_t nwritten;
162
163 if (len < (1<<6)) {
164 /* Save a 6 bit len */
165 buf[0] = (len&0xFF)|(RDB_6BITLEN<<6);
166 if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
167 nwritten = 1;
168 } else if (len < (1<<14)) {
169 /* Save a 14 bit len */
170 buf[0] = ((len>>8)&0xFF)|(RDB_14BITLEN<<6);
171 buf[1] = len&0xFF;
172 if (rdbWriteRaw(rdb,buf,2) == -1) return -1;
173 nwritten = 2;
174 } else if (len <= UINT32_MAX) {
175 /* Save a 32 bit len */
176 buf[0] = RDB_32BITLEN;
177 if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
178 uint32_t len32 = htonl(len);
179 if (rdbWriteRaw(rdb,&len32,4) == -1) return -1;
180 nwritten = 1+4;
181 } else {
182 /* Save a 64 bit len */
183 buf[0] = RDB_64BITLEN;
184 if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
185 len = htonu64(len);
186 if (rdbWriteRaw(rdb,&len,8) == -1) return -1;
187 nwritten = 1+8;
188 }
189 return nwritten;
190}
191
192
193/* Load an encoded length. If the loaded length is a normal length as stored

Callers 14

rdbSaveLzfBlobFunction · 0.85
rdbSaveRawStringFunction · 0.85
rdbSaveStreamPELFunction · 0.85
rdbSaveStreamConsumersFunction · 0.85
rdbSaveObjectFunction · 0.85
rdbSaveKeyValuePairFunction · 0.85
rdbSaveSingleModuleAuxFunction · 0.85
rdbSaveRioFunction · 0.85
RM_SaveUnsignedFunction · 0.85
RM_SaveStringFunction · 0.85
RM_SaveStringBufferFunction · 0.85

Calls 1

rdbWriteRawFunction · 0.85

Tested by

no test coverage detected