6#include <bond/core/config.h>
13inline bool ValidateType(BondDataType src, BondDataType dst)
46 return (dst == BT_DOUBLE);
57 const struct_list* last;
62inline void ValidateStruct(
const RuntimeSchema& src,
63 const RuntimeSchema& dst,
64 const struct_list* list,
67inline bool ValidateType(
const RuntimeSchema& src,
68 const RuntimeSchema& dst,
69 const struct_list* list,
72 if (dst.GetTypeId() != src.GetTypeId())
75 return ValidateType(src.GetTypeId(), dst.GetTypeId());
78 if (dst.GetType().bonded_type != src.GetType().bonded_type)
83 if (dst.GetTypeId() == BT_STRUCT && !dst.GetType().bonded_type)
85 ValidateStruct(src, dst, list, identical);
89 if (!dst.GetType().element.empty())
91 RuntimeSchema r_dst(dst, *dst.GetType().element);
92 RuntimeSchema r_src(src, *src.GetType().element);
94 if (!ValidateType(r_src, r_dst, list, identical))
100 if (!dst.GetType().key.empty())
102 RuntimeSchema r_dst(dst, *dst.GetType().key);
103 RuntimeSchema r_src(src, *src.GetType().key);
105 if (!ValidateType(r_src, r_dst, list, identical))
114inline void ValidateFields(
const RuntimeSchema& src,
115 const RuntimeSchema& dst,
116 const struct_list* list,
119 const StructDef& s_dst = dst.GetStruct();
120 const StructDef& s_src = src.GetStruct();
122 size_t n_dst = s_dst.fields.size();
123 size_t n_src = s_src.fields.size();
130 for (
size_t i_dst = 0, i_src = 0; i_dst < n_dst; )
132 const FieldDef* f_dst = &s_dst.fields[i_dst];
133 const FieldDef* f_src = (i_src < n_src) ? &s_src.fields[i_src] : NULL;
135 if (f_src && f_src->id < f_dst->id)
141 if (!f_src || f_src->id > f_dst->id)
143 if (f_dst->metadata.modifier == Required)
145 RequiredFieldMissingException(s_dst, *f_dst);
152 if (f_dst->metadata.modifier == Required &&
153 f_src->metadata.modifier == Optional)
155 OptionalToRequiredException(s_src, s_dst, *f_src, *f_dst);
158 if (!ValidateType(RuntimeSchema(src, *f_src),
159 RuntimeSchema(dst, *f_dst),
162 FieldTypeIncompatibleException(s_src, s_dst, *f_src, *f_dst);
170inline void ValidateStruct(
const RuntimeSchema& src,
171 const RuntimeSchema& dst,
172 const struct_list* list,
176 list, &dst.GetStruct(), &src.GetStruct()
179 for (; list; list = list->last)
181 if (list->dst == next.dst &&
182 list->src == next.src)
188 uint16_t d_dst = schema_depth(dst);
189 uint16_t d_src = schema_depth(src);
193 StructBaseDifferentException(src.GetStruct(), dst.GetStruct());
198 return ValidateStruct(src.GetBaseSchema(), dst, &next, identical =
false);
203 ValidateStruct(src.GetBaseSchema(), dst.GetBaseSchema(), &next, identical);
206 ValidateFields(src, dst, &next, identical);
211template <
typename Protocols>
213 :
public DeserializingTransform
216 void Begin(
const Metadata&)
const
222 void UnknownEnd()
const
225 template <
typename T>
226 bool Base(
const T& value)
const
228 return Recurse(value);
231 template <
typename T>
232 bool Field(uint16_t,
const Metadata&,
const T& value)
const
234 return Recurse(value);
237 template <
typename T>
238 [[noreturn]]
bool UnknownField(uint16_t
id,
const T&)
const
240 UnknownSchemaDefException(
id);
243 template <
typename T>
244 void Container(
const T& element, uint32_t size)
const
250 template <
typename Key,
typename T>
251 void Container(
const Key&,
const T& value, uint32_t size)
const
258 template <
typename T>
259 bool Recurse(
const T&)
const
264 template <
typename T,
typename Reader>
265 typename boost::enable_if<is_basic_type<T>,
bool>::type
266 Recurse(
const value<T, Reader>&)
const
271 template <
typename T,
typename Reader>
272 typename boost::disable_if<is_basic_type<T>,
bool>::type
273 Recurse(
const value<T, Reader>& value)
const
275 Apply<Protocols>(*
this, value);
279 template <
typename T,
typename Reader>
280 bool Recurse(
const bonded<T, Reader>& value)
const
282 return Apply<Protocols>(*
this, value);
namespace bond
Definition: apply.h:17