#ifndef DNSDIST
+struct MDBOutVal; // forward declaration because of how the functions below tie in with MDBOutVal
+
+namespace LMDBLS {
+ class __attribute__((__packed__)) LSheader {
+ private:
+ static auto bswap64(uint64_t value) -> uint64_t
+ {
#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__)
-#error "your compiler did not define byte order macros"
+#error "your compiler does not define byte order macros"
#endif
-// FIXME do something more portable than __builtin_bswap64
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-#define _LMDB_SAFE_BSWAP64MAYBE(x) __builtin_bswap64(x)
+ // FIXME: Do something more portable than __builtin_bswap64.
+ return __builtin_bswap64(value);
#else
-#define _LMDB_SAFE_BSWAP64MAYBE(x) (x)
+ return value;
#endif
+ }
-struct MDBOutVal; // forward declaration because of how the functions below tie in with MDBOutVal
-
-namespace LMDBLS {
- class __attribute__((__packed__)) LSheader {
public:
uint64_t d_timestamp;
uint64_t d_txnid;
uint8_t d_version;
uint8_t d_flags;
- uint32_t d_reserved;
+ uint32_t d_reserved{};
uint16_t d_numextra;
- LSheader(uint64_t timestamp, uint64_t txnid, uint8_t flags=0, uint8_t version=0, uint8_t numextra=0):
- d_timestamp(_LMDB_SAFE_BSWAP64MAYBE(timestamp)),
- d_txnid(_LMDB_SAFE_BSWAP64MAYBE(txnid)),
+ // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
+ LSheader(uint64_t timestamp, uint64_t txnid, uint8_t flags = 0, uint8_t version = 0, uint8_t numextra = 0) :
+ d_timestamp(bswap64(timestamp)),
+ d_txnid(bswap64(txnid)),
d_version(version),
d_flags(flags),
- d_reserved(0),
d_numextra(htons(numextra))
{
-
}
std::string toString() {
return std::string((char*)this, sizeof(*this)) + std::string(ntohs(d_numextra)*8, '\0');
}
- uint64_t getTimestamp() const {
- return _LMDB_SAFE_BSWAP64MAYBE(d_timestamp);
+ [[nodiscard]] uint64_t getTimestamp() const {
+ return bswap64(d_timestamp);
}
};
extern bool s_flag_deleted;
}
-#undef _LMDB_SAFE_BSWAP64MAYBE
-
#endif /* ifndef DNSDIST */