50 lines
776 B
C++
50 lines
776 B
C++
#include <sp/common/ByteSwapping.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#else
|
|
|
|
#include <arpa/inet.h>
|
|
#include <endian.h>
|
|
|
|
#define htonll htobe64
|
|
#define ntohll be64toh
|
|
|
|
#endif
|
|
|
|
namespace sp {
|
|
|
|
template <>
|
|
void ToNetwork<std::uint16_t>(std::uint16_t& value) {
|
|
value = htons(value);
|
|
}
|
|
|
|
template <>
|
|
void ToNetwork<std::uint32_t>(std::uint32_t& value) {
|
|
value = htonl(value);
|
|
}
|
|
|
|
template <>
|
|
void ToNetwork<std::uint64_t>(std::uint64_t& value) {
|
|
value = htonll(value);
|
|
}
|
|
|
|
template <>
|
|
void FromNetwork<std::uint16_t>(std::uint16_t& value) {
|
|
value = ntohs(value);
|
|
}
|
|
|
|
template <>
|
|
void FromNetwork<std::uint32_t>(std::uint32_t& value) {
|
|
value = ntohl(value);
|
|
}
|
|
|
|
template <>
|
|
void FromNetwork<std::uint64_t>(std::uint64_t& value) {
|
|
value = ntohll(value);
|
|
}
|
|
|
|
} // namespace sp
|