bux API Reference
1.12.6
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Serialize.cpp
Go to the documentation of this file.
1
#include "
Serialize.h
"
2
#include <functional>
// std::hash<>
3
#include <iterator>
// std::istreambuf_iterator
4
#include <istream>
// std::istream
5
#include <ostream>
// std::ostream
6
7
namespace
bux
{
8
9
//
10
// Implement Functions
11
//
12
size_t
read_size
(
const
std::string &src,
size_t
&off)
noexcept
13
{
14
size_t
n;
15
read
(src, off, n);
16
return
n;
17
}
18
19
std::tuple<std::string,size_t,bool>
load_hashed_str
(std::istream &in)
20
{
21
size_t
last_hash;
22
in.read(
reinterpret_cast<
char
*
>
(&last_hash),
sizeof
last_hash);
23
const
std::string src{std::istreambuf_iterator<char>{in}, {}};
24
return
{src, last_hash, std::hash<std::string>{}(src) == last_hash};
25
}
26
27
size_t
save_hashed_str
(std::ostream &out,
const
std::string &s)
28
{
29
size_t
n = std::hash<std::string>{}(s);
30
out.write(
reinterpret_cast<
char
*
>
(&n),
sizeof
n) <<s;
31
return
n;
32
}
33
34
}
// namespace bux
Serialize.h
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
bux::load_hashed_str
std::tuple< std::string, size_t, bool > load_hashed_str(std::istream &in)
Definition
Serialize.cpp:19
bux::read
void read(const std::string &src, size_t &off, T &data) noexcept
Definition
Serialize.h:35
bux::read_size
size_t read_size(const std::string &src, size_t &off) noexcept
Definition
Serialize.cpp:12
bux::save_hashed_str
size_t save_hashed_str(std::ostream &out, const std::string &s)
Definition
Serialize.cpp:27
Generated by
1.18.0