From: Fred Morcos Date: Wed, 16 Oct 2024 13:15:11 +0000 (+0200) Subject: Specialize MDBOutVal::get/getNoStripHeader for uint32_t X-Git-Tag: rec-5.2.0-alpha1~26^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1b0e658fcb743057d1d01388f613fe2cedcc4c3a;p=thirdparty%2Fpdns.git Specialize MDBOutVal::get/getNoStripHeader for uint32_t --- diff --git a/ext/lmdb-safe/lmdb-safe.hh b/ext/lmdb-safe/lmdb-safe.hh index 1c62d88029..1cb7aa41e8 100644 --- a/ext/lmdb-safe/lmdb-safe.hh +++ b/ext/lmdb-safe/lmdb-safe.hh @@ -174,54 +174,50 @@ struct MDBOutVal } #ifndef DNSDIST - template ::value, - T>::type* = nullptr> const - T get() - { - T ret; - - size_t offset = LMDBLS::LScheckHeaderAndGetSize(this, sizeof(T)); - - memcpy(&ret, reinterpret_cast(d_mdbval.mv_data)+offset, sizeof(T)); - - static_assert(sizeof(T) == 4, "this code currently only supports 32 bit integers"); - ret = ntohl(ret); - return ret; - } - - template ::value, - T>::type* = nullptr> const - T getNoStripHeader() - { - T ret; - if(d_mdbval.mv_size != sizeof(T)) - throw std::runtime_error("MDB data has wrong length for type"); - - memcpy(&ret, d_mdbval.mv_data, sizeof(T)); - - static_assert(sizeof(T) == 4, "this code currently only supports 32 bit integers"); - ret = ntohl(ret); - return ret; - } + template ::value, T>::type* = nullptr> + T get() const; + template ::value, T>::type* = nullptr> + T getNoStripHeader() const; #endif /* ifndef DNSDIST */ - template ::value,T>::type* = nullptr> + template ::value, T>::type* = nullptr> T get() const; - #ifndef DNSDIST - template ::value,T>::type* = nullptr> + template ::value, T>::type* = nullptr> T getNoStripHeader() const; #endif MDB_val d_mdbval; }; +#ifndef DNSDIST +template <> +inline uint32_t MDBOutVal::get() const +{ + uint32_t ret = 0; + size_t offset = LMDBLS::LScheckHeaderAndGetSize(this, sizeof(uint32_t)); + // NOLINTNEXTLINE + memcpy(&ret, reinterpret_cast(d_mdbval.mv_data) + offset, sizeof(uint32_t)); + ret = ntohl(ret); + return ret; +} + +template <> +inline uint32_t MDBOutVal::getNoStripHeader() const +{ + uint32_t ret = 0; + if (d_mdbval.mv_size != sizeof(uint32_t)) { + throw std::runtime_error("MDB data has wrong length for type"); + } + + memcpy(&ret, d_mdbval.mv_data, sizeof(uint32_t)); + ret = ntohl(ret); + return ret; +} +#endif /* ifndef DNSDIST */ + template<> inline std::string MDBOutVal::get() const { #ifndef DNSDIST