return e;
}
-/* Return the total amount used by an entry (encoded length + payload). */
+/* Return the total number of bytes used by the entry at "p". */
static unsigned int zipRawEntryLength(unsigned char *p) {
- unsigned int prevlensize, lensize, len;
- /* Byte-size of encoded length of previous entry */
- zipDecodeLength(p,&prevlensize);
- /* Encoded length of this entry's payload */
- len = zipDecodeLength(p+prevlensize, &lensize);
- return prevlensize+lensize+len;
+ zlentry e = zipEntry(p);
+ return e.headersize + e.len;
}
/* Create a new empty ziplist. */
* 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 ziplistGet(unsigned char *p, unsigned char **sstr, unsigned int *slen, long long *sval) {
zlentry entry;
if (*p == ZIP_END) return 0;
- if (e) *e = NULL;
+ if (sstr) *sstr = NULL;
entry = zipEntry(p);
if (entry.encoding == ZIP_ENC_RAW) {
- if (e) {
- *elen = entry.len;
- *e = p+entry.headersize;
+ if (sstr) {
+ *slen = entry.len;
+ *sstr = p+entry.headersize;
}
} else {
- if (v) {
- *v = zipLoadInteger(p+entry.headersize,entry.encoding);
+ if (sval) {
+ *sval = zipLoadInteger(p+entry.headersize,entry.encoding);
}
}
return 1;
}
/* Compare entry pointer to by 'p' with 'entry'. Return 1 if equal. */
-unsigned int ziplistCompare(unsigned char *p, unsigned char *s, unsigned int slen) {
+unsigned int ziplistCompare(unsigned char *p, unsigned char *sstr, unsigned int slen) {
zlentry entry;
unsigned char sencoding;
long long val, sval;
if (entry.encoding == ZIP_ENC_RAW) {
/* Raw compare */
if (entry.len == slen) {
- return memcmp(p+entry.headersize,s,slen) == 0;
+ return memcmp(p+entry.headersize,sstr,slen) == 0;
} else {
return 0;
}
} else {
/* Try to compare encoded values */
- if (zipTryEncoding(s,&sval,&sencoding)) {
+ if (zipTryEncoding(sstr,&sval,&sencoding)) {
if (entry.encoding == sencoding) {
val = zipLoadInteger(p+entry.headersize,entry.encoding);
return val == sval;
}
void ziplistRepr(unsigned char *zl) {
- unsigned char *p, encoding;
- unsigned int prevrawlensize, prevrawlen, lensize, len;
+ unsigned char *p;
+ zlentry entry;
printf("{total bytes %d} {length %u}\n",ZIPLIST_BYTES(zl), ZIPLIST_LENGTH(zl));
p = ziplistHead(zl);
while(*p != ZIP_END) {
- prevrawlen = zipDecodeLength(p,&prevrawlensize);
- len = zipDecodeLength(p+prevrawlensize,&lensize);
- printf("{offset %ld, header %u, payload %u} ",p-zl,prevrawlensize+lensize,len);
- encoding = ZIP_ENCODING(p+prevrawlensize);
- p += prevrawlensize+lensize;
- if (encoding == ZIP_ENC_RAW) {
- fwrite(p,len,1,stdout);
+ entry = zipEntry(p);
+ printf("{offset %ld, header %u, payload %u} ",p-zl,entry.headersize,entry.len);
+ p += entry.headersize;
+ if (entry.encoding == ZIP_ENC_RAW) {
+ fwrite(p,entry.len,1,stdout);
} else {
- printf("%lld", zipLoadInteger(p,encoding));
+ printf("%lld", zipLoadInteger(p,entry.encoding));
}
printf("\n");
- p += len;
+ p += entry.len;
}
printf("{end}\n\n");
}