#include <string.h>
#include <assert.h>
#include "zmalloc.h"
+#include "endian.h"
#define ZIPMAP_BIGLEN 254
#define ZIPMAP_END 255
if (len < ZIPMAP_BIGLEN) return len;
memcpy(&len,p+1,sizeof(unsigned int));
+ memrev32ifbe(&len);
return len;
}
} else {
p[0] = ZIPMAP_BIGLEN;
memcpy(p+1,&len,sizeof(len));
+ memrev32ifbe(p+1);
return 1+sizeof(len);
}
}
/* Match or skip the key */
l = zipmapDecodeLength(p);
llen = zipmapEncodeLength(NULL,l);
- if (k == NULL && l == klen && !memcmp(p+llen,key,l)) {
+ if (key != NULL && k == NULL && l == klen && !memcmp(p+llen,key,l)) {
/* Only return when the user doesn't care
* for the total length of the zipmap. */
if (totlen != NULL) {
return zm;
}
-/* Call it before to iterate trought elements via zipmapNext() */
+/* Call before iterating through elements via zipmapNext() */
unsigned char *zipmapRewind(unsigned char *zm) {
return zm+1;
}
return len;
}
+/* Return the raw size in bytes of a zipmap, so that we can serialize
+ * the zipmap on disk (or everywhere is needed) just writing the returned
+ * amount of bytes of the C array starting at the zipmap pointer. */
+size_t zipmapBlobLen(unsigned char *zm) {
+ unsigned int totlen;
+ zipmapLookupRaw(zm,NULL,0,&totlen);
+ return totlen;
+}
+
+#ifdef ZIPMAP_TEST_MAIN
void zipmapRepr(unsigned char *p) {
unsigned int l;
printf("\n");
}
-#ifdef ZIPMAP_TEST_MAIN
int main(void) {
unsigned char *zm;
vlen, vlen, value);
}
}
- printf("\nIterate trought elements:\n");
+ printf("\nIterate through elements:\n");
{
unsigned char *i = zipmapRewind(zm);
unsigned char *key, *value;