0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd::util: Add hton()/ntoh() in-place swap overloads.

This commit is contained in:
Jason Volk 2019-04-06 17:07:11 -07:00
parent d1966fffb5
commit 29775f0866

View file

@ -17,6 +17,8 @@ namespace ircd::util
template<class T> T bswap(T);
// Host <-> network endian
template<class T> T &hton(T *const &);
template<class T> T &ntoh(T *const &);
template<class T> T hton(T);
template<class T> T ntoh(T);
@ -85,21 +87,37 @@ template<class T>
T
ircd::util::hton(T a)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return bswap(&a);
#else
return a;
#endif
return hton<T>(&a);
}
template<class T>
T
ircd::util::ntoh(T a)
{
return ntoh<T>(&a);
}
template<class T>
T &
ircd::util::hton(T *const &a)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return bswap(&a);
return bswap(a);
#else
return a;
assert(a);
return *a;
#endif
}
template<class T>
T &
ircd::util::ntoh(T *const &a)
{
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
return bswap(a);
#else
assert(a);
return *a;
#endif
}