From 7e69e272b813f0acb171740368655ee42de598de Mon Sep 17 00:00:00 2001 From: "Zezheng.Li" Date: Thu, 12 Oct 2023 10:42:09 +0800 Subject: [PATCH] fix --- include/ylt/struct_pack/endian_wrapper.hpp | 4 ++-- include/ylt/struct_pack/reflection.hpp | 7 +++++-- src/struct_pack/tests/test_cross_platform.cpp | 5 +++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/ylt/struct_pack/endian_wrapper.hpp b/include/ylt/struct_pack/endian_wrapper.hpp index 450881263..b1867657e 100644 --- a/include/ylt/struct_pack/endian_wrapper.hpp +++ b/include/ylt/struct_pack/endian_wrapper.hpp @@ -40,7 +40,7 @@ void write_wrapper(writer_t& writer, const char* data) { auto tmp = _byteswap_ulong(*data); writer.write(&tmp, block_size); #elif defined(__clang__) || defined(__GNUC__) - auto tmp = __builtin_bswap16(*data); + auto tmp = __builtin_bswap32(*data); writer.write(&tmp, block_size); #else writer.write(data + 3, 1); @@ -54,7 +54,7 @@ void write_wrapper(writer_t& writer, const char* data) { auto tmp = _byteswap_uint64(*data); writer.write(&tmp, block_size); #elif defined(__clang__) || defined(__GNUC__) - auto tmp = __builtin_bswap16(*data); + auto tmp = __builtin_bswap64(*data); writer.write(&tmp, block_size); #else writer.write(data + 7, 1); diff --git a/include/ylt/struct_pack/reflection.hpp b/include/ylt/struct_pack/reflection.hpp index 9847fa889..3c029645b 100644 --- a/include/ylt/struct_pack/reflection.hpp +++ b/include/ylt/struct_pack/reflection.hpp @@ -39,8 +39,11 @@ namespace struct_pack { namespace detail { -constexpr inline bool is_system_little_endian = - static_cast(1) == 1; +constexpr inline bool is_system_little_endian_impl(int value = 0x01) { + return static_cast(value) == 1; +} + +constexpr inline bool is_system_little_endian = is_system_little_endian_impl(); template using get_args_type = remove_cvref_t #include +#include #include #include "doctest.h" #include "test_struct.hpp" +#include "ylt/struct_pack/reflection.hpp" using namespace struct_pack; using namespace doctest; @@ -21,6 +23,9 @@ void data_gen() { } TEST_CASE("testing deserialize other platform data") { + std::cout << "Now endian:" + << (struct_pack::detail::is_system_little_endian ? "little" : "big") + << std::endl; std::ifstream ifs("binary_data/test_cross_platform.dat"); if (!ifs.is_open()) { ifs.open("src/struct_pack/tests/binary_data/test_cross_platform.dat");