aboutsummaryrefslogtreecommitdiff
path: root/src/serialize.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2024-02-27 18:39:22 +0000
committerCory Fields <cory-nospam-@coryfields.com>2024-02-28 13:42:38 +0000
commit86b7f28d6c507155a9d3a15487ee883989b88943 (patch)
treefe1bf5c7c64ba059ddc3c98729f7901dbe8b5b83 /src/serialize.h
parent432b18ca8d0654318a8d882b28b20af2cb2d2e5d (diff)
downloadbitcoin-86b7f28d6c507155a9d3a15487ee883989b88943.tar.xz
serialization: use internal endian conversion functions
These replace our platform-specific mess in favor of c++20 endian detection via std::endian and internal byteswap functions when necessary. They no longer rely on autoconf detection.
Diffstat (limited to 'src/serialize.h')
-rw-r--r--src/serialize.h28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/serialize.h b/src/serialize.h
index 7b336ce1af..5ae701191c 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -60,27 +60,27 @@ template<typename Stream> inline void ser_writedata8(Stream &s, uint8_t obj)
}
template<typename Stream> inline void ser_writedata16(Stream &s, uint16_t obj)
{
- obj = htole16(obj);
+ obj = htole16_internal(obj);
s.write(AsBytes(Span{&obj, 1}));
}
template<typename Stream> inline void ser_writedata16be(Stream &s, uint16_t obj)
{
- obj = htobe16(obj);
+ obj = htobe16_internal(obj);
s.write(AsBytes(Span{&obj, 1}));
}
template<typename Stream> inline void ser_writedata32(Stream &s, uint32_t obj)
{
- obj = htole32(obj);
+ obj = htole32_internal(obj);
s.write(AsBytes(Span{&obj, 1}));
}
template<typename Stream> inline void ser_writedata32be(Stream &s, uint32_t obj)
{
- obj = htobe32(obj);
+ obj = htobe32_internal(obj);
s.write(AsBytes(Span{&obj, 1}));
}
template<typename Stream> inline void ser_writedata64(Stream &s, uint64_t obj)
{
- obj = htole64(obj);
+ obj = htole64_internal(obj);
s.write(AsBytes(Span{&obj, 1}));
}
template<typename Stream> inline uint8_t ser_readdata8(Stream &s)
@@ -93,31 +93,31 @@ template<typename Stream> inline uint16_t ser_readdata16(Stream &s)
{
uint16_t obj;
s.read(AsWritableBytes(Span{&obj, 1}));
- return le16toh(obj);
+ return le16toh_internal(obj);
}
template<typename Stream> inline uint16_t ser_readdata16be(Stream &s)
{
uint16_t obj;
s.read(AsWritableBytes(Span{&obj, 1}));
- return be16toh(obj);
+ return be16toh_internal(obj);
}
template<typename Stream> inline uint32_t ser_readdata32(Stream &s)
{
uint32_t obj;
s.read(AsWritableBytes(Span{&obj, 1}));
- return le32toh(obj);
+ return le32toh_internal(obj);
}
template<typename Stream> inline uint32_t ser_readdata32be(Stream &s)
{
uint32_t obj;
s.read(AsWritableBytes(Span{&obj, 1}));
- return be32toh(obj);
+ return be32toh_internal(obj);
}
template<typename Stream> inline uint64_t ser_readdata64(Stream &s)
{
uint64_t obj;
s.read(AsWritableBytes(Span{&obj, 1}));
- return le64toh(obj);
+ return le64toh_internal(obj);
}
@@ -548,10 +548,10 @@ struct CustomUintFormatter
{
if (v < 0 || v > MAX) throw std::ios_base::failure("CustomUintFormatter value out of range");
if (BigEndian) {
- uint64_t raw = htobe64(v);
+ uint64_t raw = htobe64_internal(v);
s.write(AsBytes(Span{&raw, 1}).last(Bytes));
} else {
- uint64_t raw = htole64(v);
+ uint64_t raw = htole64_internal(v);
s.write(AsBytes(Span{&raw, 1}).first(Bytes));
}
}
@@ -563,10 +563,10 @@ struct CustomUintFormatter
uint64_t raw = 0;
if (BigEndian) {
s.read(AsWritableBytes(Span{&raw, 1}).last(Bytes));
- v = static_cast<I>(be64toh(raw));
+ v = static_cast<I>(be64toh_internal(raw));
} else {
s.read(AsWritableBytes(Span{&raw, 1}).first(Bytes));
- v = static_cast<I>(le64toh(raw));
+ v = static_cast<I>(le64toh_internal(raw));
}
}
};