MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / rdbSaveLen

Function rdbSaveLen

src/rdb.cpp:164–195  ·  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

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