diff --git a/lmdb-typed.hh b/lmdb-typed.hh index 366a942..13fde0a 100644 --- a/lmdb-typed.hh +++ b/lmdb-typed.hh @@ -80,13 +80,24 @@ inline std::string keyConv(const std::string& t) template<> inline std::string keyConv(const uint32_t& t) { - return std::string((char*)&t, sizeof(4)); + return std::string((char*)&t, sizeof(t)); } template<> inline std::string keyConv(const int32_t& t) { - return std::string((char*)&t, sizeof(4)); + return std::string((char*)&t, sizeof(t)); } +template<> +inline std::string keyConv(const uint64_t& t) +{ + return std::string((char*)&t, sizeof(t)); +} +template<> +inline std::string keyConv(const int64_t& t) +{ + return std::string((char*)&t, sizeof(t)); +} + /** This is a struct that implements index operations, but diff --git a/typed-test.cc b/typed-test.cc index 49bbc13..3517500 100644 --- a/typed-test.cc +++ b/typed-test.cc @@ -1,5 +1,5 @@ #include - +#include #include "catch2/catch.hpp" #include "lmdb-typed.hh" @@ -9,21 +9,22 @@ struct Member { std::string firstName; std::string lastName; + time_t enrolled; }; template void serialize(Archive & ar, Member& g, const unsigned int version) { - ar & g.firstName & g.lastName; + ar & g.firstName & g.lastName & g.enrolled; } - - TEST_CASE("Basic typed tests", "[basictyped]") { unlink("./tests-typed"); typedef TypedDBI, - index_on > tmembers_t; + index_on, + index_on, + index_on + > tmembers_t; auto tmembers = tmembers_t(getMDBEnv("./tests-typed", MDB_CREATE | MDB_NOSUBDIR, 0600), "members"); @@ -34,6 +35,7 @@ TEST_CASE("Basic typed tests", "[basictyped]") { txn.put(m); m.firstName="bertus"; m.lastName = "testperson"; + m.enrolled = time(0); txn.put(m); m.firstName = "other";