static int readBytes(void *target, long num) {
char peek = (num < 0) ? 1 : 0;
num = (num < 0) ? -num : num;
pos p = positions[level];
if (p.offset + num > p.size) {
return 0;
} else {
memcpy(target, (void*)((size_t)p.data + p.offset), num);
if (!peek) positions[level].offset += num;
}
return 1;
}
当num为负数的时候,只从position[level]中获取到指定大小绝对值的数,并不修改源内存的偏移量 position[level]从之前看到保存了Redis的rdb文件在内存中映射后的指针
typedef struct {
void *data;
size_t size;
size_t offset;
} pos;
static pos positions[16];