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

Function rdbEncodeInteger

src/rdb.cpp:258–278  ·  view source on GitHub ↗

Encodes the "value" argument as integer when it fits in the supported ranges * for encoded types. If the function successfully encodes the integer, the * representation is stored in the buffer pointer to by "enc" and the string * length is returned. Otherwise 0 is returned. */

Source from the content-addressed store, hash-verified

256 * representation is stored in the buffer pointer to by "enc" and the string
257 * length is returned. Otherwise 0 is returned. */
258int rdbEncodeInteger(long long value, unsigned char *enc) {
259 if (value >= -(1<<7) && value <= (1<<7)-1) {
260 enc[0] = (RDB_ENCVAL<<6)|RDB_ENC_INT8;
261 enc[1] = value&0xFF;
262 return 2;
263 } else if (value >= -(1<<15) && value <= (1<<15)-1) {
264 enc[0] = (RDB_ENCVAL<<6)|RDB_ENC_INT16;
265 enc[1] = value&0xFF;
266 enc[2] = (value>>8)&0xFF;
267 return 3;
268 } else if (value >= -((long long)1<<31) && value <= ((long long)1<<31)-1) {
269 enc[0] = (RDB_ENCVAL<<6)|RDB_ENC_INT32;
270 enc[1] = value&0xFF;
271 enc[2] = (value>>8)&0xFF;
272 enc[3] = (value>>16)&0xFF;
273 enc[4] = (value>>24)&0xFF;
274 return 5;
275 } else {
276 return 0;
277 }
278}
279
280/* Loads an integer-encoded object with the specified encoding type "enctype".
281 * The returned value changes according to the flags, see

Callers 2

rdbTryIntegerEncodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected