Skip to content

Commit 4fbd072

Browse files
committed
added the lost files
1 parent b339d3e commit 4fbd072

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

yas/record.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
#include "yas/record.hpp"
3+
4+
namespace yas_test {
5+
6+
void
7+
to_string(const Record &record, std::string &data)
8+
{
9+
yas::mem_ostream os;
10+
yas::binary_oarchive<yas::mem_ostream, flags> oa(os);
11+
oa & record;
12+
13+
auto buf = os.get_intrusive_buffer();
14+
data.assign(buf.data, buf.size);
15+
}
16+
17+
void
18+
from_string(Record &record, const std::string &data)
19+
{
20+
yas::mem_istream is(data.c_str(), data.size());
21+
yas::binary_iarchive<yas::mem_istream, flags> ia(is);
22+
ia & record;
23+
}
24+
25+
} // namespace

yas/record.hpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
#ifndef __YAS_RECORD_HPP_INCLUDED__
3+
#define __YAS_RECORD_HPP_INCLUDED__
4+
5+
#include <vector>
6+
#include <string>
7+
8+
#include <stdint.h>
9+
10+
#include <yas/mem_streams.hpp>
11+
#include <yas/binary_iarchive.hpp>
12+
#include <yas/binary_oarchive.hpp>
13+
#include <yas/std_types.hpp>
14+
15+
namespace yas_test {
16+
17+
enum { flags = yas::binary|yas::no_header|yas::seq_size_32 };
18+
19+
typedef std::vector<int64_t> Integers;
20+
typedef std::vector<std::string> Strings;
21+
22+
struct Record {
23+
24+
Integers ids;
25+
Strings strings;
26+
27+
bool operator==(const Record &other) {
28+
return (ids == other.ids && strings == other.strings);
29+
}
30+
31+
bool operator!=(const Record &other) {
32+
return !(*this == other);
33+
}
34+
35+
template<typename Archive>
36+
void serialize(Archive &ar)
37+
{
38+
ar & ids & strings;
39+
}
40+
};
41+
42+
void to_string(const Record &record, std::string &data);
43+
void from_string(Record &record, const std::string &data);
44+
45+
} // namespace
46+
47+
#endif

0 commit comments

Comments
 (0)