Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
f2204374
Commit
f2204374
authored
Mar 09, 2011
by
antirez
Browse files
ziplist are now endianess agnostic
parent
336c82d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/ziplist.c
View file @
f2204374
...
@@ -68,6 +68,7 @@
...
@@ -68,6 +68,7 @@
#include <limits.h>
#include <limits.h>
#include "zmalloc.h"
#include "zmalloc.h"
#include "ziplist.h"
#include "ziplist.h"
#include "endian.h"
int
ll2string
(
char
*
s
,
size_t
len
,
long
long
value
);
int
ll2string
(
char
*
s
,
size_t
len
,
long
long
value
);
...
@@ -207,6 +208,7 @@ static unsigned int zipPrevDecodeLength(unsigned char *p, unsigned int *lensize)
...
@@ -207,6 +208,7 @@ static unsigned int zipPrevDecodeLength(unsigned char *p, unsigned int *lensize)
}
else
{
}
else
{
if
(
lensize
)
*
lensize
=
1
+
sizeof
(
len
);
if
(
lensize
)
*
lensize
=
1
+
sizeof
(
len
);
memcpy
(
&
len
,
p
+
1
,
sizeof
(
len
));
memcpy
(
&
len
,
p
+
1
,
sizeof
(
len
));
memrev32ifbe
(
&
len
);
}
}
return
len
;
return
len
;
}
}
...
@@ -223,6 +225,7 @@ static unsigned int zipPrevEncodeLength(unsigned char *p, unsigned int len) {
...
@@ -223,6 +225,7 @@ static unsigned int zipPrevEncodeLength(unsigned char *p, unsigned int len) {
}
else
{
}
else
{
p
[
0
]
=
ZIP_BIGLEN
;
p
[
0
]
=
ZIP_BIGLEN
;
memcpy
(
p
+
1
,
&
len
,
sizeof
(
len
));
memcpy
(
p
+
1
,
&
len
,
sizeof
(
len
));
memrev32ifbe
(
p
+
1
);
return
1
+
sizeof
(
len
);
return
1
+
sizeof
(
len
);
}
}
}
}
...
@@ -234,6 +237,7 @@ static void zipPrevEncodeLengthForceLarge(unsigned char *p, unsigned int len) {
...
@@ -234,6 +237,7 @@ static void zipPrevEncodeLengthForceLarge(unsigned char *p, unsigned int len) {
if
(
p
==
NULL
)
return
;
if
(
p
==
NULL
)
return
;
p
[
0
]
=
ZIP_BIGLEN
;
p
[
0
]
=
ZIP_BIGLEN
;
memcpy
(
p
+
1
,
&
len
,
sizeof
(
len
));
memcpy
(
p
+
1
,
&
len
,
sizeof
(
len
));
memrev32ifbe
(
p
+
1
);
}
}
/* Return the difference in number of bytes needed to store the new length
/* Return the difference in number of bytes needed to store the new length
...
@@ -287,12 +291,15 @@ static void zipSaveInteger(unsigned char *p, int64_t value, unsigned char encodi
...
@@ -287,12 +291,15 @@ static void zipSaveInteger(unsigned char *p, int64_t value, unsigned char encodi
if
(
encoding
==
ZIP_INT_16B
)
{
if
(
encoding
==
ZIP_INT_16B
)
{
i16
=
value
;
i16
=
value
;
memcpy
(
p
,
&
i16
,
sizeof
(
i16
));
memcpy
(
p
,
&
i16
,
sizeof
(
i16
));
memrev16ifbe
(
p
);
}
else
if
(
encoding
==
ZIP_INT_32B
)
{
}
else
if
(
encoding
==
ZIP_INT_32B
)
{
i32
=
value
;
i32
=
value
;
memcpy
(
p
,
&
i32
,
sizeof
(
i32
));
memcpy
(
p
,
&
i32
,
sizeof
(
i32
));
memrev32ifbe
(
p
);
}
else
if
(
encoding
==
ZIP_INT_64B
)
{
}
else
if
(
encoding
==
ZIP_INT_64B
)
{
i64
=
value
;
i64
=
value
;
memcpy
(
p
,
&
i64
,
sizeof
(
i64
));
memcpy
(
p
,
&
i64
,
sizeof
(
i64
));
memrev64ifbe
(
p
);
}
else
{
}
else
{
assert
(
NULL
);
assert
(
NULL
);
}
}
...
@@ -305,12 +312,15 @@ static int64_t zipLoadInteger(unsigned char *p, unsigned char encoding) {
...
@@ -305,12 +312,15 @@ static int64_t zipLoadInteger(unsigned char *p, unsigned char encoding) {
int64_t
i64
,
ret
=
0
;
int64_t
i64
,
ret
=
0
;
if
(
encoding
==
ZIP_INT_16B
)
{
if
(
encoding
==
ZIP_INT_16B
)
{
memcpy
(
&
i16
,
p
,
sizeof
(
i16
));
memcpy
(
&
i16
,
p
,
sizeof
(
i16
));
memrev16ifbe
(
&
i16
);
ret
=
i16
;
ret
=
i16
;
}
else
if
(
encoding
==
ZIP_INT_32B
)
{
}
else
if
(
encoding
==
ZIP_INT_32B
)
{
memcpy
(
&
i32
,
p
,
sizeof
(
i32
));
memcpy
(
&
i32
,
p
,
sizeof
(
i32
));
memrev16ifbe
(
&
i32
);
ret
=
i32
;
ret
=
i32
;
}
else
if
(
encoding
==
ZIP_INT_64B
)
{
}
else
if
(
encoding
==
ZIP_INT_64B
)
{
memcpy
(
&
i64
,
p
,
sizeof
(
i64
));
memcpy
(
&
i64
,
p
,
sizeof
(
i64
));
memrev16ifbe
(
&
i64
);
ret
=
i64
;
ret
=
i64
;
}
else
{
}
else
{
assert
(
NULL
);
assert
(
NULL
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment