-/* Store entry at current position in sds *value and return pointer
- * to the next entry. */
-unsigned char *ziplistNext(unsigned char *p, unsigned char **q, unsigned char **entry, unsigned int *elen) {
- unsigned int lensize;
- if (*p == ZIP_END) return NULL;
- if (entry) {
- *elen = zipDecodeLength(p,&lensize);
- *entry = p+lensize;
+/* Return pointer to next entry in ziplist. */
+unsigned char *ziplistNext(unsigned char *p) {
+ return *p == ZIP_END ? p : p+zipRawEntryLength(p);
+}
+
+/* Get entry pointer to by 'p' and store in either 'e' or 'v' depending
+ * on the encoding of the entry. 'e' is always set to NULL to be able
+ * to find out whether the string pointer or the integer value was set.
+ * Return 0 if 'p' points to the end of the zipmap, 1 otherwise. */
+unsigned int ziplistGet(unsigned char *p, unsigned char **e, unsigned int *elen, long long *v) {
+ unsigned int len, lensize;
+ if (*p == ZIP_END) return 0;
+ if (e) *e = NULL;
+ len = zipDecodeLength(p,&lensize);
+ if (ZIP_ENCODING(p) == ZIP_ENC_RAW) {
+ if (e) {
+ *elen = len;
+ *e = p+lensize;
+ }
+ } else {
+ if (v) {
+ *v = zipLoadInteger(p+lensize,ZIP_ENCODING(p));
+ }