mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
simpler endian detection for older gcc versions
This commit is contained in:
@ -24,6 +24,20 @@ namespace nlohmann
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief determine system byte order
|
||||||
|
|
||||||
|
@return true if and only if system's byte order is little endian
|
||||||
|
|
||||||
|
@note from https://stackoverflow.com/a/1001328/266378
|
||||||
|
*/
|
||||||
|
static bool little_endianess(int num = 1) noexcept
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<char*>(&num) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// binary reader //
|
// binary reader //
|
||||||
///////////////////
|
///////////////////
|
||||||
@ -117,18 +131,6 @@ class binary_reader
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief determine system byte order
|
|
||||||
|
|
||||||
@return true if and only if system's byte order is little endian
|
|
||||||
|
|
||||||
@note from https://stackoverflow.com/a/1001328/266378
|
|
||||||
*/
|
|
||||||
static constexpr bool little_endianess(int num = 1) noexcept
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<char*>(&num) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//////////
|
//////////
|
||||||
// BSON //
|
// BSON //
|
||||||
|
@ -1326,7 +1326,7 @@ class binary_writer
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// whether we can assume little endianess
|
/// whether we can assume little endianess
|
||||||
const bool is_little_endian = binary_reader<BasicJsonType, input_buffer_adapter>::little_endianess();
|
const bool is_little_endian = little_endianess();
|
||||||
|
|
||||||
/// the output
|
/// the output
|
||||||
output_adapter_t<CharType> oa = nullptr;
|
output_adapter_t<CharType> oa = nullptr;
|
||||||
|
@ -5214,6 +5214,20 @@ namespace nlohmann
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief determine system byte order
|
||||||
|
|
||||||
|
@return true if and only if system's byte order is little endian
|
||||||
|
|
||||||
|
@note from https://stackoverflow.com/a/1001328/266378
|
||||||
|
*/
|
||||||
|
static bool little_endianess(int num = 1) noexcept
|
||||||
|
{
|
||||||
|
return *reinterpret_cast<char*>(&num) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
// binary reader //
|
// binary reader //
|
||||||
///////////////////
|
///////////////////
|
||||||
@ -5307,18 +5321,6 @@ class binary_reader
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@brief determine system byte order
|
|
||||||
|
|
||||||
@return true if and only if system's byte order is little endian
|
|
||||||
|
|
||||||
@note from https://stackoverflow.com/a/1001328/266378
|
|
||||||
*/
|
|
||||||
static constexpr bool little_endianess(int num = 1) noexcept
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<char*>(&num) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//////////
|
//////////
|
||||||
// BSON //
|
// BSON //
|
||||||
@ -12674,7 +12676,7 @@ class binary_writer
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// whether we can assume little endianess
|
/// whether we can assume little endianess
|
||||||
const bool is_little_endian = binary_reader<BasicJsonType, input_buffer_adapter>::little_endianess();
|
const bool is_little_endian = little_endianess();
|
||||||
|
|
||||||
/// the output
|
/// the output
|
||||||
output_adapter_t<CharType> oa = nullptr;
|
output_adapter_t<CharType> oa = nullptr;
|
||||||
|
Reference in New Issue
Block a user