Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
raw_variant.hpp
Go to the documentation of this file.
1#pragma once
3#include <fc/io/raw_fwd.hpp>
5#include <fc/variant.hpp>
6
7namespace fc { namespace raw {
8
9 template<typename Stream>
11 {
12 public:
13 variant_packer( Stream& _s ):s(_s){}
14 virtual void handle()const { }
15 virtual void handle( const int64_t& v )const
16 {
17 fc::raw::pack( s, v );
18 }
19 virtual void handle( const uint64_t& v )const
20 {
21 fc::raw::pack( s, v );
22 }
23 virtual void handle( const double& v )const
24 {
25 fc::raw::pack( s, v );
26 }
27 virtual void handle( const bool& v )const
28 {
29 fc::raw::pack( s, v );
30 }
31 virtual void handle( const string& v )const
32 {
33 fc::raw::pack( s, v );
34 }
35 virtual void handle( const variant_object& v)const
36 {
37 fc::raw::pack( s, v );
38 }
39 virtual void handle( const variants& v)const
40 {
41 fc::raw::pack( s, v );
42 }
43 virtual void handle( const blob& v)const
44 {
45 fc::raw::pack( s, v );
46 }
47
49
50 };
51
52
53 template<typename Stream>
54 inline void pack( Stream& s, const variant& v )
55 {
56 pack( s, uint8_t(v.get_type()) );
58 }
59 template<typename Stream>
60 inline void unpack( Stream& s, variant& v )
61 {
62 uint8_t t;
63 unpack( s, t );
64 switch( t )
65 {
67 return;
69 {
70 int64_t val;
71 raw::unpack(s,val);
72 v = val;
73 return;
74 }
76 {
77 uint64_t val;
78 raw::unpack(s,val);
79 v = val;
80 return;
81 }
83 {
84 double val;
85 raw::unpack(s,val);
86 v = val;
87 return;
88 }
90 {
91 bool val;
92 raw::unpack(s,val);
93 v = val;
94 return;
95 }
97 {
98 fc::string val;
99 raw::unpack(s,val);
100 v = fc::move(val);
101 return;
102 }
104 {
105 variants val;
106 raw::unpack(s,val);
107 v = fc::move(val);
108 return;
109 }
111 {
112 variant_object val;
113 raw::unpack(s,val);
114 v = fc::move(val);
115 return;
116 }
118 {
119 blob val;
120 raw::unpack(s,val);
121 v = fc::move(val);
122 return;
123 }
124 default:
125 FC_THROW_EXCEPTION( parse_error_exception, "Unknown Variant Type ${t}", ("t", t) );
126 }
127 }
128
129 template<typename Stream>
130 inline void pack( Stream& s, const variant_object& v )
131 {
132 unsigned_int vs = (uint32_t)v.size();
133 pack( s, vs );
134 for( auto itr = v.begin(); itr != v.end(); ++itr )
135 {
136 pack( s, itr->key() );
137 pack( s, itr->value() );
138 }
139 }
140 template<typename Stream>
141 inline void unpack( Stream& s, variant_object& v )
142 {
143 unsigned_int vs;
144 unpack( s, vs );
145
147 mvo.reserve(vs.value);
148 for( uint32_t i = 0; i < vs.value; ++i )
149 {
152 fc::raw::unpack(s,key);
154 mvo.set( fc::move(key), fc::move(value) );
155 }
156 v = fc::move(mvo);
157 }
158
159} } // fc::raw
An order-preserving dictionary of variants.
mutable_variant_object & set(string key, variant var) &
virtual void handle(const int64_t &v) const
virtual void handle(const variant_object &v) const
virtual void handle(const bool &v) const
virtual void handle() const
handles null_type variants
virtual void handle(const double &v) const
virtual void handle(const uint64_t &v) const
virtual void handle(const string &v) const
virtual void handle(const blob &v) const
virtual void handle(const variants &v) const
An order-preserving dictionary of variants.
size_t size() const
iterator end() const
iterator begin() const
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void visit(const visitor &v) const
Definition variant.cpp:268
type_id get_type() const
Definition variant.cpp:304
Concept for reading and writing characters.
Defines exception's used by fc.
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
std::string string
Definition string.hpp:10
std::vector< fc::variant > variants
Definition variant.hpp:173
#define value
Definition pkcs11.h:157
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
uint32_t value
Definition varint.hpp:17
uint8_t key[16]
Definition yubico_otp.c:41
char * s