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

Function zipmapEncodeLength

src/zipmap.c:120–134  ·  view source on GitHub ↗

Encode the length 'l' writing it in 'p'. If p is NULL it just returns * the amount of bytes required to encode such a length. */

Source from the content-addressed store, hash-verified

118/* Encode the length 'l' writing it in 'p'. If p is NULL it just returns
119 * the amount of bytes required to encode such a length. */
120static unsigned int zipmapEncodeLength(unsigned char *p, unsigned int len) {
121 if (p == NULL) {
122 return ZIPMAP_LEN_BYTES(len);
123 } else {
124 if (len < ZIPMAP_BIGLEN) {
125 p[0] = len;
126 return 1;
127 } else {
128 p[0] = ZIPMAP_BIGLEN;
129 memcpy(p+1,&len,sizeof(len));
130 memrev32ifbe(p+1);
131 return 1+sizeof(len);
132 }
133 }
134}
135
136/* Search for a matching key, returning a pointer to the entry inside the
137 * zipmap. Returns NULL if the key is not found.

Callers 5

zipmapLookupRawFunction · 0.85
zipmapRawKeyLengthFunction · 0.85
zipmapRawValueLengthFunction · 0.85
zipmapSetFunction · 0.85
zipmapReprFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected