Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
raw.hpp
Go to the documentation of this file.
1#pragma once
5#include <fc/io/varint.hpp>
6#include <fc/fwd.hpp>
7#include <fc/array.hpp>
8#include <fc/time.hpp>
9#include <fc/filesystem.hpp>
11#include <fc/safe.hpp>
12#include <fc/static_variant.hpp>
13#include <fc/io/raw_fwd.hpp>
14#include <array>
15#include <map>
16#include <deque>
17#include <list>
18
19#include <boost/multiprecision/cpp_int.hpp>
20#include <boost/interprocess/containers/string.hpp>
21#include <boost/interprocess/allocators/allocator.hpp>
22#include <boost/interprocess/managed_mapped_file.hpp>
23#include <fc/crypto/hex.hpp>
24
25namespace fc {
26 namespace raw {
27
28 namespace bip = boost::interprocess;
29 using shared_string = bip::basic_string< char, std::char_traits< char >, bip::allocator<char, bip::managed_mapped_file::segment_manager> >;
30
31 template<size_t Size>
32 using UInt = boost::multiprecision::number<
33 boost::multiprecision::cpp_int_backend<Size, Size, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void> >;
34 template<size_t Size>
35 using Int = boost::multiprecision::number<
36 boost::multiprecision::cpp_int_backend<Size, Size, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void> >;
37 template<typename Stream> void pack( Stream& s, const UInt<256>& n );
38 template<typename Stream> void unpack( Stream& s, UInt<256>& n );
39 template<typename Stream> void pack( Stream& s, const Int<256>& n );
40 template<typename Stream> void unpack( Stream& s, Int<256>& n );
41 template<typename Stream, typename T> void pack( Stream& s, const boost::multiprecision::number<T>& n );
42 template<typename Stream, typename T> void unpack( Stream& s, boost::multiprecision::number<T>& n );
43
44 template<typename Stream, typename Arg0, typename... Args>
45 inline void pack( Stream& s, const Arg0& a0, Args... args ) {
46 pack( s, a0 );
47 pack( s, args... );
48 }
49
50 template<typename Stream>
51 inline void pack( Stream& s, const fc::exception& e )
52 {
53 fc::raw::pack( s, e.code() );
54 fc::raw::pack( s, std::string(e.name()) );
55 fc::raw::pack( s, std::string(e.what()) );
56 fc::raw::pack( s, e.get_log() );
57 }
58 template<typename Stream>
59 inline void unpack( Stream& s, fc::exception& e )
60 {
61 int64_t code;
62 std::string name, what;
63 log_messages msgs;
64
65 fc::raw::unpack( s, code );
67 fc::raw::unpack( s, what );
68 fc::raw::unpack( s, msgs );
69
70 e = fc::exception( fc::move(msgs), code, name, what );
71 }
72
73 template<typename Stream>
74 inline void pack( Stream& s, const fc::log_message& msg )
75 {
76 fc::raw::pack( s, variant(msg) );
77 }
78 template<typename Stream>
79 inline void unpack( Stream& s, fc::log_message& msg )
80 {
81 fc::variant vmsg;
82 fc::raw::unpack( s, vmsg );
83 msg = vmsg.as<log_message>();
84 }
85
86 template<typename Stream>
87 inline void pack( Stream& s, const fc::path& tp )
88 {
90 }
91
92 template<typename Stream>
93 inline void unpack( Stream& s, fc::path& tp )
94 {
95 std::string p;
97 tp = p;
98 }
99
100 template<typename Stream>
101 inline void pack( Stream& s, const fc::time_point_sec& tp )
102 {
103 uint32_t usec = tp.sec_since_epoch();
104 s.write( (const char*)&usec, sizeof(usec) );
105 }
106
107 template<typename Stream>
108 inline void unpack( Stream& s, fc::time_point_sec& tp )
109 { try {
110 uint32_t sec;
111 s.read( (char*)&sec, sizeof(sec) );
112 tp = fc::time_point() + fc::seconds(sec);
113 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
114
115 template<typename Stream>
116 inline void pack( Stream& s, const fc::time_point& tp )
117 {
118 uint64_t usec = tp.time_since_epoch().count();
119 s.write( (const char*)&usec, sizeof(usec) );
120 }
121
122 template<typename Stream>
123 inline void unpack( Stream& s, fc::time_point& tp )
124 { try {
125 uint64_t usec;
126 s.read( (char*)&usec, sizeof(usec) );
127 tp = fc::time_point() + fc::microseconds(usec);
128 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
129
130 template<typename Stream>
131 inline void pack( Stream& s, const fc::microseconds& usec )
132 {
133 uint64_t usec_as_int64 = usec.count();
134 s.write( (const char*)&usec_as_int64, sizeof(usec_as_int64) );
135 }
136
137 template<typename Stream>
138 inline void unpack( Stream& s, fc::microseconds& usec )
139 { try {
140 uint64_t usec_as_int64;
141 s.read( (char*)&usec_as_int64, sizeof(usec_as_int64) );
142 usec = fc::microseconds(usec_as_int64);
143 } FC_RETHROW_EXCEPTIONS( warn, "" ) }
144
145 template<typename Stream, typename T, size_t N>
146 inline auto pack( Stream& s, const fc::array<T,N>& v) -> std::enable_if_t<!is_trivial_array<T>>
147 {
148 static_assert( N <= MAX_NUM_ARRAY_ELEMENTS, "number of elements in array is too large" );
149 for (uint64_t i = 0; i < N; ++i)
150 fc::raw::pack(s, v.data[i]);
151 }
152
153 template<typename Stream, typename T, size_t N>
154 inline auto pack( Stream& s, const fc::array<T,N>& v) -> std::enable_if_t<is_trivial_array<T>>
155 {
156 static_assert( N <= MAX_NUM_ARRAY_ELEMENTS, "number of elements in array is too large" );
157 s.write((const char*)&v.data[0], N*sizeof(T));
158 }
159
160 template<typename Stream, typename T, size_t N>
161 inline auto unpack( Stream& s, fc::array<T,N>& v) -> std::enable_if_t<!is_trivial_array<T>>
162 { try {
163 static_assert( N <= MAX_NUM_ARRAY_ELEMENTS, "number of elements in array is too large" );
164 for (uint64_t i = 0; i < N; ++i)
165 fc::raw::unpack(s, v.data[i]);
166 } FC_RETHROW_EXCEPTIONS( warn, "fc::array<${type},${length}>", ("type",fc::get_typename<T>::name())("length",N) ) }
167
168 template<typename Stream, typename T, size_t N>
169 inline auto unpack( Stream& s, fc::array<T,N>& v) -> std::enable_if_t<is_trivial_array<T>>
170 { try {
171 static_assert( N <= MAX_NUM_ARRAY_ELEMENTS, "number of elements in array is too large" );
172 s.read((char*)&v.data[0], N*sizeof(T));
173 } FC_RETHROW_EXCEPTIONS( warn, "fc::array<${type},${length}>", ("type",fc::get_typename<T>::name())("length",N) ) }
174
175 template<typename Stream, typename T, size_t N>
176 inline void pack( Stream& s, T (&v)[N]) {
178 for (uint64_t i = 0; i < N; ++i)
179 fc::raw::pack(s, v[i]);
180 }
181
182 template<typename Stream, typename T, size_t N>
183 inline void unpack( Stream& s, T (&v)[N])
184 { try {
185 unsigned_int size; fc::raw::unpack( s, size );
186 FC_ASSERT( size.value == N );
187 for (uint64_t i = 0; i < N; ++i)
188 fc::raw::unpack(s, v[i]);
189 } FC_RETHROW_EXCEPTIONS( warn, "${type} (&v)[${length}]", ("type",fc::get_typename<T>::name())("length",N) ) }
190
191 template<typename Stream, typename T>
192 inline void pack( Stream& s, const std::shared_ptr<T>& v)
193 {
194 fc::raw::pack( s, bool(!!v) );
195 if( !!v ) fc::raw::pack( s, *v );
196 }
197
198 template<typename Stream, typename T>
199 inline void unpack( Stream& s, std::shared_ptr<T>& v)
200 { try {
201 bool b; fc::raw::unpack( s, b );
202 if( b ) { v = std::make_shared<T>(); fc::raw::unpack( s, *v ); }
203 } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }
204
205 template<typename Stream> inline void pack( Stream& s, const signed_int& v ) {
206 uint32_t val = (v.value<<1) ^ (v.value>>31); //apply zigzag encoding
207 do {
208 uint8_t b = uint8_t(val) & 0x7f;
209 val >>= 7;
210 b |= ((val > 0) << 7);
211 s.write((char*)&b,1);//.put(b);
212 } while( val );
213 }
214
215 template<typename Stream> inline void pack( Stream& s, const unsigned_int& v ) {
216 uint64_t val = v.value;
217 do {
218 uint8_t b = uint8_t(val) & 0x7f;
219 val >>= 7;
220 b |= ((val > 0) << 7);
221 s.write((char*)&b,1);//.put(b);
222 }while( val );
223 }
224
225 template<typename Stream> inline void unpack( Stream& s, signed_int& vi ) {
226 uint32_t v = 0; char b = 0; int by = 0;
227 do {
228 s.get(b);
229 v |= uint32_t(uint8_t(b) & 0x7f) << by;
230 by += 7;
231 } while( uint8_t(b) & 0x80 );
232 vi.value= (v>>1) ^ (~(v&1)+1ull); //reverse zigzag encoding
233 }
234
235 template<typename Stream> inline void unpack( Stream& s, unsigned_int& vi ) {
236 uint64_t v = 0; char b = 0; uint8_t by = 0;
237 do {
238 s.get(b);
239 v |= uint32_t(uint8_t(b) & 0x7f) << by;
240 by += 7;
241 } while( uint8_t(b) & 0x80 && by < 32 );
242 vi.value = static_cast<uint32_t>(v);
243 }
244
245 template<typename Stream, typename T> inline void unpack( Stream& s, const T& vi )
246 {
247 T tmp;
248 fc::raw::unpack( s, tmp );
249 FC_ASSERT( vi == tmp );
250 }
251
252 template<typename Stream> inline void pack( Stream& s, const char* v ) { fc::raw::pack( s, fc::string(v) ); }
253
254 template<typename Stream, typename T>
255 void pack( Stream& s, const safe<T>& v ) { fc::raw::pack( s, v.value ); }
256
257 template<typename Stream, typename T>
259
260 template<typename Stream, typename T, unsigned int S, typename Align>
261 void pack( Stream& s, const fc::fwd<T,S,Align>& v ) {
262 fc::raw::pack( *v );
263 }
264
265 template<typename Stream, typename T, unsigned int S, typename Align>
267 fc::raw::unpack( *v );
268 }
269
270 // optional
271 template<typename Stream, typename T>
272 void pack( Stream& s, const std::optional<T>& v ) {
273 fc::raw::pack( s, v.has_value() );
274 if( v ) fc::raw::pack( s, *v );
275 }
276
277 template<typename Stream, typename T>
278 void unpack( Stream& s, std::optional<T>& v )
279 { try {
280 bool b; fc::raw::unpack( s, b );
281 if( b ) { v = T(); fc::raw::unpack( s, *v ); }
282 } FC_RETHROW_EXCEPTIONS( warn, "optional<${type}>", ("type",fc::get_typename<T>::name() ) ) }
283
284 // std::vector<char>
285 template<typename Stream> inline void pack( Stream& s, const std::vector<char>& value ) {
288 if( value.size() )
289 s.write( &value.front(), (uint32_t)value.size() );
290 }
291 template<typename Stream> inline void unpack( Stream& s, std::vector<char>& value ) {
292 unsigned_int size; fc::raw::unpack( s, size );
294 value.resize(size.value);
295 if( value.size() )
296 s.read( value.data(), value.size() );
297 }
298
299 // fc::string
300 template<typename Stream> inline void pack( Stream& s, const fc::string& v ) {
301 FC_ASSERT( v.size() <= MAX_SIZE_OF_BYTE_ARRAYS );
302 fc::raw::pack( s, unsigned_int((uint32_t)v.size()));
303 if( v.size() ) s.write( v.c_str(), v.size() );
304 }
305
306 template<typename Stream> inline void unpack( Stream& s, fc::string& v ) {
307 std::vector<char> tmp; fc::raw::unpack(s,tmp);
308 if( tmp.size() )
309 v = fc::string(tmp.data(),tmp.data()+tmp.size());
310 else v = fc::string();
311 }
312
313 // bip::basic_string
314 template<typename Stream> inline void pack( Stream& s, const shared_string& v ) {
315 FC_ASSERT( v.size() <= MAX_SIZE_OF_BYTE_ARRAYS );
316 fc::raw::pack( s, unsigned_int((uint32_t)v.size()));
317 if( v.size() ) s.write( v.c_str(), v.size() );
318 }
319
320 template<typename Stream> inline void unpack( Stream& s, shared_string& v ) {
321 std::vector<char> tmp; fc::raw::unpack(s,tmp);
322 FC_ASSERT(v.size() == 0);
323 if( tmp.size() ) {
324 v.append(tmp.begin(), tmp.end());
325 }
326 }
327
328 // bool
329 template<typename Stream> inline void pack( Stream& s, const bool& v ) { fc::raw::pack( s, uint8_t(v) ); }
330 template<typename Stream> inline void unpack( Stream& s, bool& v )
331 {
332 uint8_t b;
333 fc::raw::unpack( s, b );
334 FC_ASSERT( (b & ~1) == 0 );
335 v=(b!=0);
336 }
337
338 namespace detail {
339
340 template<typename Stream, typename Class>
342 pack_object_visitor(const Class& _c, Stream& _s)
343 :c(_c),s(_s){}
344
345 template<typename T, typename C, T(C::*p)>
346 void operator()( const char* name )const {
347 fc::raw::pack( s, c.*p );
348 }
349 private:
350 const Class& c;
351 Stream& s;
352 };
353
354 template<typename Stream, typename Class>
357 : fc::reflector_init_visitor<Class>(_c), s(_s){}
358
359 template<typename T, typename C, T(C::*p)>
360 inline void operator()( const char* name )const
361 { try {
362 fc::raw::unpack( s, this->obj.*p );
363 } FC_RETHROW_EXCEPTIONS( warn, "Error unpacking field ${field}", ("field",name) ) }
364
365 private:
366 Stream& s;
367 };
368
369 template<typename IsClass=fc::true_type>
370 struct if_class{
371 template<typename Stream, typename T>
372 static inline void pack( Stream& s, const T& v ) { s << v; }
373 template<typename Stream, typename T>
374 static inline void unpack( Stream& s, T& v ) { s >> v; }
375 };
376
377 template<>
379 template<typename Stream, typename T>
380 static inline void pack( Stream& s, const T& v ) {
381 s.write( (char*)&v, sizeof(v) );
382 }
383 template<typename Stream, typename T>
384 static inline void unpack( Stream& s, T& v ) {
385 s.read( (char*)&v, sizeof(v) );
386 }
387 };
388
389 template<typename IsEnum=fc::false_type>
390 struct if_enum {
391 template<typename Stream, typename T>
392 static inline void pack( Stream& s, const T& v ) {
394 }
395 template<typename Stream, typename T>
396 static inline void unpack( Stream& s, T& v ) {
398 }
399 };
400 template<>
402 template<typename Stream, typename T>
403 static inline void pack( Stream& s, const T& v ) {
405 }
406 template<typename Stream, typename T>
407 static inline void unpack( Stream& s, T& v ) {
408 int64_t temp;
409 fc::raw::unpack(s, temp);
410 v = (T)temp;
411 }
412 };
413
414 template<typename IsReflected=fc::false_type>
416 template<typename Stream, typename T>
417 static inline void pack( Stream& s, const T& v ) {
419 }
420 template<typename Stream, typename T>
421 static inline void unpack( Stream& s, T& v ) {
423 }
424 };
425 template<>
427 template<typename Stream, typename T>
428 static inline void pack( Stream& s, const T& v ) {
430 }
431 template<typename Stream, typename T>
432 static inline void unpack( Stream& s, T& v ) {
434 }
435 };
436
437 } // namesapce detail
438
439 // allow users to verify version of fc calls reflector_init on unpacked reflected types
441
442 template<typename Stream, typename T>
443 inline void pack( Stream& s, const std::unordered_set<T>& value ) {
446 auto itr = value.begin();
447 auto end = value.end();
448 while( itr != end ) {
449 fc::raw::pack( s, *itr );
450 ++itr;
451 }
452 }
453 template<typename Stream, typename T>
454 inline void unpack( Stream& s, std::unordered_set<T>& value ) {
455 unsigned_int size; fc::raw::unpack( s, size );
457 value.clear();
458 value.reserve(size.value);
459 for( uint32_t i = 0; i < size.value; ++i )
460 {
461 T tmp;
462 fc::raw::unpack( s, tmp );
463 value.insert( std::move(tmp) );
464 }
465 }
466
467
468 template<typename Stream, typename K, typename V>
469 inline void pack( Stream& s, const std::pair<K,V>& value ) {
470 fc::raw::pack( s, value.first );
471 fc::raw::pack( s, value.second );
472 }
473 template<typename Stream, typename K, typename V>
474 inline void unpack( Stream& s, std::pair<K,V>& value )
475 {
476 fc::raw::unpack( s, value.first );
477 fc::raw::unpack( s, value.second );
478 }
479
480 template<typename Stream, typename K, typename V>
481 inline void pack( Stream& s, const std::unordered_map<K,V>& value ) {
484 auto itr = value.begin();
485 auto end = value.end();
486 while( itr != end ) {
487 fc::raw::pack( s, *itr );
488 ++itr;
489 }
490 }
491 template<typename Stream, typename K, typename V>
492 inline void unpack( Stream& s, std::unordered_map<K,V>& value )
493 {
494 unsigned_int size; fc::raw::unpack( s, size );
496 value.clear();
497 value.reserve(size.value);
498 for( uint32_t i = 0; i < size.value; ++i )
499 {
500 std::pair<K,V> tmp;
501 fc::raw::unpack( s, tmp );
502 value.insert( std::move(tmp) );
503 }
504 }
505 template<typename Stream, typename K, typename V>
506 inline void pack( Stream& s, const std::map<K,V>& value ) {
509 auto itr = value.begin();
510 auto end = value.end();
511 while( itr != end ) {
512 fc::raw::pack( s, *itr );
513 ++itr;
514 }
515 }
516 template<typename Stream, typename K, typename V>
517 inline void unpack( Stream& s, std::map<K,V>& value )
518 {
519 unsigned_int size; fc::raw::unpack( s, size );
521 value.clear();
522 for( uint32_t i = 0; i < size.value; ++i )
523 {
524 std::pair<K,V> tmp;
525 fc::raw::unpack( s, tmp );
526 value.insert( std::move(tmp) );
527 }
528 }
529
530 template<typename Stream, typename T>
531 inline void pack( Stream& s, const std::deque<T>& value ) {
534 for( const auto& i : value ) {
535 fc::raw::pack( s, i );
536 }
537 }
538
539 template<typename Stream, typename T>
540 inline void unpack( Stream& s, std::deque<T>& value ) {
541 unsigned_int size; fc::raw::unpack( s, size );
543 value.resize(size.value);
544 for( auto& i : value ) {
545 fc::raw::unpack( s, i );
546 }
547 }
548
549 template<typename Stream, typename T, typename... U>
550 inline void pack( Stream& s, const boost::container::deque<T, U...>& value ) {
552 fc::raw::pack( s, unsigned_int( (uint32_t) value.size() ) );
553 for( const auto& i : value ) {
554 fc::raw::pack( s, i );
555 }
556 }
557
558 template<typename Stream, typename T, typename... U>
559 inline void unpack( Stream& s, boost::container::deque<T, U...>& value ) {
560 unsigned_int size;
561 fc::raw::unpack( s, size );
563 value.resize( size.value );
564 for( auto& i : value ) {
565 fc::raw::unpack( s, i );
566 }
567 }
568
569 template<typename Stream, typename T>
570 inline void pack( Stream& s, const std::vector<T>& value ) {
573 for( const auto& i : value ) {
574 fc::raw::pack( s, i );
575 }
576 }
577
578 template<typename Stream, typename T>
579 inline void unpack( Stream& s, std::vector<T>& value ) {
580 unsigned_int size; fc::raw::unpack( s, size );
582 value.resize(size.value);
583 for( auto& i : value ) {
584 fc::raw::unpack( s, i );
585 }
586 }
587
588 template<typename Stream, typename T>
589 inline void pack( Stream& s, const std::list<T>& value ) {
592 for( const auto& i : value ) {
593 fc::raw::pack( s, i );
594 }
595 }
596
597 template<typename Stream, typename T>
598 inline void unpack( Stream& s, std::list<T>& value ) {
599 unsigned_int size; fc::raw::unpack( s, size );
601 while( size.value-- ) {
602 T i;
603 fc::raw::unpack( s, i );
604 value.emplace_back( std::move( i ) );
605 }
606 }
607
608 template<typename Stream, typename T>
609 inline void pack( Stream& s, const std::set<T>& value ) {
612 auto itr = value.begin();
613 auto end = value.end();
614 while( itr != end ) {
615 fc::raw::pack( s, *itr );
616 ++itr;
617 }
618 }
619
620 template<typename Stream, typename T>
621 inline void unpack( Stream& s, std::set<T>& value ) {
622 unsigned_int size; fc::raw::unpack( s, size );
624 for( uint64_t i = 0; i < size.value; ++i )
625 {
626 T tmp;
627 fc::raw::unpack( s, tmp );
628 value.insert( std::move(tmp) );
629 }
630 }
631
632 template<typename Stream, typename T, std::size_t S>
633 inline auto pack( Stream& s, const std::array<T, S>& value ) -> std::enable_if_t<is_trivial_array<T>>
634 {
635 s.write((const char*)value.data(), S * sizeof(T));
636 }
637
638 template<typename Stream, typename T, std::size_t S>
639 inline auto pack( Stream& s, const std::array<T, S>& value ) -> std::enable_if_t<!is_trivial_array<T>>
640 {
641 for( std::size_t i = 0; i < S; ++i ) {
642 fc::raw::pack( s, value[i] );
643 }
644 }
645
646 template<typename Stream, typename T, std::size_t S>
647 inline auto unpack( Stream& s, std::array<T, S>& value ) -> std::enable_if_t<is_trivial_array<T>>
648 {
649 s.read((char*)value.data(), S * sizeof(T));
650 }
651
652 template<typename Stream, typename T, std::size_t S>
653 inline auto unpack( Stream& s, std::array<T, S>& value ) -> std::enable_if_t<!is_trivial_array<T>>
654 {
655 for( std::size_t i = 0; i < S; ++i ) {
656 fc::raw::unpack( s, value[i] );
657 }
658 }
659
660 template<typename Stream, typename T>
664 template<typename Stream, typename T>
665 inline void unpack( Stream& s, T& v )
666 { try {
668 } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
669
670 template<typename T>
671 inline size_t pack_size( const T& v )
672 {
674 fc::raw::pack(ps,v );
675 return ps.tellp();
676 }
677
678 template<typename T>
679 inline std::vector<char> pack( const T& v ) {
681 fc::raw::pack(ps,v );
682 std::vector<char> vec(ps.tellp());
683
684 if( vec.size() ) {
685 datastream<char*> ds( vec.data(), size_t(vec.size()) );
686 fc::raw::pack(ds,v);
687 }
688 return vec;
689 }
690
691 template<typename T, typename... Next>
692 inline std::vector<char> pack( const T& v, Next... next ) {
694 fc::raw::pack(ps,v,next...);
695 std::vector<char> vec(ps.tellp());
696
697 if( vec.size() ) {
698 datastream<char*> ds( vec.data(), size_t(vec.size()) );
699 fc::raw::pack(ds,v,next...);
700 }
701 return vec;
702 }
703
704
705 template<typename T>
706 inline T unpack( const std::vector<char>& s )
707 { try {
708 T tmp;
709 datastream<const char*> ds( s.data(), size_t(s.size()) );
710 fc::raw::unpack(ds,tmp);
711 return tmp;
712 } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
713
714 template<typename T>
715 inline void unpack( const std::vector<char>& s, T& tmp )
716 { try {
717 datastream<const char*> ds( s.data(), size_t(s.size()) );
718 fc::raw::unpack(ds,tmp);
719 } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
720
721 template<typename T>
722 inline void pack( char* d, uint32_t s, const T& v ) {
724 fc::raw::pack(ds,v );
725 }
726
727 template<typename T>
728 inline T unpack( const char* d, uint32_t s )
729 { try {
730 T v;
732 fc::raw::unpack(ds,v);
733 return v;
734 } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
735
736 template<typename T>
737 inline void unpack( const char* d, uint32_t s, T& v )
738 { try {
740 fc::raw::unpack(ds,v);
741 } FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
742
743 template<typename Stream>
745 {
748
749 typedef void result_type;
750 template<typename T> void operator()( const T& v )const
751 {
752 fc::raw::pack( stream, v );
753 }
754 };
755
756 template<typename Stream>
758 {
761
762 typedef void result_type;
763 template<typename T> void operator()( T& v )const
764 {
766 }
767 };
768
769
770 template<typename Stream, typename... T>
771 void pack( Stream& s, const std::variant<T...>& sv )
772 {
773 fc::raw::pack( s, unsigned_int(sv.index()) );
774 std::visit( pack_static_variant<Stream>(s), sv );
775 }
776
777 template<typename Stream, typename... T> void unpack( Stream& s, std::variant<T...>& sv )
778 {
779 unsigned_int w;
780 fc::raw::unpack( s, w );
781 fc::from_index(sv, w.value);
782 std::visit( unpack_static_variant<Stream>(s), sv );
783 }
784
785
786
787 template<typename Stream, typename T> void pack( Stream& s, const boost::multiprecision::number<T>& n ) {
788 static_assert( sizeof( n ) == (std::numeric_limits<boost::multiprecision::number<T>>::digits+1)/8, "unexpected padding" );
789 s.write( (const char*)&n, sizeof(n) );
790 }
791 template<typename Stream, typename T> void unpack( Stream& s, boost::multiprecision::number<T>& n ) {
792 static_assert( sizeof( n ) == (std::numeric_limits<boost::multiprecision::number<T>>::digits+1)/8, "unexpected padding" );
793 s.read( (char*)&n, sizeof(n) );
794 }
795
796 template<typename Stream> void pack( Stream& s, const UInt<256>& n ) {
797 pack( s, static_cast<UInt<128>>(n) );
798 pack( s, static_cast<UInt<128>>(n >> 128) );
799 }
800 template<typename Stream> void unpack( Stream& s, UInt<256>& n ) {
801 UInt<128> tmp[2];
802 unpack( s, tmp[0] );
803 unpack( s, tmp[1] );
804 n = tmp[1];
805 n <<= 128;
806 n |= tmp[0];
807 }
808
809} } // namespace fc::raw
const mie::Vuint & p
Definition bn.cpp:27
std::string name
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
const log_messages & get_log() const
int64_t code() const
const char * name() const
const char * what() const noexcept override
Used to forward declare value types.
Definition fwd.hpp:11
aggregates a message along with the context and associated meta-information.
constexpr int64_t count() const
Definition time.hpp:26
wraps boost::filesystem::path to provide platform independent path manipulation.
std::string generic_string() const
constexpr uint32_t sec_since_epoch() const
Definition time.hpp:88
constexpr const microseconds & time_since_epoch() const
Definition time.hpp:52
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
T as() const
Definition variant.hpp:327
Concept for reading and writing characters.
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
#define FC_RETHROW_EXCEPTIONS(LOG_LEVEL, FORMAT,...)
Catchs all exception's, std::exceptions, and ... and rethrows them after appending the provided log m...
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
constexpr bool has_feature_reflector_init_on_unpacked_reflected_types
Definition raw.hpp:440
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
bip::basic_string< char, std::char_traits< char >, bip::allocator< char, bip::managed_mapped_file::segment_manager > > shared_string
Definition raw.hpp:29
size_t pack_size(const T &v)
Definition raw.hpp:671
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< Size, Size, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > UInt
Definition raw.hpp:32
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< Size, Size, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void > > Int
Definition raw.hpp:35
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
std::vector< log_message > log_messages
constexpr microseconds seconds(int64_t s)
Definition time.hpp:32
void from_index(variant &v, int index)
#define value
Definition pkcs11.h:157
#define S(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
#define T(meth, val, expected)
const int N
Definition quantize.cpp:54
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
static void unpack(Stream &s, T &v)
Definition raw.hpp:384
static void pack(Stream &s, const T &v)
Definition raw.hpp:380
static void unpack(Stream &s, T &v)
Definition raw.hpp:374
static void pack(Stream &s, const T &v)
Definition raw.hpp:372
static void pack(Stream &s, const T &v)
Definition raw.hpp:403
static void unpack(Stream &s, T &v)
Definition raw.hpp:407
static void pack(Stream &s, const T &v)
Definition raw.hpp:392
static void unpack(Stream &s, T &v)
Definition raw.hpp:396
static void pack(Stream &s, const T &v)
Definition raw.hpp:428
static void unpack(Stream &s, T &v)
Definition raw.hpp:432
static void pack(Stream &s, const T &v)
Definition raw.hpp:417
static void unpack(Stream &s, T &v)
Definition raw.hpp:421
void operator()(const char *name) const
Definition raw.hpp:346
pack_object_visitor(const Class &_c, Stream &_s)
Definition raw.hpp:342
unpack_object_visitor(Class &_c, Stream &_s)
Definition raw.hpp:356
void operator()(const char *name) const
Definition raw.hpp:360
pack_static_variant(Stream &s)
Definition raw.hpp:747
void operator()(const T &v) const
Definition raw.hpp:750
unpack_static_variant(Stream &s)
Definition raw.hpp:760
void operator()(T &v) const
Definition raw.hpp:763
defines visit functions for T Unless this is specialized, visit() will not be defined for T.
Definition reflect.hpp:33
T value
Definition safe.hpp:23
serializes a 32 bit signed interger in as few bytes as possible
Definition varint.hpp:41
int32_t value
Definition varint.hpp:49
uint32_t value
Definition varint.hpp:17
Definition dtoa.c:306
#define MAX_SIZE_OF_BYTE_ARRAYS
Definition utility.hpp:19
#define MAX_NUM_ARRAY_ELEMENTS
Definition utility.hpp:18
CK_ULONG d
char * s