-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite3_map_ser.h
30 lines (26 loc) · 1.02 KB
/
sqlite3_map_ser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) 2015-2016 The Pebblecoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
namespace sqlite3 {
/// strings go through as-is
std::string store_string(const std::string& s) { return s; }
std::string load_string(const std::string& s) { return s; }
/// simple pod serialization
template<typename T>
typename std::enable_if<std::is_pod<T>::value, std::string>::type
store_pod(const T& t) {
std::string buff;
buff.assign(reinterpret_cast<const char*>(&t), sizeof(T));
return buff;
}
template<typename T>
typename std::enable_if<std::is_pod<T>::value, T>::type
load_pod(const std::string& buff) {
if (buff.size() != sizeof(T)) {
throw std::runtime_error("Invalid-sized string " + std::to_string(buff.size()) +
" in database for POD of size " + std::to_string(sizeof(T)));
}
return *reinterpret_cast<const T*>(buff.data());
}
}