mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
boost: fix little/big endian compatibility
When no little/big endian flag is given to the writer, it stores data in host endianness. When loading, if no flag is set, it also assumes host endianness. This works as long as the loading and writing are done on machines with the same endianness. We change this to default to little endian when saving. This will cause the loader to see the little endian flag, and swap endianness when loading on a big endian machine. Similarly, writing on a big endian machine will swap on save, and a little endian machine will load little endian data.
This commit is contained in:
parent
54fd97ae3f
commit
c1fa4a7f8c
2 changed files with 4 additions and 2 deletions
|
@ -258,7 +258,7 @@ portable_binary_iarchive::load_impl(boost::intmax_t & l, char maxsize){
|
||||||
this->primitive_base_t::load_binary(cptr, size);
|
this->primitive_base_t::load_binary(cptr, size);
|
||||||
|
|
||||||
#if BOOST_ENDIAN_BIG_BYTE
|
#if BOOST_ENDIAN_BIG_BYTE
|
||||||
if(m_flags & endian_little)
|
if((m_flags & endian_little) || (!(m_flags & endian_big)))
|
||||||
#else
|
#else
|
||||||
if(m_flags & endian_big)
|
if(m_flags & endian_big)
|
||||||
#endif
|
#endif
|
||||||
|
@ -343,6 +343,8 @@ portable_binary_iarchive::init(unsigned int flags){
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (!(m_flags & (endian_little | endian_big)))
|
||||||
|
m_flags |= endian_little;
|
||||||
unsigned char x;
|
unsigned char x;
|
||||||
load(x);
|
load(x);
|
||||||
m_flags = x << CHAR_BIT;
|
m_flags = x << CHAR_BIT;
|
||||||
|
|
|
@ -171,7 +171,7 @@ protected:
|
||||||
|
|
||||||
void init(unsigned int flags);
|
void init(unsigned int flags);
|
||||||
public:
|
public:
|
||||||
portable_binary_oarchive(std::ostream & os, unsigned flags = 0) :
|
portable_binary_oarchive(std::ostream & os, unsigned flags = endian_little) :
|
||||||
primitive_base_t(
|
primitive_base_t(
|
||||||
* os.rdbuf(),
|
* os.rdbuf(),
|
||||||
0 != (flags & boost::archive::no_codecvt)
|
0 != (flags & boost::archive::no_codecvt)
|
||||||
|
|
Loading…
Reference in a new issue