Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::ostream_snapshot_writer Class Reference

#include <snapshot.hpp>

Inheritance diagram for sysio::chain::ostream_snapshot_writer:
Collaboration diagram for sysio::chain::ostream_snapshot_writer:

Public Member Functions

 ostream_snapshot_writer (std::ostream &snapshot)
 
void write_start_section (const std::string &section_name) override
 
void write_row (const detail::abstract_snapshot_row_writer &row_writer) override
 
void write_end_section () override
 
void finalize ()
 
- Public Member Functions inherited from sysio::chain::snapshot_writer
template<typename F >
void write_section (const std::string section_name, F f)
 
template<typename T , typename F >
void write_section (F f)
 
virtual ~snapshot_writer ()
 

Static Public Attributes

static const uint32_t magic_number = 0x30510550
 

Additional Inherited Members

- Protected Member Functions inherited from sysio::chain::snapshot_writer

Detailed Description

Definition at line 329 of file snapshot.hpp.

Constructor & Destructor Documentation

◆ ostream_snapshot_writer()

sysio::chain::ostream_snapshot_writer::ostream_snapshot_writer ( std::ostream & snapshot)
explicit

Definition at line 122 of file snapshot.cpp.

123:snapshot(snapshot)
124,header_pos(snapshot.tellp())
125,section_pos(-1)
126,row_count(0)
127{
128 // write magic number
129 auto totem = magic_number;
130 snapshot.write((char*)&totem, sizeof(totem));
131
132 // write version
133 auto version = current_snapshot_version;
134 snapshot.write((char*)&version, sizeof(version));
135}
static const uint32_t magic_number
Definition snapshot.hpp:338

Member Function Documentation

◆ finalize()

void sysio::chain::ostream_snapshot_writer::finalize ( )

Definition at line 186 of file snapshot.cpp.

186 {
187 uint64_t end_marker = std::numeric_limits<uint64_t>::max();
188
189 // write a placeholder for the section size
190 snapshot.write((char*)&end_marker, sizeof(end_marker));
191}
unsigned __int64 uint64_t
Definition stdint.h:136

◆ write_end_section()

void sysio::chain::ostream_snapshot_writer::write_end_section ( )
overridevirtual

Implements sysio::chain::snapshot_writer.

Definition at line 167 of file snapshot.cpp.

167 {
168 auto restore = snapshot.tellp();
169
170 uint64_t section_size = restore - section_pos - sizeof(uint64_t);
171
172 snapshot.seekp(section_pos);
173
174 // write a the section size
175 snapshot.write((char*)&section_size, sizeof(section_size));
176
177 // write the row count
178 snapshot.write((char*)&row_count, sizeof(row_count));
179
180 snapshot.seekp(restore);
181
182 section_pos = std::streampos(-1);
183 row_count = 0;
184}

◆ write_row()

void sysio::chain::ostream_snapshot_writer::write_row ( const detail::abstract_snapshot_row_writer & row_writer)
overridevirtual

Implements sysio::chain::snapshot_writer.

Definition at line 156 of file snapshot.cpp.

156 {
157 auto restore = snapshot.tellp();
158 try {
159 row_writer.write(snapshot);
160 } catch (...) {
161 snapshot.seekp(restore);
162 throw;
163 }
164 row_count++;
165}
Here is the call graph for this function:

◆ write_start_section()

void sysio::chain::ostream_snapshot_writer::write_start_section ( const std::string & section_name)
overridevirtual

Implements sysio::chain::snapshot_writer.

Definition at line 137 of file snapshot.cpp.

138{
139 SYS_ASSERT(section_pos == std::streampos(-1), snapshot_exception, "Attempting to write a new section without closing the previous section");
140 section_pos = snapshot.tellp();
141 row_count = 0;
142
143 uint64_t placeholder = std::numeric_limits<uint64_t>::max();
144
145 // write a placeholder for the section size
146 snapshot.write((char*)&placeholder, sizeof(placeholder));
147
148 // write placeholder for row count
149 snapshot.write((char*)&placeholder, sizeof(placeholder));
150
151 // write the section name (null terminated)
152 snapshot.write(section_name.data(), section_name.size());
153 snapshot.put(0);
154}
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7

Member Data Documentation

◆ magic_number

const uint32_t sysio::chain::ostream_snapshot_writer::magic_number = 0x30510550
static

Definition at line 338 of file snapshot.hpp.


The documentation for this class was generated from the following files: