5050# include <sys/endian.h>
5151#endif /* HAVE_SYS_ENDIAN_H */
5252
53- #include <nghttp3/nghttp3.h>
53+ #if defined(__APPLE__ )
54+ # include <libkern/OSByteOrder.h>
55+ #endif // __APPLE__
5456
55- #if defined(HAVE_BSWAP_64 ) || \
56- (defined(HAVE_DECL_BSWAP_64 ) && HAVE_DECL_BSWAP_64 > 0 )
57- # define nghttp3_bswap64 bswap_64
58- #else /* !HAVE_BSWAP_64 */
59- # define nghttp3_bswap64 (N ) \
60- ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
61- #endif /* !HAVE_BSWAP_64 */
57+ #include <nghttp3/nghttp3.h>
6258
6359#if defined(HAVE_BE64TOH ) || \
6460 (defined(HAVE_DECL_BE64TOH ) && HAVE_DECL_BE64TOH > 0 )
6965# define nghttp3_ntohl64 (N ) (N)
7066# define nghttp3_htonl64 (N ) (N)
7167# else /* !WORDS_BIGENDIAN */
68+ # if defined(HAVE_BSWAP_64 ) || \
69+ (defined(HAVE_DECL_BSWAP_64 ) && HAVE_DECL_BSWAP_64 > 0 )
70+ # define nghttp3_bswap64 bswap_64
71+ # elif defined(WIN32 )
72+ # define nghttp3_bswap64 _byteswap_uint64
73+ # elif defined(__APPLE__ )
74+ # define nghttp3_bswap64 OSSwapInt64
75+ # else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
76+ # define nghttp3_bswap64 (N ) \
77+ ((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
78+ # endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
7279# define nghttp3_ntohl64 (N ) nghttp3_bswap64(N)
7380# define nghttp3_htonl64 (N ) nghttp3_bswap64(N)
7481# endif /* !WORDS_BIGENDIAN */
@@ -106,17 +113,17 @@ STIN uint16_t htons(uint16_t hostshort) {
106113STIN uint32_t ntohl (uint32_t netlong ) {
107114 uint32_t res ;
108115 unsigned char * p = (unsigned char * )& netlong ;
109- res = * p ++ << 24 ;
110- res += * p ++ << 16 ;
111- res += * p ++ << 8 ;
116+ res = ( uint32_t )( * p ++ << 24 ) ;
117+ res += ( uint32_t )( * p ++ << 16 ) ;
118+ res += ( uint32_t )( * p ++ << 8 ) ;
112119 res += * p ;
113120 return res ;
114121}
115122
116123STIN uint16_t ntohs (uint16_t netshort ) {
117124 uint16_t res ;
118125 unsigned char * p = (unsigned char * )& netshort ;
119- res = * p ++ << 8 ;
126+ res = ( uint16_t )( * p ++ << 8 ) ;
120127 res += * p ;
121128 return res ;
122129}
@@ -137,10 +144,10 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p);
137144int64_t nghttp3_get_varint_fb (const uint8_t * p );
138145
139146/*
140- * nghttp3_get_varint_len returns the required number of bytes to read
147+ * nghttp3_get_varintlen returns the required number of bytes to read
141148 * variable-length integer starting at |p|.
142149 */
143- size_t nghttp3_get_varint_len (const uint8_t * p );
150+ size_t nghttp3_get_varintlen (const uint8_t * p );
144151
145152/*
146153 * nghttp3_put_uint64be writes |n| in host byte order in |p| in
@@ -149,27 +156,13 @@ size_t nghttp3_get_varint_len(const uint8_t *p);
149156 */
150157uint8_t * nghttp3_put_uint64be (uint8_t * p , uint64_t n );
151158
152- /*
153- * nghttp3_put_uint48be writes |n| in host byte order in |p| in
154- * network byte order. It writes only least significant 48 bits. It
155- * returns the one beyond of the last written position.
156- */
157- uint8_t * nghttp3_put_uint48be (uint8_t * p , uint64_t n );
158-
159159/*
160160 * nghttp3_put_uint32be writes |n| in host byte order in |p| in
161161 * network byte order. It returns the one beyond of the last written
162162 * position.
163163 */
164164uint8_t * nghttp3_put_uint32be (uint8_t * p , uint32_t n );
165165
166- /*
167- * nghttp3_put_uint24be writes |n| in host byte order in |p| in
168- * network byte order. It writes only least significant 24 bits. It
169- * returns the one beyond of the last written position.
170- */
171- uint8_t * nghttp3_put_uint24be (uint8_t * p , uint32_t n );
172-
173166/*
174167 * nghttp3_put_uint16be writes |n| in host byte order in |p| in
175168 * network byte order. It returns the one beyond of the last written
@@ -184,10 +177,10 @@ uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
184177uint8_t * nghttp3_put_varint (uint8_t * p , int64_t n );
185178
186179/*
187- * nghttp3_put_varint_len returns the required number of bytes to
180+ * nghttp3_put_varintlen returns the required number of bytes to
188181 * encode |n|.
189182 */
190- size_t nghttp3_put_varint_len (int64_t n );
183+ size_t nghttp3_put_varintlen (int64_t n );
191184
192185/*
193186 * nghttp3_ord_stream_id returns the ordinal number of |stream_id|.
@@ -200,22 +193,4 @@ uint64_t nghttp3_ord_stream_id(int64_t stream_id);
200193 */
201194#define NGHTTP3_PRI_INC_MASK (1 << 7)
202195
203- /*
204- * nghttp3_pri_to_uint8 encodes |pri| into uint8_t variable.
205- */
206- uint8_t nghttp3_pri_to_uint8 (const nghttp3_pri * pri );
207-
208- /*
209- * nghttp3_pri_uint8_urgency extracts urgency from |PRI| which is
210- * supposed to be constructed by nghttp3_pri_to_uint8.
211- */
212- #define nghttp3_pri_uint8_urgency (PRI ) \
213- ((uint32_t)((PRI) & ~NGHTTP3_PRI_INC_MASK))
214-
215- /*
216- * nghttp3_pri_uint8_inc extracts inc from |PRI| which is supposed to
217- * be constructed by nghttp3_pri_to_uint8.
218- */
219- #define nghttp3_pri_uint8_inc (PRI ) (((PRI)&NGHTTP3_PRI_INC_MASK) != 0)
220-
221196#endif /* NGHTTP3_CONV_H */
0 commit comments