-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix byte order issue (big endian/little endian)
- Loading branch information
Showing
6 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace uvio::net { | ||
|
||
#if __BYTE_ORDER == __LITTLE_ENDIAN | ||
static inline auto htonll(uint64_t x) -> uint64_t { | ||
return __bswap_64(x); | ||
} | ||
static inline auto ntohll(uint64_t x) -> uint64_t { | ||
return __bswap_64(x); | ||
} | ||
static inline auto htonl(uint32_t x) -> uint32_t { | ||
return __bswap_32(x); | ||
} | ||
static inline auto ntohl(uint32_t x) -> uint32_t { | ||
return __bswap_32(x); | ||
} | ||
static inline auto htons(uint16_t x) -> uint16_t { | ||
return __bswap_16(x); | ||
} | ||
static inline auto ntohs(uint16_t x) -> uint16_t { | ||
return __bswap_16(x); | ||
} | ||
#elif __BYTE_ORDER == __BIG_ENDIAN | ||
static inline auto htonll(uint64_t x) -> uint64_t { | ||
return x; | ||
} | ||
static inline auto ntohll(uint64_t x) -> uint64_t { | ||
return x; | ||
} | ||
static inline auto htonl(uint32_t x) -> uint32_t { | ||
return x; | ||
} | ||
static inline auto ntohl(uint32_t x) -> uint32_t { | ||
return x; | ||
} | ||
static inline auto htons(uint16_t x) -> uint16_t { | ||
return x; | ||
} | ||
static inline auto ntohs(uint16_t x) -> uint16_t { | ||
return x; | ||
} | ||
#else | ||
#error "__BYTE_ORDER not defined!" | ||
#endif | ||
|
||
} // namespace uvio::net |