#pragma once #include #include "utils/cast.hpp" namespace utils { inline uint16_t HostToLittleEndian(uint16_t value) { return htole16(value); } inline uint32_t HostToLittleEndian(uint32_t value) { return htole32(value); } inline uint64_t HostToLittleEndian(uint64_t value) { return htole64(value); } inline int16_t HostToLittleEndian(int16_t value) { return MemcpyCast(htole16(MemcpyCast(value))); } inline int32_t HostToLittleEndian(int32_t value) { return MemcpyCast(htole32(MemcpyCast(value))); } inline int64_t HostToLittleEndian(int64_t value) { return MemcpyCast(htole64(MemcpyCast(value))); } inline uint16_t LittleEndianToHost(uint16_t value) { return le16toh(value); } inline uint32_t LittleEndianToHost(uint32_t value) { return le32toh(value); } inline uint64_t LittleEndianToHost(uint64_t value) { return le64toh(value); } inline int16_t LittleEndianToHost(int16_t value) { return MemcpyCast(le16toh(MemcpyCast(value))); } inline int32_t LittleEndianToHost(int32_t value) { return MemcpyCast(le32toh(MemcpyCast(value))); } inline int64_t LittleEndianToHost(int64_t value) { return MemcpyCast(le64toh(MemcpyCast(value))); } inline uint16_t HostToBigEndian(uint16_t value) { return htobe16(value); } inline uint32_t HostToBigEndian(uint32_t value) { return htobe32(value); } inline uint64_t HostToBigEndian(uint64_t value) { return htobe64(value); } inline int16_t HostToBigEndian(int16_t value) { return MemcpyCast(htobe16(MemcpyCast(value))); } inline int32_t HostToBigEndian(int32_t value) { return MemcpyCast(htobe32(MemcpyCast(value))); } inline int64_t HostToBigEndian(int64_t value) { return MemcpyCast(htobe64(MemcpyCast(value))); } inline uint16_t BigEndianToHost(uint16_t value) { return be16toh(value); } inline uint32_t BigEndianToHost(uint32_t value) { return be32toh(value); } inline uint64_t BigEndianToHost(uint64_t value) { return be64toh(value); } inline int16_t BigEndianToHost(int16_t value) { return MemcpyCast(be16toh(MemcpyCast(value))); } inline int32_t BigEndianToHost(int32_t value) { return MemcpyCast(be32toh(MemcpyCast(value))); } inline int64_t BigEndianToHost(int64_t value) { return MemcpyCast(be64toh(MemcpyCast(value))); } } // namespace utils