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

Function zipmapNext

src/zipmap.c:319–334  ·  view source on GitHub ↗

This function is used to iterate through all the zipmap elements. * In the first call the first argument is the pointer to the zipmap + 1. * In the next calls what zipmapNext returns is used as first argument. * Example: * * unsigned char *i = zipmapRewind(my_zipmap); * while((i = zipmapNext(i,&key,&klen,&value,&vlen)) != NULL) { * printf("%d bytes key at $p\n", klen, key); * print

Source from the content-addressed store, hash-verified

317 * }
318 */
319unsigned char *zipmapNext(unsigned char *zm, unsigned char **key, unsigned int *klen, unsigned char **value, unsigned int *vlen) {
320 if (zm[0] == ZIPMAP_END) return NULL;
321 if (key) {
322 *key = zm;
323 *klen = zipmapDecodeLength(zm);
324 *key += ZIPMAP_LEN_BYTES(*klen);
325 }
326 zm += zipmapRawKeyLength(zm);
327 if (value) {
328 *value = zm+1;
329 *vlen = zipmapDecodeLength(zm);
330 *value += ZIPMAP_LEN_BYTES(*vlen);
331 }
332 zm += zipmapRawValueLength(zm);
333 return zm;
334}
335
336/* Search a key and retrieve the pointer and len of the associated value.
337 * If the key is found the function returns 1, otherwise 0. */

Callers 3

rdbLoadObjectFunction · 0.85
zipmapLenFunction · 0.85
zipmapTestFunction · 0.85

Calls 3

zipmapDecodeLengthFunction · 0.85
zipmapRawKeyLengthFunction · 0.85
zipmapRawValueLengthFunction · 0.85

Tested by

no test coverage detected