mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:27:46 +00:00
AK: Use endianness flags to determine if conversion is necessary
This commit is contained in:
parent
940de40f28
commit
01ae3e9c85
2 changed files with 24 additions and 20 deletions
|
@ -26,21 +26,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Platform.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
template<typename T>
|
||||
[[gnu::always_inline]] inline T convert_between_host_and_network(T value)
|
||||
{
|
||||
if constexpr (sizeof(T) == 8)
|
||||
return __builtin_bswap64(value);
|
||||
if constexpr (sizeof(T) == 4)
|
||||
return __builtin_bswap32(value);
|
||||
if constexpr (sizeof(T) == 2)
|
||||
return __builtin_bswap16(value);
|
||||
if constexpr (sizeof(T) == 1)
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class [[gnu::packed]] NetworkOrdered
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue