Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
serialization.hpp
Go to the documentation of this file.
1
12#ifndef SERIALIZATION_HPP_
13#define SERIALIZATION_HPP_
14
15#include <istream>
16#include <map>
17#include <ostream>
18#include <set>
19#include <vector>
20
21namespace libff {
22
23/*
24 * @todo
25 * The serialization is fragile. Shoud be rewritten using a standard, portable-format
26 * library like boost::serialize.
27 *
28 * However, for now the following conventions are used within the code.
29 *
30 * All algebraic objects support either binary or decimal output using
31 * the standard C++ stream operators (operator<<, operator>>).
32 *
33 * The binary mode is activated by defining a BINARY_OUTPUT
34 * preprocessor macro (e.g. g++ -DBINARY_OUTPUT ...).
35 *
36 * Binary output assumes that the stream is to be binary read at its
37 * current position so any white space should be consumed beforehand.
38 *
39 * Consecutive algebraic objects are separated by OUTPUT_NEWLINE and
40 * within themselves (e.g. X and Y coordinates for field elements) with
41 * OUTPUT_SEPARATOR (as defined below).
42 *
43 * Therefore to dump two integers, two Fp elements and another integer
44 * one would:
45 *
46 * out << 3 << "\n";
47 * out << 4 << "\n";
48 * out << FieldT(56) << OUTPUT_NEWLINE;
49 * out << FieldT(78) << OUTPUT_NEWLINE;
50 * out << 9 << "\n";
51 *
52 * Then reading back it its reader's responsibility (!) to consume "\n"
53 * after 4, but Fp::operator<< will correctly consume OUTPUT_NEWLINE.
54 *
55 * The reader should also consume "\n" after 9, so that another field
56 * element can be properly chained. This is especially important for
57 * binary output.
58 *
59 * The binary serialization of algebraic objects is currently *not*
60 * portable between machines of different word sizes.
61 */
62
63#ifdef BINARY_OUTPUT
64#define OUTPUT_NEWLINE ""
65#define OUTPUT_SEPARATOR ""
66#else
67#define OUTPUT_NEWLINE "\n"
68#define OUTPUT_SEPARATOR " "
69#endif
70
71inline void consume_newline(std::istream &in);
72inline void consume_OUTPUT_NEWLINE(std::istream &in);
73inline void consume_OUTPUT_SEPARATOR(std::istream &in);
74
75inline void output_bool(std::ostream &out, const bool b);
76inline void input_bool(std::istream &in, bool &b);
77
78inline void output_bool_vector(std::ostream &out, const std::vector<bool> &v);
79inline void input_bool_vector(std::istream &in, std::vector<bool> &v);
80
81template<typename T>
82T reserialize(const T &obj);
83
84template<typename T>
85std::ostream& operator<<(std::ostream& out, const std::vector<T> &v);
86
87template<typename T>
88std::istream& operator>>(std::ostream& out, std::vector<T> &v);
89
90template<typename T1, typename T2>
91std::ostream& operator<<(std::ostream& out, const std::map<T1, T2> &m);
92
93template<typename T1, typename T2>
94std::istream& operator>>(std::istream& in, std::map<T1, T2> &m);
95
96template<typename T>
97std::ostream& operator<<(std::ostream& out, const std::set<T> &s);
98
99template<typename T>
100std::istream& operator>>(std::istream& in, std::set<T> &s);
101
102} // libff
103
104#include <libff/common/serialization.tcc>
105
106#endif // SERIALIZATION_HPP_
void output_bool(std::ostream &out, const bool b)
T reserialize(const T &obj)
void consume_OUTPUT_NEWLINE(std::istream &in)
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
void consume_OUTPUT_SEPARATOR(std::istream &in)
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
void input_bool(std::istream &in, bool &b)
void input_bool_vector(std::istream &in, std::vector< bool > &v)
void consume_newline(std::istream &in)
void output_bool_vector(std::ostream &out, const std::vector< bool > &v)
#define T(meth, val, expected)
char * s