/* Store entry at current position in sds *value and return pointer
* to the next entry. */
-unsigned char *ziplistNext(unsigned char *p, sds *value) {
+unsigned char *ziplistNext(unsigned char *p, unsigned char **entry, unsigned int *elen) {
if (*p == ZIP_END) return NULL;
- if (value) {
- unsigned int len;
- len = zipDecodeLength(p);
- *value = sdsnewlen(p+zipEncodeLength(NULL,len),len);
+ if (entry) {
+ *elen = zipDecodeLength(p);
+ *entry = p+ZIP_LEN_BYTES(*elen);
}
p += zipRawEntryLength(p);
return p;
}
int main(int argc, char **argv) {
- unsigned char *zl, *p;
+ unsigned char *zl, *p, *entry;
+ unsigned int elen;
sds s;
zl = createList();
{
zl = createList();
p = ziplistIndex(zl, 0);
- while ((p = ziplistNext(p, &s)) != NULL) {
- printf("Entry: %s (length %ld)\n", s, sdslen(s));
+ while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
+ printf("Entry: ");
+ fwrite(entry,elen,1,stdout);
+ printf(" (length %d)\n", elen);
}
printf("\n");
}
{
zl = createList();
p = ziplistIndex(zl, 1);
- while ((p = ziplistNext(p, &s)) != NULL) {
- printf("Entry: %s (length %ld)\n", s, sdslen(s));
+ while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
+ printf("Entry: ");
+ fwrite(entry,elen,1,stdout);
+ printf(" (length %d)\n", elen);
}
printf("\n");
}
{
zl = createList();
p = ziplistIndex(zl, 2);
- while ((p = ziplistNext(p, &s)) != NULL) {
- printf("Entry: %s (length %ld)\n", s, sdslen(s));
+ while ((p = ziplistNext(p, &entry, &elen)) != NULL) {
+ printf("Entry: ");
+ fwrite(entry,elen,1,stdout);
+ printf(" (length %d)\n", elen);
}
printf("\n");
}
{
zl = createList();
p = ziplistIndex(zl, 3);
- if (ziplistNext(p, &s) == NULL) {
+ if (ziplistNext(p, &entry, &elen) == NULL) {
printf("No entry\n");
} else {
printf("ERROR\n");