Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
snapshot_suites.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <snapshots.hpp>
5
6using namespace sysio::chain;
7using namespace sysio::testing;
8
14
15 struct writer : public writer_t {
16 writer( const std::shared_ptr<write_storage_t>& storage )
19 {
20
21 }
22
23 std::shared_ptr<write_storage_t> storage;
24 };
25
26 struct reader : public reader_t {
27 explicit reader(const snapshot_t& storage)
28 :reader_t(storage)
29 {}
30 };
31
32
33 static auto get_writer() {
34 return std::make_shared<writer>(std::make_shared<write_storage_t>());
35 }
36
37 static auto finalize(const std::shared_ptr<writer>& w) {
38 w->finalize();
39 return snapshot_t(*w->storage);
40 }
41
42 static auto get_reader( const snapshot_t& buffer) {
43 return std::make_shared<reader>(buffer);
44 }
45
46 static snapshot_t load_from_file(const std::string& filename) {
47 snapshot_input_file<snapshot::json> file(filename);
48 return file.read();
49 }
50
51 static void write_to_file( const std::string& basename, const snapshot_t& snapshot ) {
52 snapshot_output_file<snapshot::json> file(basename);
53 file.write<snapshot_t>(snapshot);
54 }
55};
56
60 using write_storage_t = std::ostringstream;
61 using snapshot_t = std::string;
62 using read_storage_t = std::istringstream;
63
64 struct writer : public writer_t {
65 writer( const std::shared_ptr<write_storage_t>& storage )
68 {
69
70 }
71
72 std::shared_ptr<write_storage_t> storage;
73 };
74
75 struct reader : public reader_t {
76 explicit reader(const std::shared_ptr<read_storage_t>& storage)
79 {}
80
81 std::shared_ptr<read_storage_t> storage;
82 };
83
84
85 static auto get_writer() {
86 return std::make_shared<writer>(std::make_shared<write_storage_t>());
87 }
88
89 static auto finalize(const std::shared_ptr<writer>& w) {
90 w->finalize();
91 return w->storage->str();
92 }
93
94 static auto get_reader( const snapshot_t& buffer) {
95 return std::make_shared<reader>(std::make_shared<read_storage_t>(buffer));
96 }
97
98 static snapshot_t load_from_file(const std::string& filename) {
99 snapshot_input_file<snapshot::binary> file(filename);
100 return file.read_as_string();
101 }
102
103 static void write_to_file( const std::string& basename, const snapshot_t& snapshot ) {
104 snapshot_output_file<snapshot::binary> file(basename);
105 file.write<snapshot_t>(snapshot);
106 }
107};
108
109using snapshot_suites = boost::mpl::list<variant_snapshot_suite, buffered_snapshot_suite>;
110
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
boost::mpl::list< variant_snapshot_suite, buffered_snapshot_suite > snapshot_suites
std::shared_ptr< read_storage_t > storage
reader(const std::shared_ptr< read_storage_t > &storage)
std::shared_ptr< write_storage_t > storage
writer(const std::shared_ptr< write_storage_t > &storage)
std::istringstream read_storage_t
static void write_to_file(const std::string &basename, const snapshot_t &snapshot)
static auto get_reader(const snapshot_t &buffer)
std::ostringstream write_storage_t
static snapshot_t load_from_file(const std::string &filename)
static auto finalize(const std::shared_ptr< writer > &w)
reader(const snapshot_t &storage)
writer(const std::shared_ptr< write_storage_t > &storage)
std::shared_ptr< write_storage_t > storage
static void write_to_file(const std::string &basename, const snapshot_t &snapshot)
static snapshot_t load_from_file(const std::string &filename)
static auto get_reader(const snapshot_t &buffer)
static auto finalize(const std::shared_ptr< writer > &w)