6#include <bond/core/config.h>
8#include "simple_json_reader.h"
13template <
typename BufferT>
14inline const typename SimpleJsonReader<BufferT>::Field*
15SimpleJsonReader<BufferT>::FindField(uint16_t
id,
const Metadata& metadata, BondDataType type,
bool is_enum)
17 rapidjson::Value::ConstMemberIterator it = MemberBegin();
19 if (it != MemberEnd())
21 const char* name = detail::FieldName(metadata).c_str();
22 detail::JsonTypeMatching jsonType(type, type, is_enum);
25 for (rapidjson::Value::ConstMemberIterator end = MemberEnd(); it != end; ++it)
27 if (jsonType.TypeMatch(it->value))
29 if (strcmp(it->name.GetString(), name) == 0)
36 if (detail::try_lexical_convert(it->name.GetString(), parsedId) &&
id == parsedId)
49template <
typename Protocols,
typename A,
typename T,
typename Buffer>
50inline void DeserializeContainer(std::vector<bool, A>& var,
const T& , SimpleJsonReader<Buffer>& reader)
52 rapidjson::Value::ConstValueIterator it = reader.ArrayBegin();
53 resize_list(var, reader.ArraySize());
55 for (enumerator<std::vector<bool, A> > items(var); items.more(); ++it)
57 items.next() = it->IsTrue();
63template <
typename Protocols,
typename T,
typename Buffer>
64inline void DeserializeContainer(blob& var,
const T& , SimpleJsonReader<Buffer>& reader)
66 if (uint32_t size = reader.ArraySize())
68 boost::shared_ptr<char[]> buffer = boost::make_shared_noinit<char[]>(size);
71 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end && i < size; ++it)
73 buffer[i++] =
static_cast<blob::value_type
>(it->GetInt());
75 var.assign(buffer, i);
83template <
typename Protocols,
typename X,
typename T,
typename Buffer>
84inline typename boost::enable_if<is_list_container<X> >::type
85DeserializeContainer(X& var,
const T& element, SimpleJsonReader<Buffer>& reader)
87 detail::JsonTypeMatching type(get_type_id<
typename element_type<X>::type>::value,
89 std::is_enum<
typename element_type<X>::type>::value);
91 rapidjson::Value::ConstValueIterator it = reader.ArrayBegin();
92 resize_list(var, reader.ArraySize());
94 for (enumerator<X> items(var); items.more(); ++it)
96 if (type.ComplexTypeMatch(*it))
98 SimpleJsonReader<Buffer> input(reader, *it);
99 DeserializeElement<Protocols>(var, items.next(), detail::MakeValue(input, element));
101 else if (type.BasicTypeMatch(*it))
103 SimpleJsonReader<Buffer> input(reader, *it);
104 DeserializeElement<Protocols>(var, items.next(), value<
typename element_type<X>::type, SimpleJsonReader<Buffer>&>(input));
115template <
typename Protocols,
typename X,
typename T,
typename Buffer>
116inline typename boost::enable_if<is_set_container<X> >::type
117DeserializeContainer(X& var,
const T& element, SimpleJsonReader<Buffer>& reader)
119 detail::JsonTypeMatching type(get_type_id<
typename element_type<X>::type>::value,
121 std::is_enum<
typename element_type<X>::type>::value);
124 typename element_type<X>::type e(make_element(var));
126 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end; ++it)
128 if (type.BasicTypeMatch(*it))
130 detail::Read(*it, e);
138template <
typename Protocols,
typename X,
typename T,
typename Buffer>
139inline typename boost::enable_if<is_map_container<X> >::type
140DeserializeMap(X& var, BondDataType keyType,
const T& element, SimpleJsonReader<Buffer>& reader)
142 detail::JsonTypeMatching key_type(
143 get_type_id<
typename element_type<X>::type::first_type>::value,
145 std::is_enum<
typename element_type<X>::type::first_type>::value);
147 detail::JsonTypeMatching value_type(
148 get_type_id<
typename element_type<X>::type::second_type>::value,
150 std::is_enum<
typename element_type<X>::type::second_type>::value);
154 typename element_type<X>::type::first_type key(make_key(var));
156 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end; ++it)
158 if (key_type.BasicTypeMatch(*it))
160 detail::Read(*it, key);
164 bond::InvalidKeyTypeException();
171 bond::ElementNotFoundException(key);
174 SimpleJsonReader<Buffer> input(reader, *it);
176 if (value_type.ComplexTypeMatch(*it))
177 detail::MakeValue(input, element).template Deserialize<Protocols>(mapped_at(var, key));
179 value<typename element_type<X>::type::second_type, SimpleJsonReader<Buffer>&>(input).
Deserialize(mapped_at(var, key));
namespace bond
Definition: apply.h:17
void Deserialize(Reader input, T &obj)
Deserialize an object from a protocol reader.
Definition: bond.h:27