@eosrio/node-abieos 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/abieos.node +0 -0
- package/lib/abieos.d.ts +19 -0
- package/lib/abieos.d.ts.map +1 -0
- package/lib/abieos.js +100 -0
- package/lib/abieos.ts +107 -0
- package/package.json +13 -8
- package/.idea/modules.xml +0 -8
- package/.idea/node-abieos.iml +0 -12
- package/.idea/vcs.xml +0 -9
- package/.idea/workspace.xml +0 -66
- package/CMakeLists.txt +0 -35
- package/abieos.d.ts +0 -21
- package/abieos.js +0 -59
- package/eosio.json +0 -1596
- package/include/.clang-format +0 -76
- package/include/eosio/abi.hpp +0 -393
- package/include/eosio/asset.hpp +0 -458
- package/include/eosio/bytes.hpp +0 -27
- package/include/eosio/chain_conversions.hpp +0 -450
- package/include/eosio/chain_types.hpp +0 -14
- package/include/eosio/check.hpp +0 -178
- package/include/eosio/convert.hpp +0 -95
- package/include/eosio/crypto.hpp +0 -148
- package/include/eosio/eosio_outcome.hpp +0 -41
- package/include/eosio/fixed_bytes.hpp +0 -250
- package/include/eosio/float.hpp +0 -35
- package/include/eosio/for_each_field.hpp +0 -48
- package/include/eosio/fpconv.c +0 -336
- package/include/eosio/fpconv.h +0 -41
- package/include/eosio/fpconv.license +0 -23
- package/include/eosio/from_bin.hpp +0 -272
- package/include/eosio/from_json.hpp +0 -749
- package/include/eosio/from_string.hpp +0 -28
- package/include/eosio/map_macro.h +0 -64
- package/include/eosio/murmur.hpp +0 -55
- package/include/eosio/name.hpp +0 -178
- package/include/eosio/opaque.hpp +0 -184
- package/include/eosio/operators.hpp +0 -71
- package/include/eosio/powers.h +0 -76
- package/include/eosio/reflection.hpp +0 -61
- package/include/eosio/ship_protocol.hpp +0 -971
- package/include/eosio/stream.hpp +0 -235
- package/include/eosio/symbol.hpp +0 -300
- package/include/eosio/time.hpp +0 -264
- package/include/eosio/to_bin.hpp +0 -189
- package/include/eosio/to_json.hpp +0 -334
- package/include/eosio/to_key.hpp +0 -305
- package/include/eosio/types.hpp +0 -103
- package/include/eosio/varint.hpp +0 -452
- package/include/outcome-basic.hpp +0 -6836
- package/include/rapidjson/allocators.h +0 -284
- package/include/rapidjson/cursorstreamwrapper.h +0 -78
- package/include/rapidjson/document.h +0 -2646
- package/include/rapidjson/encodedstream.h +0 -299
- package/include/rapidjson/encodings.h +0 -716
- package/include/rapidjson/error/en.h +0 -74
- package/include/rapidjson/error/error.h +0 -161
- package/include/rapidjson/filereadstream.h +0 -99
- package/include/rapidjson/filewritestream.h +0 -104
- package/include/rapidjson/fwd.h +0 -151
- package/include/rapidjson/internal/biginteger.h +0 -290
- package/include/rapidjson/internal/diyfp.h +0 -271
- package/include/rapidjson/internal/dtoa.h +0 -245
- package/include/rapidjson/internal/ieee754.h +0 -78
- package/include/rapidjson/internal/itoa.h +0 -308
- package/include/rapidjson/internal/meta.h +0 -186
- package/include/rapidjson/internal/pow10.h +0 -55
- package/include/rapidjson/internal/regex.h +0 -732
- package/include/rapidjson/internal/stack.h +0 -231
- package/include/rapidjson/internal/strfunc.h +0 -69
- package/include/rapidjson/internal/strtod.h +0 -290
- package/include/rapidjson/internal/swap.h +0 -46
- package/include/rapidjson/istreamwrapper.h +0 -113
- package/include/rapidjson/memorybuffer.h +0 -70
- package/include/rapidjson/memorystream.h +0 -71
- package/include/rapidjson/msinttypes/inttypes.h +0 -316
- package/include/rapidjson/msinttypes/stdint.h +0 -300
- package/include/rapidjson/ostreamwrapper.h +0 -81
- package/include/rapidjson/pointer.h +0 -1357
- package/include/rapidjson/prettywriter.h +0 -277
- package/include/rapidjson/rapidjson.h +0 -654
- package/include/rapidjson/reader.h +0 -2230
- package/include/rapidjson/schema.h +0 -2494
- package/include/rapidjson/stream.h +0 -223
- package/include/rapidjson/stringbuffer.h +0 -121
- package/include/rapidjson/writer.h +0 -710
- package/src/abi.cpp +0 -274
- package/src/abieos.cpp +0 -334
- package/src/abieos.h +0 -91
- package/src/abieos.hpp +0 -1011
- package/src/abieos_exception.hpp +0 -89
- package/src/abieos_numeric.hpp +0 -94
- package/src/abieos_ripemd160.hpp +0 -417
- package/src/crypto.cpp +0 -215
- package/src/main.cpp +0 -242
- package/src/ship.abi.cpp +0 -695
- package/tools/CMakeLists.txt +0 -9
- package/tools/name.cpp +0 -86
package/include/eosio/time.hpp
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
#include "chain_conversions.hpp"
|
|
3
|
-
#include "check.hpp"
|
|
4
|
-
#include "operators.hpp"
|
|
5
|
-
#include "reflection.hpp"
|
|
6
|
-
#include "from_json.hpp"
|
|
7
|
-
#include <stdint.h>
|
|
8
|
-
#include <string>
|
|
9
|
-
|
|
10
|
-
namespace eosio {
|
|
11
|
-
/**
|
|
12
|
-
* @defgroup time
|
|
13
|
-
* @ingroup core
|
|
14
|
-
* @brief Classes for working with time.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
class microseconds {
|
|
18
|
-
public:
|
|
19
|
-
microseconds() = default;
|
|
20
|
-
|
|
21
|
-
explicit microseconds(int64_t c) : _count(c) {}
|
|
22
|
-
|
|
23
|
-
/// @cond INTERNAL
|
|
24
|
-
static microseconds maximum() { return microseconds(0x7fffffffffffffffll); }
|
|
25
|
-
friend microseconds operator+(const microseconds& l, const microseconds& r) {
|
|
26
|
-
return microseconds(l._count + r._count);
|
|
27
|
-
}
|
|
28
|
-
friend microseconds operator-(const microseconds& l, const microseconds& r) {
|
|
29
|
-
return microseconds(l._count - r._count);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
microseconds& operator+=(const microseconds& c) {
|
|
33
|
-
_count += c._count;
|
|
34
|
-
return *this;
|
|
35
|
-
}
|
|
36
|
-
microseconds& operator-=(const microseconds& c) {
|
|
37
|
-
_count -= c._count;
|
|
38
|
-
return *this;
|
|
39
|
-
}
|
|
40
|
-
int64_t count() const { return _count; }
|
|
41
|
-
int64_t to_seconds() const { return _count / 1000000; }
|
|
42
|
-
|
|
43
|
-
int64_t _count = 0;
|
|
44
|
-
/// @endcond
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
EOSIO_REFLECT(microseconds, _count);
|
|
48
|
-
EOSIO_COMPARE(microseconds);
|
|
49
|
-
|
|
50
|
-
inline microseconds seconds(int64_t s) { return microseconds(s * 1000000); }
|
|
51
|
-
inline microseconds milliseconds(int64_t s) { return microseconds(s * 1000); }
|
|
52
|
-
inline microseconds minutes(int64_t m) { return seconds(60 * m); }
|
|
53
|
-
inline microseconds hours(int64_t h) { return minutes(60 * h); }
|
|
54
|
-
inline microseconds days(int64_t d) { return hours(24 * d); }
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* High resolution time point in microseconds
|
|
58
|
-
*
|
|
59
|
-
* @ingroup time
|
|
60
|
-
*/
|
|
61
|
-
class time_point {
|
|
62
|
-
public:
|
|
63
|
-
time_point() = default;
|
|
64
|
-
explicit time_point(microseconds e) : elapsed(e) {}
|
|
65
|
-
const microseconds& time_since_epoch() const { return elapsed; }
|
|
66
|
-
uint32_t sec_since_epoch() const { return uint32_t(elapsed.count() / 1000000); }
|
|
67
|
-
|
|
68
|
-
static time_point max() { return time_point( microseconds::maximum() ); }
|
|
69
|
-
|
|
70
|
-
/// @cond INTERNAL
|
|
71
|
-
time_point& operator+=(const microseconds& m) {
|
|
72
|
-
elapsed += m;
|
|
73
|
-
return *this;
|
|
74
|
-
}
|
|
75
|
-
time_point& operator-=(const microseconds& m) {
|
|
76
|
-
elapsed -= m;
|
|
77
|
-
return *this;
|
|
78
|
-
}
|
|
79
|
-
time_point operator+(const microseconds& m) const { return time_point(elapsed + m); }
|
|
80
|
-
time_point operator+(const time_point& m) const { return time_point(elapsed + m.elapsed); }
|
|
81
|
-
time_point operator-(const microseconds& m) const { return time_point(elapsed - m); }
|
|
82
|
-
microseconds operator-(const time_point& m) const { return microseconds(elapsed.count() - m.elapsed.count()); }
|
|
83
|
-
microseconds elapsed;
|
|
84
|
-
/// @endcond
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
EOSIO_REFLECT(time_point, elapsed);
|
|
88
|
-
EOSIO_COMPARE(time_point);
|
|
89
|
-
|
|
90
|
-
template <typename S>
|
|
91
|
-
void from_json(time_point& obj, S& stream) {
|
|
92
|
-
auto s = stream.get_string();
|
|
93
|
-
uint64_t utc_microseconds;
|
|
94
|
-
if (!eosio::string_to_utc_microseconds(utc_microseconds, s.data(), s.data() + s.size())) {
|
|
95
|
-
check(false, convert_json_error(eosio::from_json_error::expected_time_point));
|
|
96
|
-
}
|
|
97
|
-
obj = time_point(microseconds(utc_microseconds));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
template <typename S>
|
|
101
|
-
void to_json(const time_point& obj, S& stream) {
|
|
102
|
-
return to_json(eosio::microseconds_to_str(obj.elapsed._count), stream);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* A lower resolution time_point accurate only to seconds from 1970
|
|
107
|
-
*
|
|
108
|
-
* @ingroup time
|
|
109
|
-
*/
|
|
110
|
-
class time_point_sec {
|
|
111
|
-
public:
|
|
112
|
-
time_point_sec() : utc_seconds(0) {}
|
|
113
|
-
|
|
114
|
-
explicit time_point_sec(uint32_t seconds) : utc_seconds(seconds) {}
|
|
115
|
-
|
|
116
|
-
time_point_sec(const time_point& t) : utc_seconds(uint32_t(t.time_since_epoch().count() / 1000000ll)) {}
|
|
117
|
-
|
|
118
|
-
static time_point_sec maximum() { return time_point_sec(0xffffffff); }
|
|
119
|
-
static time_point_sec min() { return time_point_sec(0); }
|
|
120
|
-
|
|
121
|
-
operator time_point() const { return time_point(eosio::seconds(utc_seconds)); }
|
|
122
|
-
uint32_t sec_since_epoch() const { return utc_seconds; }
|
|
123
|
-
|
|
124
|
-
/// @cond INTERNAL
|
|
125
|
-
time_point_sec operator=(const eosio::time_point& t) {
|
|
126
|
-
utc_seconds = uint32_t(t.time_since_epoch().count() / 1000000ll);
|
|
127
|
-
return *this;
|
|
128
|
-
}
|
|
129
|
-
time_point_sec& operator+=(uint32_t m) {
|
|
130
|
-
utc_seconds += m;
|
|
131
|
-
return *this;
|
|
132
|
-
}
|
|
133
|
-
time_point_sec& operator+=(microseconds m) {
|
|
134
|
-
utc_seconds += m.to_seconds();
|
|
135
|
-
return *this;
|
|
136
|
-
}
|
|
137
|
-
time_point_sec& operator+=(time_point_sec m) {
|
|
138
|
-
utc_seconds += m.utc_seconds;
|
|
139
|
-
return *this;
|
|
140
|
-
}
|
|
141
|
-
time_point_sec& operator-=(uint32_t m) {
|
|
142
|
-
utc_seconds -= m;
|
|
143
|
-
return *this;
|
|
144
|
-
}
|
|
145
|
-
time_point_sec& operator-=(microseconds m) {
|
|
146
|
-
utc_seconds -= m.to_seconds();
|
|
147
|
-
return *this;
|
|
148
|
-
}
|
|
149
|
-
time_point_sec& operator-=(time_point_sec m) {
|
|
150
|
-
utc_seconds -= m.utc_seconds;
|
|
151
|
-
return *this;
|
|
152
|
-
}
|
|
153
|
-
time_point_sec operator+(uint32_t offset) const { return time_point_sec(utc_seconds + offset); }
|
|
154
|
-
time_point_sec operator-(uint32_t offset) const { return time_point_sec(utc_seconds - offset); }
|
|
155
|
-
|
|
156
|
-
friend time_point operator+(const time_point_sec& t, const microseconds& m) { return time_point(t) + m; }
|
|
157
|
-
friend time_point operator-(const time_point_sec& t, const microseconds& m) { return time_point(t) - m; }
|
|
158
|
-
friend microseconds operator-(const time_point_sec& t, const time_point_sec& m) {
|
|
159
|
-
return time_point(t) - time_point(m);
|
|
160
|
-
}
|
|
161
|
-
friend microseconds operator-(const time_point& t, const time_point_sec& m) { return time_point(t) - time_point(m); }
|
|
162
|
-
uint32_t utc_seconds;
|
|
163
|
-
|
|
164
|
-
/// @endcond
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
EOSIO_REFLECT(time_point_sec, utc_seconds);
|
|
168
|
-
EOSIO_COMPARE(time_point);
|
|
169
|
-
|
|
170
|
-
template <typename S>
|
|
171
|
-
void from_json(time_point_sec& obj, S& stream) {
|
|
172
|
-
auto s = stream.get_string();
|
|
173
|
-
const char* p = s.data();
|
|
174
|
-
if (!eosio::string_to_utc_seconds(obj.utc_seconds, p, s.data() + s.size(), true, true)) {
|
|
175
|
-
check(false, convert_json_error(from_json_error::expected_time_point));
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
template <typename S>
|
|
180
|
-
void to_json(const time_point_sec& obj, S& stream) {
|
|
181
|
-
return to_json(eosio::microseconds_to_str(uint64_t(obj.utc_seconds) * 1'000'000), stream);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* This class is used in the block headers to represent the block time
|
|
186
|
-
* It is a parameterised class that takes an Epoch in milliseconds and
|
|
187
|
-
* and an interval in milliseconds and computes the number of slots.
|
|
188
|
-
*
|
|
189
|
-
* @ingroup time
|
|
190
|
-
**/
|
|
191
|
-
class block_timestamp {
|
|
192
|
-
public:
|
|
193
|
-
block_timestamp() = default;
|
|
194
|
-
|
|
195
|
-
explicit block_timestamp(uint32_t s) : slot(s) {}
|
|
196
|
-
|
|
197
|
-
block_timestamp(const time_point& t) { set_time_point(t); }
|
|
198
|
-
|
|
199
|
-
block_timestamp(const time_point_sec& t) { set_time_point(t); }
|
|
200
|
-
|
|
201
|
-
static block_timestamp maximum() { return block_timestamp(0xffff); }
|
|
202
|
-
static block_timestamp min() { return block_timestamp(0); }
|
|
203
|
-
|
|
204
|
-
block_timestamp next() const {
|
|
205
|
-
eosio::check(std::numeric_limits<uint32_t>::max() - slot >= 1, "block timestamp overflow");
|
|
206
|
-
auto result = block_timestamp(*this);
|
|
207
|
-
result.slot += 1;
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
time_point to_time_point() const { return (time_point)(*this); }
|
|
212
|
-
|
|
213
|
-
operator time_point() const {
|
|
214
|
-
int64_t msec = slot * (int64_t)block_interval_ms;
|
|
215
|
-
msec += block_timestamp_epoch;
|
|
216
|
-
return time_point(milliseconds(msec));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/// @cond INTERNAL
|
|
220
|
-
void operator=(const time_point& t) { set_time_point(t); }
|
|
221
|
-
|
|
222
|
-
bool operator>(const block_timestamp& t) const { return slot > t.slot; }
|
|
223
|
-
bool operator>=(const block_timestamp& t) const { return slot >= t.slot; }
|
|
224
|
-
bool operator<(const block_timestamp& t) const { return slot < t.slot; }
|
|
225
|
-
bool operator<=(const block_timestamp& t) const { return slot <= t.slot; }
|
|
226
|
-
bool operator==(const block_timestamp& t) const { return slot == t.slot; }
|
|
227
|
-
bool operator!=(const block_timestamp& t) const { return slot != t.slot; }
|
|
228
|
-
uint32_t slot = 0;
|
|
229
|
-
static constexpr int32_t block_interval_ms = 500;
|
|
230
|
-
static constexpr int64_t block_timestamp_epoch = 946684800000ll; // epoch is year 2000
|
|
231
|
-
/// @endcond
|
|
232
|
-
private:
|
|
233
|
-
void set_time_point(const time_point& t) {
|
|
234
|
-
int64_t micro_since_epoch = t.time_since_epoch().count();
|
|
235
|
-
int64_t msec_since_epoch = micro_since_epoch / 1000;
|
|
236
|
-
slot = uint32_t((msec_since_epoch - block_timestamp_epoch) / int64_t(block_interval_ms));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
void set_time_point(const time_point_sec& t) {
|
|
240
|
-
int64_t sec_since_epoch = t.sec_since_epoch();
|
|
241
|
-
slot = uint32_t((sec_since_epoch * 1000 - block_timestamp_epoch) / block_interval_ms);
|
|
242
|
-
}
|
|
243
|
-
}; // block_timestamp
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* @ingroup time
|
|
247
|
-
*/
|
|
248
|
-
typedef block_timestamp block_timestamp_type;
|
|
249
|
-
|
|
250
|
-
EOSIO_REFLECT(block_timestamp_type, slot);
|
|
251
|
-
|
|
252
|
-
template <typename S>
|
|
253
|
-
void from_json(block_timestamp& obj, S& stream) {
|
|
254
|
-
time_point tp;
|
|
255
|
-
from_json(tp, stream);
|
|
256
|
-
obj = block_timestamp(tp);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
template <typename S>
|
|
260
|
-
void to_json(const block_timestamp& obj, S& stream) {
|
|
261
|
-
return to_json(time_point(obj), stream);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
} // namespace eosio
|
package/include/eosio/to_bin.hpp
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <deque>
|
|
4
|
-
#include "for_each_field.hpp"
|
|
5
|
-
#include "stream.hpp"
|
|
6
|
-
#include <list>
|
|
7
|
-
#include <map>
|
|
8
|
-
#include <optional>
|
|
9
|
-
#include <set>
|
|
10
|
-
#include <variant>
|
|
11
|
-
#include <vector>
|
|
12
|
-
|
|
13
|
-
namespace eosio {
|
|
14
|
-
|
|
15
|
-
template <typename S>
|
|
16
|
-
bool to_bin(std::string_view sv, S& stream, std::string_view&);
|
|
17
|
-
|
|
18
|
-
template <typename S>
|
|
19
|
-
bool to_bin(const std::string& s, S& stream, std::string_view&);
|
|
20
|
-
|
|
21
|
-
template <typename T, typename S>
|
|
22
|
-
bool to_bin(const std::vector<T>& obj, S& stream, std::string_view&);
|
|
23
|
-
|
|
24
|
-
template <typename T, typename S>
|
|
25
|
-
bool to_bin(const std::optional<T>& obj, S& stream, std::string_view&);
|
|
26
|
-
|
|
27
|
-
template <typename... Ts, typename S>
|
|
28
|
-
bool to_bin(const std::variant<Ts...>& obj, S& stream, std::string_view&);
|
|
29
|
-
|
|
30
|
-
template <typename... Ts, typename S>
|
|
31
|
-
bool to_bin(const std::tuple<Ts...>& obj, S& stream, std::string_view&);
|
|
32
|
-
|
|
33
|
-
template <typename T, typename S>
|
|
34
|
-
bool to_bin(const T& obj, S& stream, std::string_view&);
|
|
35
|
-
|
|
36
|
-
template <typename S>
|
|
37
|
-
void varuint32_to_bin(uint64_t val, S& stream) {
|
|
38
|
-
check( !(val >> 32), convert_stream_error( stream_error::varuint_too_big) );
|
|
39
|
-
do {
|
|
40
|
-
uint8_t b = val & 0x7f;
|
|
41
|
-
val >>= 7;
|
|
42
|
-
b |= ((val > 0) << 7);
|
|
43
|
-
stream.write(b);
|
|
44
|
-
} while (val);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
inline void push_varuint32(std::vector<char>& bin, uint32_t v) {
|
|
48
|
-
vector_stream st{ bin };
|
|
49
|
-
varuint32_to_bin(v, st);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
template <typename S>
|
|
53
|
-
void to_bin(std::string_view sv, S& stream) {
|
|
54
|
-
varuint32_to_bin(sv.size(), stream);
|
|
55
|
-
stream.write(sv.data(), sv.size());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
template <typename S>
|
|
59
|
-
void to_bin(const std::string& s, S& stream) {
|
|
60
|
-
to_bin(std::string_view{ s }, stream);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
template <typename T, typename S>
|
|
64
|
-
void to_bin_range(const T& obj, S& stream) {
|
|
65
|
-
varuint32_to_bin(obj.size(), stream);
|
|
66
|
-
for (auto& x : obj) {
|
|
67
|
-
to_bin(x, stream);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
template <typename T, std::size_t N, typename S>
|
|
72
|
-
void to_bin(const T (&obj)[N], S& stream) {
|
|
73
|
-
varuint32_to_bin(N, stream);
|
|
74
|
-
if constexpr (has_bitwise_serialization<T>()) {
|
|
75
|
-
stream.write(reinterpret_cast<const char*>(&obj), N * sizeof(T));
|
|
76
|
-
} else {
|
|
77
|
-
for (auto& x : obj) {
|
|
78
|
-
to_bin(x, stream);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
template <typename T, typename S>
|
|
84
|
-
void to_bin(const std::vector<T>& obj, S& stream) {
|
|
85
|
-
varuint32_to_bin(obj.size(), stream);
|
|
86
|
-
if constexpr (has_bitwise_serialization<T>()) {
|
|
87
|
-
stream.write(reinterpret_cast<const char*>(obj.data()), obj.size() * sizeof(T));
|
|
88
|
-
} else {
|
|
89
|
-
for (auto& x : obj) {
|
|
90
|
-
to_bin(x, stream);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
template <typename T, typename S>
|
|
96
|
-
void to_bin(const std::list<T>& obj, S& stream) {
|
|
97
|
-
to_bin_range(obj, stream);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
template <typename T, typename S>
|
|
101
|
-
void to_bin(const std::deque<T>& obj, S& stream) {
|
|
102
|
-
to_bin_range(obj, stream);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
template <typename T, typename S>
|
|
106
|
-
void to_bin(const std::set<T>& obj, S& stream) {
|
|
107
|
-
to_bin_range(obj, stream);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
template <typename T, typename U, typename S>
|
|
111
|
-
void to_bin(const std::map<T, U>& obj, S& stream) {
|
|
112
|
-
to_bin_range(obj, stream);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
template <typename S>
|
|
116
|
-
void to_bin(const input_stream& obj, S& stream) {
|
|
117
|
-
varuint32_to_bin(obj.end - obj.pos, stream);
|
|
118
|
-
stream.write(obj.pos, obj.end - obj.pos);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
template <typename First, typename Second, typename S>
|
|
122
|
-
void to_bin(const std::pair<First, Second>& obj, S& stream) {
|
|
123
|
-
to_bin(obj.first, stream);
|
|
124
|
-
return to_bin(obj.second, stream);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
template <typename T, typename S>
|
|
128
|
-
void to_bin(const std::optional<T>& obj, S& stream) {
|
|
129
|
-
to_bin(obj.has_value(), stream);
|
|
130
|
-
if (obj)
|
|
131
|
-
to_bin(*obj, stream);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
template <typename... Ts, typename S>
|
|
135
|
-
void to_bin(const std::variant<Ts...>& obj, S& stream) {
|
|
136
|
-
varuint32_to_bin(obj.index(), stream);
|
|
137
|
-
std::visit([&](auto& x) { return to_bin(x, stream); }, obj);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
template <int i, typename T, typename S>
|
|
141
|
-
void to_bin_tuple(const T& obj, S& stream) {
|
|
142
|
-
if constexpr (i < std::tuple_size_v<T>) {
|
|
143
|
-
to_bin(std::get<i>(obj), stream);
|
|
144
|
-
to_bin_tuple<i + 1>(obj, stream);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
template <typename... Ts, typename S>
|
|
149
|
-
void to_bin(const std::tuple<Ts...>& obj, S& stream) {
|
|
150
|
-
to_bin_tuple<0>(obj, stream);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
template <typename T, std::size_t N, typename S>
|
|
154
|
-
void to_bin(const std::array<T, N>& obj, S& stream) {
|
|
155
|
-
for (const T& elem : obj) {
|
|
156
|
-
to_bin(elem, stream);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
template <typename T, typename S>
|
|
161
|
-
void to_bin(const T& obj, S& stream) {
|
|
162
|
-
if constexpr (has_bitwise_serialization<T>()) {
|
|
163
|
-
stream.write(reinterpret_cast<const char*>(&obj), sizeof(obj));
|
|
164
|
-
} else {
|
|
165
|
-
for_each_field(obj, [&](auto& member) {
|
|
166
|
-
to_bin(member, stream);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
template <typename T>
|
|
172
|
-
void convert_to_bin(const T& t, std::vector<char>& bin) {
|
|
173
|
-
size_stream ss;
|
|
174
|
-
to_bin(t, ss);
|
|
175
|
-
auto orig_size = bin.size();
|
|
176
|
-
bin.resize(orig_size + ss.size);
|
|
177
|
-
fixed_buf_stream fbs(bin.data() + orig_size, ss.size);
|
|
178
|
-
to_bin(t, fbs);
|
|
179
|
-
check( fbs.pos == fbs.end, convert_stream_error(stream_error::underrun) );
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
template <typename T>
|
|
183
|
-
std::vector<char> convert_to_bin(const T& t) {
|
|
184
|
-
std::vector<char> result;
|
|
185
|
-
convert_to_bin(t, result);
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
} // namespace eosio
|