3 #ifndef UVCC_ENDIAN__HPP 4 #define UVCC_ENDIAN__HPP 26 # define HOST_to_NET_16(x) ( ::htons((uint16_t)(x)) ) 27 # define HOST_to_NET_32(x) ( ::htonl((uint32_t)(x)) ) 28 # define NET_to_HOST_16(x) ( ::ntohs((uint16_t)(x)) ) 29 # define NET_to_HOST_32(x) ( ::ntohl((uint32_t)(x)) ) 30 # ifndef __BYTE_ORDER__ 31 # error __BYTE_ORDER__ macro not defined 33 # if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 34 # define HOST_to_NET_64(x) ( (uint64_t)::htonl((uint32_t)((uint64_t)(x) >> 32
)) | ((uint64_t)::htonl((uint32_t)(x)) << 32
) ) 35 # define NET_to_HOST_64(x) ( (uint64_t)::ntohl((uint32_t)((uint64_t)(x) >> 32
)) | ((uint64_t)::ntohl((uint32_t)(x)) << 32
) ) 36 # elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) 37 # define HOST_to_NET_64(x) ( (uint64_t)(x) ) 38 # define NET_to_HOST_64(x) ( (uint64_t)(x) ) 40 # error __BYTE_ORDER__ value not supported 43 # define HOST_to_NET_16(x) ( htobe16
((uint16_t)(x)) ) 44 # define HOST_to_NET_32(x) ( htobe32
((uint32_t)(x)) ) 45 # define HOST_to_NET_64(x) ( htobe64
((uint64_t)(x)) ) 46 # define NET_to_HOST_16(x) ( be16toh
((uint16_t)(x)) ) 47 # define NET_to_HOST_32(x) ( be32toh
((uint32_t)(x)) ) 48 # define NET_to_HOST_64(x) ( be64toh
((uint64_t)(x)) ) 53 template<
typename _I_ >
inline uint16_t
hton16(
const _I_ &_i) {
return HOST_to_NET_16(_i); }
54 template<
typename _I_ >
inline uint32_t
hton32(
const _I_ &_i) {
return HOST_to_NET_32(_i); }
55 template<
typename _I_ >
inline uint64_t
hton64(
const _I_ &_i) {
return HOST_to_NET_64(_i); }
57 template<
typename _I_ >
inline uint16_t
ntoh16(
const _I_ &_i) {
return NET_to_HOST_16(_i); }
58 template<
typename _I_ >
inline uint32_t
ntoh32(
const _I_ &_i) {
return NET_to_HOST_32(_i); }
59 template<
typename _I_ >
inline uint64_t
ntoh64(
const _I_ &_i) {
return NET_to_HOST_64(_i); }
Namespace for all uvcc definitions.
uint64_t hton64(const _I_ &_i)
Cross-platform htonll()
uint16_t ntoh16(const _I_ &_i)
Cross-platform ntohs()
uint64_t ntoh64(const _I_ &_i)
Cross-platform ntohll()
uint16_t hton16(const _I_ &_i)
Cross-platform htons()
uint32_t ntoh32(const _I_ &_i)
Cross-platform ntohl()
uint32_t hton32(const _I_ &_i)
Cross-platform htonl()