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

Function rdbEncodeInteger

app/redis-6.2.6/src/rdb.c:253–273  ·  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

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

Callers 2

rdbTryIntegerEncodingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected