1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 // #include <bit> // we don't have GCC with C++20 on raspi :(
13 template<typename t_tVal>
14 constexpr t_tVal swapBytes(t_tVal Val) {
16 for(size_t i = 0; i < sizeof(Val); ++i) {
17 Out = (Out << 8) | (Val & 0xFF);
23 template<typename t_tVal>
24 constexpr t_tVal littleToNative(const t_tVal &Val) {
25 // if(std::endian::native == std::endian::big) {
26 // return swapBytes(Val);
33 template<typename t_tVal>
34 constexpr auto nativeToLittle = littleToNative<t_tVal>;
36 template<typename t_tVal>
37 constexpr t_tVal bigToNative(const t_tVal &Val) {
38 // if(std::endian::native == std::endian::big) {
42 return swapBytes(Val);
46 template<typename t_tVal>
47 constexpr auto nativeToBig = bigToNative<t_tVal>;
50 } // namespace nEndian
52 #endif // _ENDIAN_HPP_