6#include <bond/core/config.h>
7#include <bond/core/detail/recursionguard.h>
9#include "simple_json_reader.h"
14template <
typename BufferT>
15inline const typename SimpleJsonReader<BufferT>::Field*
16SimpleJsonReader<BufferT>::FindField(uint16_t
id,
const Metadata& metadata, BondDataType type,
bool is_enum)
18 rapidjson::Value::ConstMemberIterator it = MemberBegin();
20 if (it != MemberEnd())
22 const char* name = detail::FieldName(metadata).c_str();
23 detail::JsonTypeMatching jsonType(type, type, is_enum);
26 for (rapidjson::Value::ConstMemberIterator end = MemberEnd(); it != end; ++it)
28 if (jsonType.TypeMatch(it->value))
30 if (strcmp(it->name.GetString(), name) == 0)
37 if (detail::try_lexical_convert(it->name.GetString(), parsedId) &&
id == parsedId)
50template <
typename Protocols,
typename A,
typename T,
typename Buffer>
53 bond::detail::RecursionGuard guard;
55 rapidjson::Value::ConstValueIterator it = reader.ArrayBegin();
56 resize_list(var, reader.ArraySize());
58 for (enumerator<std::vector<bool, A> > items(var); items.more(); ++it)
60 items.next() = it->IsTrue();
66template <
typename Protocols,
typename T,
typename Buffer>
69 bond::detail::RecursionGuard guard;
71 if (uint32_t size = reader.ArraySize())
73 boost::shared_ptr<char[]> buffer = boost::make_shared_noinit<char[]>(size);
76 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end && i < size; ++it)
78 buffer[i++] =
static_cast<blob::value_type
>(it->GetInt());
80 var.assign(buffer, i);
88template <
typename Protocols,
typename X,
typename T,
typename Buffer>
89inline typename boost::enable_if<is_list_container<X> >::type
92 bond::detail::RecursionGuard guard;
94 detail::JsonTypeMatching type(get_type_id<
typename element_type<X>::type>::value,
96 std::is_enum<
typename element_type<X>::type>::value);
98 rapidjson::Value::ConstValueIterator it = reader.ArrayBegin();
99 resize_list(var, reader.ArraySize());
101 for (enumerator<X> items(var); items.more(); ++it)
103 if (type.ComplexTypeMatch(*it))
106 DeserializeElement<Protocols>(var, items.next(), detail::MakeValue(input, element));
108 else if (type.BasicTypeMatch(*it))
111 DeserializeElement<Protocols>(var, items.next(), value<
typename element_type<X>::type,
SimpleJsonReader<Buffer>&>(input));
122template <
typename Protocols,
typename X,
typename T,
typename Buffer>
123inline typename boost::enable_if<is_set_container<X> >::type
126 bond::detail::RecursionGuard guard;
128 detail::JsonTypeMatching type(get_type_id<
typename element_type<X>::type>::value,
130 std::is_enum<
typename element_type<X>::type>::value);
133 typename element_type<X>::type e(make_element(var));
135 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end; ++it)
137 if (type.BasicTypeMatch(*it))
139 detail::Read(*it, e);
147template <
typename Protocols,
typename X,
typename T,
typename Buffer>
148inline typename boost::enable_if<is_map_container<X> >::type
151 bond::detail::RecursionGuard guard;
153 detail::JsonTypeMatching key_type(
154 get_type_id<
typename element_type<X>::type::first_type>::value,
156 std::is_enum<
typename element_type<X>::type::first_type>::value);
158 detail::JsonTypeMatching value_type(
159 get_type_id<
typename element_type<X>::type::second_type>::value,
161 std::is_enum<
typename element_type<X>::type::second_type>::value);
165 typename element_type<X>::type::first_type key(make_key(var));
167 for (rapidjson::Value::ConstValueIterator it = reader.ArrayBegin(), end = reader.ArrayEnd(); it != end; ++it)
169 if (key_type.BasicTypeMatch(*it))
171 detail::Read(*it, key);
175 bond::InvalidKeyTypeException();
182 bond::ElementNotFoundException(key);
187 if (value_type.ComplexTypeMatch(*it))
Reader for Simple JSON.
Definition simple_json_reader.h:28
Memory blob.
Definition blob.h:24
namespace bond
Definition apply.h:17
void Deserialize(Reader input, T &obj)
Deserialize an object from a protocol reader.
Definition bond.h:28