]> git.saurik.com Git - redis.git/blobdiff - zipmap.c
support for include directive in config parser
[redis.git] / zipmap.c
index 05bf6d6d9983d64d4055d43379da1f626b6b642c..f45ef0dd64c7d795638178d732934bb9755b6a36 100644 (file)
--- a/zipmap.c
+++ b/zipmap.c
@@ -116,7 +116,7 @@ static unsigned int zipmapDecodeLength(unsigned char *p) {
     unsigned int len = *p;
 
     if (len < ZIPMAP_BIGLEN) return len;
-    memcpy(&len,p,sizeof(unsigned int));
+    memcpy(&len,p+1,sizeof(unsigned int));
     return len;
 }
 
@@ -363,6 +363,15 @@ int zipmapExists(unsigned char *zm, unsigned char *key, unsigned int klen) {
     return zipmapLookupRaw(zm,key,klen,NULL,NULL,NULL) != NULL;
 }
 
+/* Return the number of entries inside a zipmap */
+unsigned int zipmapLen(unsigned char *zm) {
+    unsigned char *p = zipmapRewind(zm);
+    unsigned int len = 0;
+
+    while((p = zipmapNext(p,NULL,NULL,NULL,NULL)) != NULL) len++;
+    return len;
+}
+
 void zipmapRepr(unsigned char *p) {
     unsigned int l;
 
@@ -405,6 +414,13 @@ int main(void) {
     unsigned char *zm;
 
     zm = zipmapNew();
+
+    zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
+    zm = zipmapSet(zm,(unsigned char*) "surname",7, (unsigned char*) "foo",3,NULL);
+    zm = zipmapSet(zm,(unsigned char*) "age",3, (unsigned char*) "foo",3,NULL);
+    zipmapRepr(zm);
+    exit(1);
+
     zm = zipmapSet(zm,(unsigned char*) "hello",5, (unsigned char*) "world!",6,NULL);
     zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "bar",3,NULL);
     zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "!",1,NULL);