Skip to content

Commit 6a508a6

Browse files
committed
Add unpack_uint{16,64}
1 parent 57dabd7 commit 6a508a6

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

hton.h

+24-12
Original file line numberDiff line numberDiff line change
@@ -146,38 +146,50 @@ pack_int64(char *buf, int64_t x)
146146
}
147147

148148

149-
static inline int16_t
150-
unpack_int16(const char *buf)
149+
150+
static inline uint16_t
151+
unpack_uint16(const char *buf)
151152
{
152153
uint16_t nx;
153154
memcpy((char *)&nx, buf, sizeof(uint16_t));
154-
return (int16_t)apg_ntoh16(nx);
155+
return apg_ntoh16(nx);
155156
}
156157

157158

158-
static inline int32_t
159-
unpack_int32(const char *buf)
159+
static inline int16_t
160+
unpack_int16(const char *buf)
160161
{
161-
uint32_t nx;
162-
memcpy((char *)&nx, buf, sizeof(uint32_t));
163-
return (int32_t)apg_ntoh32(nx);
162+
return (int16_t)unpack_uint16(buf);
164163
}
165164

165+
166166
static inline uint32_t
167167
unpack_uint32(const char *buf)
168168
{
169169
uint32_t nx;
170170
memcpy((char *)&nx, buf, sizeof(uint32_t));
171-
return (uint32_t)apg_ntoh32(nx);
171+
return apg_ntoh32(nx);
172172
}
173173

174174

175-
static inline int64_t
176-
unpack_int64(const char *buf)
175+
static inline int32_t
176+
unpack_int32(const char *buf)
177+
{
178+
return (int32_t)unpack_uint32(nx);
179+
}
180+
181+
static inline uint64_t
182+
unpack_uint64(const char *buf)
177183
{
178184
uint64_t nx;
179185
memcpy((char *)&nx, buf, sizeof(uint64_t));
180-
return (int64_t)apg_ntoh64(nx);
186+
return apg_ntoh64(nx);
187+
}
188+
189+
static inline int64_t
190+
unpack_int64(const char *buf)
191+
{
192+
return (int64_t)unpack_uint64(buf);
181193
}
182194

183195

hton.pxd

+2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ cdef extern from "./hton.h":
1515
cdef void pack_float(char *buf, float f);
1616
cdef void pack_double(char *buf, double f);
1717
cdef int16_t unpack_int16(const char *buf);
18+
cdef uint16_t unpack_uint16(const char *buf);
1819
cdef int32_t unpack_int32(const char *buf);
1920
cdef uint32_t unpack_uint32(const char *buf);
2021
cdef int64_t unpack_int64(const char *buf);
22+
cdef uint64_t unpack_uint64(const char *buf);
2123
cdef float unpack_float(const char *buf);
2224
cdef double unpack_double(const char *buf);

0 commit comments

Comments
 (0)