refactor bitfield io

This commit is contained in:
2025-07-29 14:52:22 +02:00
parent 366a40afee
commit 01e406cd89
8 changed files with 182 additions and 141 deletions

View File

@@ -4,34 +4,13 @@
namespace sp {
/**
* \brief Serialize value to (network byte order) big endian
*/
template <typename T>
void ToNetwork(T& value) {}
bool IsLittleEndian();
template <>
void ToNetwork<std::uint16_t>(std::uint16_t& value);
void SwapBytes(std::uint8_t* begin, std::uint8_t* end);
template <>
void ToNetwork<std::uint32_t>(std::uint32_t& value);
template <>
void ToNetwork<std::uint64_t>(std::uint64_t& value);
/**
* \brief Deserialize value from (network byte order) big endian
*/
template <typename T>
void FromNetwork(T& value) {}
template <>
void FromNetwork<std::uint16_t>(std::uint16_t& value);
template <>
void FromNetwork<std::uint32_t>(std::uint32_t& value);
template <>
void FromNetwork<std::uint64_t>(std::uint64_t& value);
template<typename T>
void SwapBytes(T& a_Data) {
SwapBytes(reinterpret_cast<std::uint8_t*>(&a_Data), reinterpret_cast<std::uint8_t*>(&a_Data) + sizeof(T));
}
} // namespace sp