/* 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 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;
l = zipmapDecodeLength(p);
printf("{key %u}",l);
p += zipmapEncodeLength(NULL,l);
- fwrite(p,l,1,stdout);
+ if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
p += l;
l = zipmapDecodeLength(p);
printf("{value %u}",l);
p += zipmapEncodeLength(NULL,l);
e = *p++;
- fwrite(p,l,1,stdout);
+ if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
p += l+e;
if (e) {
printf("[");
printf("\n");
}
-#ifdef ZIPMAP_TEST_MAIN
int main(void) {
unsigned char *zm;