5#ifndef FLUTTER_FML_ENDIANNESS_H_
6#define FLUTTER_FML_ENDIANNESS_H_
14#include "flutter/fml/build_config.h"
18#define FML_BYTESWAP_16(n) _byteswap_ushort(n)
19#define FML_BYTESWAP_32(n) _byteswap_ulong(n)
20#define FML_BYTESWAP_64(n) _byteswap_uint64(n)
22#define FML_BYTESWAP_16(n) __builtin_bswap16(n)
23#define FML_BYTESWAP_32(n) __builtin_bswap32(n)
24#define FML_BYTESWAP_64(n) __builtin_bswap64(n)
32 integral_constant<bool, std::is_integral_v<T> || std::is_enum_v<T>> {
39template <
typename T,
class = std::enable_if_t<kIsByteSwappableV<T>>>
41 if constexpr (
sizeof(
T) == 1) {
43 }
else if constexpr (
sizeof(
T) == 2) {
45 }
else if constexpr (
sizeof(
T) == 4) {
47 }
else if constexpr (
sizeof(
T) == 8) {
50 static_assert(!
sizeof(
T),
"Unsupported size");
58template <
typename T,
class = std::enable_if_t<kIsByteSwappableV<T>>>
60#if FML_ARCH_CPU_LITTLE_ENDIAN
61 return ByteSwap<T>(n);
70template <
typename T,
class = std::enable_if_t<kIsByteSwappableV<T>>>
72#if !FML_ARCH_CPU_LITTLE_ENDIAN
73 return ByteSwap<T>(n);
#define FML_BYTESWAP_64(n)
#define FML_BYTESWAP_16(n)
#define FML_BYTESWAP_32(n)
constexpr bool kIsByteSwappableV
constexpr T BigEndianToArch(T n)
Convert a known big endian value to match the endianness of the current architecture....
constexpr T ByteSwap(T n)
Flips the endianness of the given value. The given value must be an integral type of size 1,...
constexpr T LittleEndianToArch(T n)
Convert a known little endian value to match the endianness of the current architecture....