@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.
Files changed (99) hide show
  1. package/README.md +4 -1
  2. package/dist/abieos.node +0 -0
  3. package/lib/abieos.d.ts +19 -0
  4. package/lib/abieos.d.ts.map +1 -0
  5. package/lib/abieos.js +100 -0
  6. package/lib/abieos.ts +107 -0
  7. package/package.json +13 -8
  8. package/.idea/modules.xml +0 -8
  9. package/.idea/node-abieos.iml +0 -12
  10. package/.idea/vcs.xml +0 -9
  11. package/.idea/workspace.xml +0 -66
  12. package/CMakeLists.txt +0 -35
  13. package/abieos.d.ts +0 -21
  14. package/abieos.js +0 -59
  15. package/eosio.json +0 -1596
  16. package/include/.clang-format +0 -76
  17. package/include/eosio/abi.hpp +0 -393
  18. package/include/eosio/asset.hpp +0 -458
  19. package/include/eosio/bytes.hpp +0 -27
  20. package/include/eosio/chain_conversions.hpp +0 -450
  21. package/include/eosio/chain_types.hpp +0 -14
  22. package/include/eosio/check.hpp +0 -178
  23. package/include/eosio/convert.hpp +0 -95
  24. package/include/eosio/crypto.hpp +0 -148
  25. package/include/eosio/eosio_outcome.hpp +0 -41
  26. package/include/eosio/fixed_bytes.hpp +0 -250
  27. package/include/eosio/float.hpp +0 -35
  28. package/include/eosio/for_each_field.hpp +0 -48
  29. package/include/eosio/fpconv.c +0 -336
  30. package/include/eosio/fpconv.h +0 -41
  31. package/include/eosio/fpconv.license +0 -23
  32. package/include/eosio/from_bin.hpp +0 -272
  33. package/include/eosio/from_json.hpp +0 -749
  34. package/include/eosio/from_string.hpp +0 -28
  35. package/include/eosio/map_macro.h +0 -64
  36. package/include/eosio/murmur.hpp +0 -55
  37. package/include/eosio/name.hpp +0 -178
  38. package/include/eosio/opaque.hpp +0 -184
  39. package/include/eosio/operators.hpp +0 -71
  40. package/include/eosio/powers.h +0 -76
  41. package/include/eosio/reflection.hpp +0 -61
  42. package/include/eosio/ship_protocol.hpp +0 -971
  43. package/include/eosio/stream.hpp +0 -235
  44. package/include/eosio/symbol.hpp +0 -300
  45. package/include/eosio/time.hpp +0 -264
  46. package/include/eosio/to_bin.hpp +0 -189
  47. package/include/eosio/to_json.hpp +0 -334
  48. package/include/eosio/to_key.hpp +0 -305
  49. package/include/eosio/types.hpp +0 -103
  50. package/include/eosio/varint.hpp +0 -452
  51. package/include/outcome-basic.hpp +0 -6836
  52. package/include/rapidjson/allocators.h +0 -284
  53. package/include/rapidjson/cursorstreamwrapper.h +0 -78
  54. package/include/rapidjson/document.h +0 -2646
  55. package/include/rapidjson/encodedstream.h +0 -299
  56. package/include/rapidjson/encodings.h +0 -716
  57. package/include/rapidjson/error/en.h +0 -74
  58. package/include/rapidjson/error/error.h +0 -161
  59. package/include/rapidjson/filereadstream.h +0 -99
  60. package/include/rapidjson/filewritestream.h +0 -104
  61. package/include/rapidjson/fwd.h +0 -151
  62. package/include/rapidjson/internal/biginteger.h +0 -290
  63. package/include/rapidjson/internal/diyfp.h +0 -271
  64. package/include/rapidjson/internal/dtoa.h +0 -245
  65. package/include/rapidjson/internal/ieee754.h +0 -78
  66. package/include/rapidjson/internal/itoa.h +0 -308
  67. package/include/rapidjson/internal/meta.h +0 -186
  68. package/include/rapidjson/internal/pow10.h +0 -55
  69. package/include/rapidjson/internal/regex.h +0 -732
  70. package/include/rapidjson/internal/stack.h +0 -231
  71. package/include/rapidjson/internal/strfunc.h +0 -69
  72. package/include/rapidjson/internal/strtod.h +0 -290
  73. package/include/rapidjson/internal/swap.h +0 -46
  74. package/include/rapidjson/istreamwrapper.h +0 -113
  75. package/include/rapidjson/memorybuffer.h +0 -70
  76. package/include/rapidjson/memorystream.h +0 -71
  77. package/include/rapidjson/msinttypes/inttypes.h +0 -316
  78. package/include/rapidjson/msinttypes/stdint.h +0 -300
  79. package/include/rapidjson/ostreamwrapper.h +0 -81
  80. package/include/rapidjson/pointer.h +0 -1357
  81. package/include/rapidjson/prettywriter.h +0 -277
  82. package/include/rapidjson/rapidjson.h +0 -654
  83. package/include/rapidjson/reader.h +0 -2230
  84. package/include/rapidjson/schema.h +0 -2494
  85. package/include/rapidjson/stream.h +0 -223
  86. package/include/rapidjson/stringbuffer.h +0 -121
  87. package/include/rapidjson/writer.h +0 -710
  88. package/src/abi.cpp +0 -274
  89. package/src/abieos.cpp +0 -334
  90. package/src/abieos.h +0 -91
  91. package/src/abieos.hpp +0 -1011
  92. package/src/abieos_exception.hpp +0 -89
  93. package/src/abieos_numeric.hpp +0 -94
  94. package/src/abieos_ripemd160.hpp +0 -417
  95. package/src/crypto.cpp +0 -215
  96. package/src/main.cpp +0 -242
  97. package/src/ship.abi.cpp +0 -695
  98. package/tools/CMakeLists.txt +0 -9
  99. package/tools/name.cpp +0 -86
@@ -1,336 +0,0 @@
1
- /// From https://github.com/night-shift/fpconv
2
- /// Boost Software License 1.0
3
- /// See accompanying license file
4
-
5
- #include <stdbool.h>
6
- #include <string.h>
7
-
8
- #include "fpconv.h"
9
- #include "powers.h"
10
-
11
- #define fracmask 0x000FFFFFFFFFFFFFU
12
- #define expmask 0x7FF0000000000000U
13
- #define hiddenbit 0x0010000000000000U
14
- #define signmask 0x8000000000000000U
15
- #define expbias (1023 + 52)
16
-
17
- #define absv(n) ((n) < 0 ? -(n) : (n))
18
- #define minv(a, b) ((a) < (b) ? (a) : (b))
19
-
20
- static uint64_t tens[] = {
21
- 10000000000000000000U, 1000000000000000000U, 100000000000000000U,
22
- 10000000000000000U, 1000000000000000U, 100000000000000U,
23
- 10000000000000U, 1000000000000U, 100000000000U,
24
- 10000000000U, 1000000000U, 100000000U,
25
- 10000000U, 1000000U, 100000U,
26
- 10000U, 1000U, 100U,
27
- 10U, 1U
28
- };
29
-
30
- static inline uint64_t get_dbits(double d)
31
- {
32
- union {
33
- double dbl;
34
- uint64_t i;
35
- } dbl_bits = { d };
36
-
37
- return dbl_bits.i;
38
- }
39
-
40
- static Fp build_fp(double d)
41
- {
42
- uint64_t bits = get_dbits(d);
43
-
44
- Fp fp;
45
- fp.frac = bits & fracmask;
46
- fp.exp = (bits & expmask) >> 52;
47
-
48
- if(fp.exp) {
49
- fp.frac += hiddenbit;
50
- fp.exp -= expbias;
51
-
52
- } else {
53
- fp.exp = -expbias + 1;
54
- }
55
-
56
- return fp;
57
- }
58
-
59
- static void normalize(Fp* fp)
60
- {
61
- while ((fp->frac & hiddenbit) == 0) {
62
- fp->frac <<= 1;
63
- fp->exp--;
64
- }
65
-
66
- int shift = 64 - 52 - 1;
67
- fp->frac <<= shift;
68
- fp->exp -= shift;
69
- }
70
-
71
- static void get_normalized_boundaries(Fp* fp, Fp* lower, Fp* upper)
72
- {
73
- upper->frac = (fp->frac << 1) + 1;
74
- upper->exp = fp->exp - 1;
75
-
76
- while ((upper->frac & (hiddenbit << 1)) == 0) {
77
- upper->frac <<= 1;
78
- upper->exp--;
79
- }
80
-
81
- int u_shift = 64 - 52 - 2;
82
-
83
- upper->frac <<= u_shift;
84
- upper->exp = upper->exp - u_shift;
85
-
86
-
87
- int l_shift = fp->frac == hiddenbit ? 2 : 1;
88
-
89
- lower->frac = (fp->frac << l_shift) - 1;
90
- lower->exp = fp->exp - l_shift;
91
-
92
-
93
- lower->frac <<= lower->exp - upper->exp;
94
- lower->exp = upper->exp;
95
- }
96
-
97
- static Fp multiply(Fp* a, Fp* b)
98
- {
99
- const uint64_t lomask = 0x00000000FFFFFFFF;
100
-
101
- uint64_t ah_bl = (a->frac >> 32) * (b->frac & lomask);
102
- uint64_t al_bh = (a->frac & lomask) * (b->frac >> 32);
103
- uint64_t al_bl = (a->frac & lomask) * (b->frac & lomask);
104
- uint64_t ah_bh = (a->frac >> 32) * (b->frac >> 32);
105
-
106
- uint64_t tmp = (ah_bl & lomask) + (al_bh & lomask) + (al_bl >> 32);
107
- /* round up */
108
- tmp += 1U << 31;
109
-
110
- Fp fp = {
111
- ah_bh + (ah_bl >> 32) + (al_bh >> 32) + (tmp >> 32),
112
- a->exp + b->exp + 64
113
- };
114
-
115
- return fp;
116
- }
117
-
118
- static void round_digit(char* digits, int ndigits, uint64_t delta, uint64_t rem, uint64_t kappa, uint64_t frac)
119
- {
120
- while (rem < frac && delta - rem >= kappa &&
121
- (rem + kappa < frac || frac - rem > rem + kappa - frac)) {
122
-
123
- digits[ndigits - 1]--;
124
- rem += kappa;
125
- }
126
- }
127
-
128
- static int generate_digits(Fp* fp, Fp* upper, Fp* lower, char* digits, int* K)
129
- {
130
- uint64_t wfrac = upper->frac - fp->frac;
131
- uint64_t delta = upper->frac - lower->frac;
132
-
133
- Fp one;
134
- one.frac = 1ULL << -upper->exp;
135
- one.exp = upper->exp;
136
-
137
- uint64_t part1 = upper->frac >> -one.exp;
138
- uint64_t part2 = upper->frac & (one.frac - 1);
139
-
140
- int idx = 0, kappa = 10;
141
- uint64_t* divp;
142
- /* 1000000000 */
143
- for(divp = tens + 10; kappa > 0; divp++) {
144
-
145
- uint64_t div = *divp;
146
- unsigned digit = part1 / div;
147
-
148
- if (digit || idx) {
149
- digits[idx++] = digit + '0';
150
- }
151
-
152
- part1 -= digit * div;
153
- kappa--;
154
-
155
- uint64_t tmp = (part1 <<-one.exp) + part2;
156
- if (tmp <= delta) {
157
- *K += kappa;
158
- round_digit(digits, idx, delta, tmp, div << -one.exp, wfrac);
159
-
160
- return idx;
161
- }
162
- }
163
-
164
- /* 10 */
165
- uint64_t* unit = tens + 18;
166
-
167
- while(true) {
168
- part2 *= 10;
169
- delta *= 10;
170
- kappa--;
171
-
172
- unsigned digit = part2 >> -one.exp;
173
- if (digit || idx) {
174
- digits[idx++] = digit + '0';
175
- }
176
-
177
- part2 &= one.frac - 1;
178
- if (part2 < delta) {
179
- *K += kappa;
180
- round_digit(digits, idx, delta, part2, one.frac, wfrac * *unit);
181
-
182
- return idx;
183
- }
184
-
185
- unit--;
186
- }
187
- }
188
-
189
- static int grisu2(double d, char* digits, int* K)
190
- {
191
- Fp w = build_fp(d);
192
-
193
- Fp lower, upper;
194
- get_normalized_boundaries(&w, &lower, &upper);
195
-
196
- normalize(&w);
197
-
198
- int k;
199
- Fp cp = find_cachedpow10(upper.exp, &k);
200
-
201
- w = multiply(&w, &cp);
202
- upper = multiply(&upper, &cp);
203
- lower = multiply(&lower, &cp);
204
-
205
- lower.frac++;
206
- upper.frac--;
207
-
208
- *K = -k;
209
-
210
- return generate_digits(&w, &upper, &lower, digits, K);
211
- }
212
-
213
- static int emit_digits(char* digits, int ndigits, char* dest, int K, bool neg)
214
- {
215
- int exp = absv(K + ndigits - 1);
216
-
217
- /* write plain integer */
218
- if(K >= 0 && (exp < (ndigits + 7))) {
219
- memcpy(dest, digits, ndigits);
220
- memset(dest + ndigits, '0', K);
221
-
222
- return ndigits + K;
223
- }
224
-
225
- /* write decimal w/o scientific notation */
226
- if(K < 0 && (K > -7 || exp < 4)) {
227
- int offset = ndigits - absv(K);
228
- /* fp < 1.0 -> write leading zero */
229
- if(offset <= 0) {
230
- offset = -offset;
231
- dest[0] = '0';
232
- dest[1] = '.';
233
- memset(dest + 2, '0', offset);
234
- memcpy(dest + offset + 2, digits, ndigits);
235
-
236
- return ndigits + 2 + offset;
237
-
238
- /* fp > 1.0 */
239
- } else {
240
- memcpy(dest, digits, offset);
241
- dest[offset] = '.';
242
- memcpy(dest + offset + 1, digits + offset, ndigits - offset);
243
-
244
- return ndigits + 1;
245
- }
246
- }
247
-
248
- /* write decimal w/ scientific notation */
249
- ndigits = minv(ndigits, 18 - neg);
250
-
251
- int idx = 0;
252
- dest[idx++] = digits[0];
253
-
254
- if(ndigits > 1) {
255
- dest[idx++] = '.';
256
- memcpy(dest + idx, digits + 1, ndigits - 1);
257
- idx += ndigits - 1;
258
- }
259
-
260
- dest[idx++] = 'e';
261
-
262
- char sign = K + ndigits - 1 < 0 ? '-' : '+';
263
- dest[idx++] = sign;
264
-
265
- int cent = 0;
266
-
267
- if(exp > 99) {
268
- cent = exp / 100;
269
- dest[idx++] = cent + '0';
270
- exp -= cent * 100;
271
- }
272
- if(exp > 9) {
273
- int dec = exp / 10;
274
- dest[idx++] = dec + '0';
275
- exp -= dec * 10;
276
-
277
- } else if(cent) {
278
- dest[idx++] = '0';
279
- }
280
-
281
- dest[idx++] = exp % 10 + '0';
282
-
283
- return idx;
284
- }
285
-
286
- static int filter_special(double fp, char* dest)
287
- {
288
- if(fp == 0.0) {
289
- dest[0] = '0';
290
- return 1;
291
- }
292
-
293
- uint64_t bits = get_dbits(fp);
294
-
295
- bool nan = (bits & expmask) == expmask;
296
-
297
- if(!nan) {
298
- return 0;
299
- }
300
-
301
- if(bits & fracmask) {
302
- dest[0] = 'n'; dest[1] = 'a'; dest[2] = 'n';
303
-
304
- } else {
305
- dest[0] = 'i'; dest[1] = 'n'; dest[2] = 'f';
306
- }
307
-
308
- return 3;
309
- }
310
-
311
- int fpconv_dtoa(double d, char dest[24])
312
- {
313
- char digits[18];
314
-
315
- int str_len = 0;
316
- bool neg = false;
317
-
318
- if(get_dbits(d) & signmask) {
319
- dest[0] = '-';
320
- str_len++;
321
- neg = true;
322
- }
323
-
324
- int spec = filter_special(d, dest + str_len);
325
-
326
- if(spec) {
327
- return str_len + spec;
328
- }
329
-
330
- int K = 0;
331
- int ndigits = grisu2(d, digits, &K);
332
-
333
- str_len += emit_digits(digits, ndigits, dest + str_len, K, neg);
334
-
335
- return str_len;
336
- }
@@ -1,41 +0,0 @@
1
- /// From https://github.com/night-shift/fpconv
2
- /// Boost Software License 1.0
3
- /// See accompanying license file
4
-
5
- #ifndef FPCONV_H
6
- # define FPCONV_H
7
-
8
- /* Fast and accurate double to string conversion based on Florian Loitsch's
9
- * Grisu-algorithm[1].
10
- *
11
- * Input:
12
- * fp -> the double to convert, dest -> destination buffer.
13
- * The generated string will never be longer than 24 characters.
14
- * Make sure to pass a pointer to at least 24 bytes of memory.
15
- * The emitted string will not be null terminated.
16
- *
17
- * Output:
18
- * The number of written characters.
19
- *
20
- * Exemplary usage:
21
- *
22
- * void print(double d)
23
- * {
24
- * char buf[24 + 1] // plus null terminator
25
- * int str_len = fpconv_dtoa(d, buf);
26
- *
27
- * buf[str_len] = '\0';
28
- * printf("%s", buf);
29
- * }
30
- *
31
- */
32
-
33
- # ifdef __cplusplus
34
- extern "C" int fpconv_dtoa(double fp, char dest[24]);
35
- # else
36
- int fpconv_dtoa(double fp, char dest[24]);
37
- # endif
38
-
39
- #endif
40
-
41
- /* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */
@@ -1,23 +0,0 @@
1
- Boost Software License - Version 1.0 - August 17th, 2003
2
-
3
- Permission is hereby granted, free of charge, to any person or organization
4
- obtaining a copy of the software and accompanying documentation covered by
5
- this license (the "Software") to use, reproduce, display, distribute,
6
- execute, and transmit the Software, and to prepare derivative works of the
7
- Software, and to permit third-parties to whom the Software is furnished to
8
- do so, all subject to the following:
9
-
10
- The copyright notices in the Software and this entire statement, including
11
- the above license grant, this restriction and the following disclaimer,
12
- must be included in all copies of the Software, in whole or in part, and
13
- all derivative works of the Software, unless such copies or derivative
14
- works are solely in the form of machine-executable object code generated by
15
- a source language processor.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20
- SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21
- FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
- DEALINGS IN THE SOFTWARE.
@@ -1,272 +0,0 @@
1
- #pragma once
2
-
3
- #include <deque>
4
- #include "convert.hpp"
5
- #include "for_each_field.hpp"
6
- #include "stream.hpp"
7
- #include <list>
8
- #include <map>
9
- #include <optional>
10
- #include <set>
11
- #include <tuple>
12
- #include <variant>
13
- #include <vector>
14
- #include <string_view>
15
-
16
- namespace eosio {
17
-
18
- template <typename T, typename S>
19
- void from_bin(T& obj, S& stream);
20
-
21
- template <typename S>
22
- void varuint32_from_bin(uint32_t& dest, S& stream) {
23
- dest = 0;
24
- int shift = 0;
25
- uint8_t b = 0;
26
- do {
27
- check( shift < 35, convert_stream_error(stream_error::invalid_varuint_encoding) );
28
- from_bin(b, stream);
29
- dest |= uint32_t(b & 0x7f) << shift;
30
- shift += 7;
31
- } while (b & 0x80);
32
- }
33
-
34
- template <typename S>
35
- void varuint64_from_bin(uint64_t& dest, S& stream) {
36
- dest = 0;
37
- int shift = 0;
38
- uint8_t b = 0;
39
- do {
40
- check( shift < 70, convert_stream_error(stream_error::invalid_varuint_encoding) );
41
- from_bin(b, stream);
42
- dest |= uint64_t(b & 0x7f) << shift;
43
- shift += 7;
44
- } while (b & 0x80);
45
- }
46
-
47
- template <typename S>
48
- void varint32_from_bin(int32_t& result, S& stream) {
49
- uint32_t v;
50
- varuint32_from_bin(v, stream);
51
- if (v & 1)
52
- result = ((~v) >> 1) | 0x8000'0000;
53
- else
54
- result = v >> 1;
55
- }
56
-
57
- template <typename T, typename S>
58
- void from_bin_assoc(T& v, S& stream) {
59
- uint32_t size;
60
- varuint32_from_bin(size, stream);
61
- for (size_t i = 0; i < size; ++i) {
62
- typename T::value_type elem;
63
- from_bin(elem, stream);
64
- v.emplace(elem);
65
- }
66
- }
67
-
68
- template <typename T, typename S>
69
- void from_bin_sequence(T& v, S& stream) {
70
- uint32_t size;
71
- varuint32_from_bin(size, stream);
72
- for (size_t i = 0; i < size; ++i) {
73
- v.emplace_back();
74
- from_bin(v.back(), stream);
75
- }
76
- }
77
-
78
- template <typename T, std::size_t N, typename S>
79
- void from_bin(T (&v)[N], S& stream) {
80
- uint32_t size;
81
- varuint32_from_bin(size, stream);
82
- check( size == N, convert_stream_error(stream_error::array_size_mismatch) );
83
- if constexpr (has_bitwise_serialization<T>()) {
84
- stream.read(reinterpret_cast<char*>(v), size * sizeof(T));
85
- } else {
86
- for (size_t i = 0; i < size; ++i) {
87
- from_bin(v[i], stream);
88
- }
89
- }
90
- }
91
-
92
- template <typename T, typename S>
93
- void from_bin(std::vector<T>& v, S& stream) {
94
- if constexpr (has_bitwise_serialization<T>()) {
95
- if constexpr (sizeof(size_t) >= 8) {
96
- uint64_t size;
97
- varuint64_from_bin(size, stream);
98
- stream.check_available(size * sizeof(T));
99
- v.resize(size);
100
- stream.read(reinterpret_cast<char*>(v.data()), size * sizeof(T));
101
- } else {
102
- uint32_t size;
103
- varuint32_from_bin(size, stream);
104
- stream.check_available(size * sizeof(T));
105
- v.resize(size);
106
- stream.read(reinterpret_cast<char*>(v.data()), size * sizeof(T));
107
- }
108
- } else {
109
- uint32_t size;
110
- varuint32_from_bin(size, stream);
111
- v.resize(size);
112
- for (size_t i = 0; i < size; ++i) {
113
- from_bin(v[i], stream);
114
- }
115
- }
116
- }
117
-
118
- template <typename T, typename S>
119
- void from_bin(std::set<T>& v, S& stream) {
120
- return from_bin_assoc(v, stream);
121
- }
122
-
123
- template <typename T, typename U, typename S>
124
- void from_bin(std::map<T, U>& v, S& stream) {
125
- uint32_t size;
126
- varuint32_from_bin(size, stream);
127
- for (size_t i = 0; i < size; ++i) {
128
- std::pair<T, U> elem;
129
- from_bin(elem, stream);
130
- v.emplace(elem);
131
- }
132
- }
133
-
134
- template <typename T, typename S>
135
- void from_bin(std::deque<T>& v, S& stream) {
136
- return from_bin_sequence(v, stream);
137
- }
138
-
139
- template <typename T, typename S>
140
- void from_bin(std::list<T>& v, S& stream) {
141
- return from_bin_sequence(v, stream);
142
- }
143
-
144
- template <typename S>
145
- void from_bin(input_stream& obj, S& stream) {
146
- if constexpr (sizeof(size_t) >= 8) {
147
- uint64_t size;
148
- varuint64_from_bin(size, stream);
149
- stream.check_available(size);
150
- stream.read_reuse_storage(obj.pos, size);
151
- obj.end = obj.pos + size;
152
- } else {
153
- uint32_t size;
154
- varuint32_from_bin(size, stream);
155
- stream.check_available(size);
156
- stream.read_reuse_storage(obj.pos, size);
157
- obj.end = obj.pos + size;
158
- }
159
- }
160
-
161
- template <typename First, typename Second, typename S>
162
- void from_bin(std::pair<First, Second>& obj, S& stream) {
163
- from_bin(obj.first, stream);
164
- from_bin(obj.second, stream);
165
- }
166
-
167
- template <typename S>
168
- inline void from_bin(std::string& obj, S& stream) {
169
- uint32_t size;
170
- varuint32_from_bin(size, stream);
171
- obj.resize(size);
172
- stream.read(obj.data(), obj.size());
173
- }
174
-
175
- template <typename S>
176
- inline void from_bin(std::string_view& obj, S& stream) {
177
- uint32_t size;
178
- varuint32_from_bin(size, stream);
179
- obj = std::string_view(stream.get_pos(),size);
180
- stream.skip(size);
181
- }
182
-
183
- template <typename T, typename S>
184
- void from_bin(std::optional<T>& obj, S& stream) {
185
- bool present;
186
- from_bin(present, stream);
187
- if (!present) {
188
- obj.reset();
189
- return;
190
- }
191
- obj.emplace();
192
- from_bin(*obj, stream);
193
- }
194
-
195
- template <uint32_t I, typename... Ts, typename S>
196
- void variant_from_bin(std::variant<Ts...>& v, uint32_t i, S& stream) {
197
- if constexpr (I < std::variant_size_v<std::variant<Ts...>>) {
198
- if (i == I) {
199
- auto& x = v.template emplace<I>();
200
- from_bin(x, stream);
201
- } else {
202
- variant_from_bin<I + 1>(v, i, stream);
203
- }
204
- } else {
205
- check( false, convert_stream_error(stream_error::bad_variant_index) );
206
- }
207
- }
208
-
209
- template <typename... Ts, typename S>
210
- void from_bin(std::variant<Ts...>& obj, S& stream) {
211
- uint32_t u;
212
- varuint32_from_bin(u, stream);
213
- variant_from_bin<0>(obj, u, stream);
214
- }
215
-
216
- template <typename T, std::size_t N, typename S>
217
- void from_bin(std::array<T, N>& obj, S& stream) {
218
- for (T& elem : obj) {
219
- from_bin(elem, stream);
220
- }
221
- }
222
-
223
- template <int N, typename T, typename S>
224
- void from_bin_tuple(T& obj, S& stream) {
225
- if constexpr (N < std::tuple_size_v<T>) {
226
- from_bin(std::get<N>(obj), stream);
227
- from_bin_tuple<N + 1>(obj, stream);
228
- }
229
- }
230
-
231
- template <typename... T, typename S>
232
- void from_bin(std::tuple<T...>& obj, S& stream) {
233
- return from_bin_tuple<0>(obj, stream);
234
- }
235
-
236
- template <typename T, typename S>
237
- void from_bin(T& obj, S& stream) {
238
- if constexpr (has_bitwise_serialization<T>()) {
239
- stream.read(reinterpret_cast<char*>(&obj), sizeof(T));
240
- } else if constexpr (std::is_same_v<serialization_type<T>, void>) {
241
- for_each_field(obj, [&](auto& member) {
242
- from_bin(member, stream);
243
- });
244
- } else {
245
- // TODO: This can operate in place for standard serializers
246
- decltype(serialize_as(obj)) temp;
247
- from_bin(temp, stream);
248
- convert(temp, obj, choose_first);
249
- }
250
- }
251
-
252
- template <typename T, typename S>
253
- T from_bin(S& stream) {
254
- T obj;
255
- from_bin(obj, stream);
256
- return obj;
257
- }
258
-
259
- template <typename T>
260
- void convert_from_bin(T& obj, const std::vector<char>& bin) {
261
- input_stream stream{ bin };
262
- return from_bin(obj, stream);
263
- }
264
-
265
- template <typename T>
266
- T convert_from_bin(const std::vector<char>& bin) {
267
- T obj;
268
- convert_from_bin(obj, bin);
269
- return obj;
270
- }
271
-
272
- } // namespace eosio