34 #if !HAVE_DECL_BE64ENC 35 #undef HAVE_SYS_ENDIAN_H 38 #ifdef HAVE_SYS_ENDIAN_H 40 #include <sys/endian.h> 46 #define INLINE __inline 52 be32dec(
const void *pp)
54 const uint8_t *p = (uint8_t
const *)pp;
56 return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
57 ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
61 be32enc(
void *pp, uint32_t
x)
63 uint8_t * p = (uint8_t *)pp;
66 p[2] = (x >> 8) & 0xff;
67 p[1] = (x >> 16) & 0xff;
68 p[0] = (x >> 24) & 0xff;
72 be64dec(
const void *pp)
74 const uint8_t *p = (uint8_t
const *)pp;
76 return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
77 ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
78 ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
79 ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
83 be64enc(
void *pp, uint64_t
x)
85 uint8_t * p = (uint8_t *)pp;
88 p[6] = (x >> 8) & 0xff;
89 p[5] = (x >> 16) & 0xff;
90 p[4] = (x >> 24) & 0xff;
91 p[3] = (x >> 32) & 0xff;
92 p[2] = (x >> 40) & 0xff;
93 p[1] = (x >> 48) & 0xff;
94 p[0] = (x >> 56) & 0xff;
98 le32dec(
const void *pp)
100 const uint8_t *p = (uint8_t
const *)pp;
102 return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
103 ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
107 le32enc(
void *pp, uint32_t
x)
109 uint8_t * p = (uint8_t *)pp;
112 p[1] = (x >> 8) & 0xff;
113 p[2] = (x >> 16) & 0xff;
114 p[3] = (x >> 24) & 0xff;
118 le64dec(
const void *pp)
120 const uint8_t *p = (uint8_t
const *)pp;
122 return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
123 ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
124 ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
125 ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
129 le64enc(
void *pp, uint64_t
x)
131 uint8_t * p = (uint8_t *)pp;
134 p[1] = (x >> 8) & 0xff;
135 p[2] = (x >> 16) & 0xff;
136 p[3] = (x >> 24) & 0xff;
137 p[4] = (x >> 32) & 0xff;
138 p[5] = (x >> 40) & 0xff;
139 p[6] = (x >> 48) & 0xff;
140 p[7] = (x >> 56) & 0xff;