Skip to content

Commit d75d804

Browse files
authored
Merge pull request #3 from tailhook/unpack_uint32
Add unpack_uint32 function
2 parents 3158dbb + e020c46 commit d75d804

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

hton.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,30 +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)
161+
{
162+
return (int16_t)unpack_uint16(buf);
163+
}
164+
165+
166+
static inline uint32_t
167+
unpack_uint32(const char *buf)
160168
{
161169
uint32_t nx;
162170
memcpy((char *)&nx, buf, sizeof(uint32_t));
163-
return (int32_t)apg_ntoh32(nx);
171+
return apg_ntoh32(nx);
164172
}
165173

166174

167-
static inline int64_t
168-
unpack_int64(const char *buf)
175+
static inline int32_t
176+
unpack_int32(const char *buf)
177+
{
178+
return (int32_t)unpack_uint32(buf);
179+
}
180+
181+
static inline uint64_t
182+
unpack_uint64(const char *buf)
169183
{
170184
uint64_t nx;
171185
memcpy((char *)&nx, buf, sizeof(uint64_t));
172-
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);
173193
}
174194

175195

hton.pxd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +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);
20+
cdef uint32_t unpack_uint32(const char *buf);
1921
cdef int64_t unpack_int64(const char *buf);
22+
cdef uint64_t unpack_uint64(const char *buf);
2023
cdef float unpack_float(const char *buf);
2124
cdef double unpack_double(const char *buf);

0 commit comments

Comments
 (0)