]>
git.saurik.com Git - redis.git/blob - zip.c
4 /* The following macro returns the number of bytes needed to encode the length
5 * for the integer value _l, that is, 1 byte for lengths < ZIP_BIGLEN and
6 * 5 bytes for all the other lengths. */
7 #define ZIP_LEN_BYTES(_l) (((_l) < ZIP_BIGLEN) ? 1 : sizeof(unsigned int)+1)
9 /* Decode the encoded length pointed by 'p' */
10 static unsigned int zipDecodeLength(unsigned char *p
) {
11 unsigned int len
= *p
;
13 if (len
< ZIP_BIGLEN
) return len
;
14 memcpy(&len
,p
+1,sizeof(unsigned int));
18 /* Encode the length 'l' writing it in 'p'. If p is NULL it just returns
19 * the amount of bytes required to encode such a length. */
20 static unsigned int zipEncodeLength(unsigned char *p
, unsigned int len
) {
22 return ZIP_LEN_BYTES(len
);
24 if (len
< ZIP_BIGLEN
) {
29 memcpy(p
+1,&len
,sizeof(len
));
35 /* Return the total amount used by an entry (encoded length + payload). */
36 static unsigned int zipRawEntryLength(unsigned char *p
) {
37 unsigned int l
= zipDecodeLength(p
);
38 return zipEncodeLength(NULL
,l
) + l
;
41 /* Resize the zip* structure. */
42 static unsigned char *zipResize(unsigned char *z
, unsigned int len
) {