Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: mojo/public/cpp/bindings/lib/array_serialization.h

Issue 1387993002: mojo::Serialize*_() calls now propogate/return validation errors. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: unscope VALIDATION_ERROR_* enum values. early exit on null-input. additional comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_
7 7
8 #include <string.h> // For |memcpy()|. 8 #include <string.h> // For |memcpy()|.
9 #include <vector> 9 #include <vector>
10 10
(...skipping 27 matching lines...) Expand all
38 38
39 // Handles serialization and deserialization of arrays of pod types. 39 // Handles serialization and deserialization of arrays of pod types.
40 template <typename E, typename F> 40 template <typename E, typename F>
41 struct ArraySerializer<E, F, false> { 41 struct ArraySerializer<E, F, false> {
42 static_assert(sizeof(E) == sizeof(F), "Incorrect array serializer"); 42 static_assert(sizeof(E) == sizeof(F), "Incorrect array serializer");
43 static size_t GetSerializedSize(const Array<E>& input) { 43 static size_t GetSerializedSize(const Array<E>& input) {
44 return sizeof(Array_Data<F>) + Align(input.size() * sizeof(E)); 44 return sizeof(Array_Data<F>) + Align(input.size() * sizeof(E));
45 } 45 }
46 46
47 template <typename Iterator> 47 template <typename Iterator>
48 static void SerializeElements(Iterator it, 48 static ValidationError SerializeElements(
49 size_t num_elements, 49 Iterator it,
50 Buffer* buf, 50 size_t num_elements,
51 Array_Data<F>* output, 51 Buffer* buf,
52 const ArrayValidateParams* validate_params) { 52 Array_Data<F>* output,
53 const ArrayValidateParams* validate_params) {
53 MOJO_DCHECK(!validate_params->element_is_nullable) 54 MOJO_DCHECK(!validate_params->element_is_nullable)
54 << "Primitive type should be non-nullable"; 55 << "Primitive type should be non-nullable";
55 MOJO_DCHECK(!validate_params->element_validate_params) 56 MOJO_DCHECK(!validate_params->element_validate_params)
56 << "Primitive type should not have array validate params"; 57 << "Primitive type should not have array validate params";
57 for (size_t i = 0; i < num_elements; ++i, ++it) 58 for (size_t i = 0; i < num_elements; ++i, ++it)
58 output->at(i) = *it; 59 output->at(i) = *it;
60
61 return VALIDATION_ERROR_NONE;
59 } 62 }
60 63
61 // We can optimize serializing PODs by |memcpy|ing directly. 64 // We can optimize serializing PODs by |memcpy|ing directly.
62 // Note that this has precedence over its templated sibling defined above. 65 // Note that this has precedence over its templated sibling defined above.
63 static void SerializeElements(typename Array<E>::Iterator it, 66 static ValidationError SerializeElements(
64 size_t num_elements, 67 typename Array<E>::Iterator it,
65 Buffer* buf, 68 size_t num_elements,
66 Array_Data<F>* output, 69 Buffer* buf,
67 const ArrayValidateParams* validate_params) { 70 Array_Data<F>* output,
71 const ArrayValidateParams* validate_params) {
68 MOJO_DCHECK(!validate_params->element_is_nullable) 72 MOJO_DCHECK(!validate_params->element_is_nullable)
69 << "Primitive type should be non-nullable"; 73 << "Primitive type should be non-nullable";
70 MOJO_DCHECK(!validate_params->element_validate_params) 74 MOJO_DCHECK(!validate_params->element_validate_params)
71 << "Primitive type should not have array validate params"; 75 << "Primitive type should not have array validate params";
72 if (num_elements) 76 if (num_elements)
73 memcpy(output->storage(), &(*it), num_elements * sizeof(E)); 77 memcpy(output->storage(), &(*it), num_elements * sizeof(E));
78
79 return VALIDATION_ERROR_NONE;
74 } 80 }
75 81
76 static void DeserializeElements(Array_Data<F>* input, Array<E>* output) { 82 static void DeserializeElements(Array_Data<F>* input, Array<E>* output) {
77 std::vector<E> result(input->size()); 83 std::vector<E> result(input->size());
78 if (input->size()) 84 if (input->size())
79 memcpy(&result[0], input->storage(), input->size() * sizeof(E)); 85 memcpy(&result[0], input->storage(), input->size() * sizeof(E));
80 output->Swap(&result); 86 output->Swap(&result);
81 } 87 }
82 }; 88 };
83 89
84 // Serializes and deserializes arrays of bools. 90 // Serializes and deserializes arrays of bools.
85 template <> 91 template <>
86 struct ArraySerializer<bool, bool, false> { 92 struct ArraySerializer<bool, bool, false> {
87 static size_t GetSerializedSize(const Array<bool>& input) { 93 static size_t GetSerializedSize(const Array<bool>& input) {
88 return sizeof(Array_Data<bool>) + Align((input.size() + 7) / 8); 94 return sizeof(Array_Data<bool>) + Align((input.size() + 7) / 8);
89 } 95 }
90 96
91 template <typename Iterator> 97 template <typename Iterator>
92 static void SerializeElements(Iterator it, 98 static ValidationError SerializeElements(
93 size_t num_elements, 99 Iterator it,
94 Buffer* buf, 100 size_t num_elements,
95 Array_Data<bool>* output, 101 Buffer* buf,
96 const ArrayValidateParams* validate_params) { 102 Array_Data<bool>* output,
103 const ArrayValidateParams* validate_params) {
97 MOJO_DCHECK(!validate_params->element_is_nullable) 104 MOJO_DCHECK(!validate_params->element_is_nullable)
98 << "Primitive type should be non-nullable"; 105 << "Primitive type should be non-nullable";
99 MOJO_DCHECK(!validate_params->element_validate_params) 106 MOJO_DCHECK(!validate_params->element_validate_params)
100 << "Primitive type should not have array validate params"; 107 << "Primitive type should not have array validate params";
101 108
102 // TODO(darin): Can this be a memcpy somehow instead of a bit-by-bit copy? 109 // TODO(darin): Can this be a memcpy somehow instead of a bit-by-bit copy?
103 for (size_t i = 0; i < num_elements; ++i, ++it) 110 for (size_t i = 0; i < num_elements; ++i, ++it)
104 output->at(i) = *it; 111 output->at(i) = *it;
112
113 return VALIDATION_ERROR_NONE;
105 } 114 }
106 115
107 static void DeserializeElements(Array_Data<bool>* input, 116 static void DeserializeElements(Array_Data<bool>* input,
108 Array<bool>* output) { 117 Array<bool>* output) {
109 Array<bool> result(input->size()); 118 Array<bool> result(input->size());
110 // TODO(darin): Can this be a memcpy somehow instead of a bit-by-bit copy? 119 // TODO(darin): Can this be a memcpy somehow instead of a bit-by-bit copy?
111 for (size_t i = 0; i < input->size(); ++i) 120 for (size_t i = 0; i < input->size(); ++i)
112 result.at(i) = input->at(i); 121 result.at(i) = input->at(i);
113 output->Swap(&result); 122 output->Swap(&result);
114 } 123 }
115 }; 124 };
116 125
117 // Serializes and deserializes arrays of handles. 126 // Serializes and deserializes arrays of handles.
118 template <typename H> 127 template <typename H>
119 struct ArraySerializer<ScopedHandleBase<H>, H, false> { 128 struct ArraySerializer<ScopedHandleBase<H>, H, false> {
120 static size_t GetSerializedSize(const Array<ScopedHandleBase<H>>& input) { 129 static size_t GetSerializedSize(const Array<ScopedHandleBase<H>>& input) {
121 return sizeof(Array_Data<H>) + Align(input.size() * sizeof(H)); 130 return sizeof(Array_Data<H>) + Align(input.size() * sizeof(H));
122 } 131 }
123 132
124 template <typename Iterator> 133 template <typename Iterator>
125 static void SerializeElements(Iterator it, 134 static ValidationError SerializeElements(
126 size_t num_elements, 135 Iterator it,
127 Buffer* buf, 136 size_t num_elements,
128 Array_Data<H>* output, 137 Buffer* buf,
129 const ArrayValidateParams* validate_params) { 138 Array_Data<H>* output,
139 const ArrayValidateParams* validate_params) {
130 MOJO_DCHECK(!validate_params->element_validate_params) 140 MOJO_DCHECK(!validate_params->element_validate_params)
131 << "Handle type should not have array validate params"; 141 << "Handle type should not have array validate params";
132 142
133 for (size_t i = 0; i < num_elements; ++i, ++it) { 143 for (size_t i = 0; i < num_elements; ++i, ++it) {
134 // Transfer ownership of the handle. 144 // Transfer ownership of the handle.
135 output->at(i) = it->release(); 145 output->at(i) = it->release();
136 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 146 if (!validate_params->element_is_nullable && !output->at(i).is_valid()) {
137 !validate_params->element_is_nullable && !output->at(i).is_valid(), 147 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
138 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, 148 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
139 MakeMessageWithArrayIndex( 149 MakeMessageWithArrayIndex(
140 "invalid handle in array expecting valid handles", num_elements, 150 "invalid handle in array expecting valid handles", num_elements,
141 i)); 151 i));
152 return VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE;
153 }
142 } 154 }
155
156 return VALIDATION_ERROR_NONE;
143 } 157 }
144 158
145 static void DeserializeElements(Array_Data<H>* input, 159 static void DeserializeElements(Array_Data<H>* input,
146 Array<ScopedHandleBase<H>>* output) { 160 Array<ScopedHandleBase<H>>* output) {
147 Array<ScopedHandleBase<H>> result(input->size()); 161 Array<ScopedHandleBase<H>> result(input->size());
148 for (size_t i = 0; i < input->size(); ++i) 162 for (size_t i = 0; i < input->size(); ++i)
149 result.at(i) = MakeScopedHandle(FetchAndReset(&input->at(i))); 163 result.at(i) = MakeScopedHandle(FetchAndReset(&input->at(i)));
150 output->Swap(&result); 164 output->Swap(&result);
151 } 165 }
152 }; 166 };
(...skipping 11 matching lines...) Expand all
164 typename RemovePointer<typename WrapperTraits<S>::DataType>::type S_Data; 178 typename RemovePointer<typename WrapperTraits<S>::DataType>::type S_Data;
165 static size_t GetSerializedSize(const Array<S>& input) { 179 static size_t GetSerializedSize(const Array<S>& input) {
166 size_t size = sizeof(Array_Data<S_Data*>) + 180 size_t size = sizeof(Array_Data<S_Data*>) +
167 input.size() * sizeof(StructPointer<S_Data>); 181 input.size() * sizeof(StructPointer<S_Data>);
168 for (size_t i = 0; i < input.size(); ++i) 182 for (size_t i = 0; i < input.size(); ++i)
169 size += GetSerializedSize_(*(UnwrapConstStructPtr<S>::value(input[i]))); 183 size += GetSerializedSize_(*(UnwrapConstStructPtr<S>::value(input[i])));
170 return size; 184 return size;
171 } 185 }
172 186
173 template <typename Iterator> 187 template <typename Iterator>
174 static void SerializeElements(Iterator it, 188 static ValidationError SerializeElements(
175 size_t num_elements, 189 Iterator it,
176 Buffer* buf, 190 size_t num_elements,
177 Array_Data<S_Data*>* output, 191 Buffer* buf,
178 const ArrayValidateParams* validate_params) { 192 Array_Data<S_Data*>* output,
193 const ArrayValidateParams* validate_params) {
179 for (size_t i = 0; i < num_elements; ++i, ++it) { 194 for (size_t i = 0; i < num_elements; ++i, ++it) {
180 S_Data* element; 195 S_Data* element;
181 SerializeCaller::Run(&(*it), buf, &element, 196 auto retval = SerializeCaller::Run(
182 validate_params->element_validate_params); 197 &(*it), buf, &element, validate_params->element_validate_params);
198 if (retval != VALIDATION_ERROR_NONE)
199 return retval;
200
183 output->at(i) = element; 201 output->at(i) = element;
184 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 202 if (!validate_params->element_is_nullable && !element) {
185 !validate_params->element_is_nullable && !element, 203 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
186 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 204 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
187 MakeMessageWithArrayIndex("null in array expecting valid pointers", 205 MakeMessageWithArrayIndex("null in array expecting valid pointers",
188 num_elements, i)); 206 num_elements, i));
207 return VALIDATION_ERROR_UNEXPECTED_NULL_POINTER;
208 }
189 } 209 }
210
211 return VALIDATION_ERROR_NONE;
190 } 212 }
191 213
192 static void DeserializeElements(Array_Data<S_Data*>* input, 214 static void DeserializeElements(Array_Data<S_Data*>* input,
193 Array<S>* output) { 215 Array<S>* output) {
194 Array<S> result(input->size()); 216 Array<S> result(input->size());
195 for (size_t i = 0; i < input->size(); ++i) { 217 for (size_t i = 0; i < input->size(); ++i) {
196 DeserializeCaller::Run(input->at(i), &result[i]); 218 DeserializeCaller::Run(input->at(i), &result[i]);
197 } 219 }
198 output->Swap(&result); 220 output->Swap(&result);
199 } 221 }
200 222
201 private: 223 private:
202 // SerializeCaller template is used by |ArraySerializer| to dispatch a 224 // SerializeCaller template is used by |ArraySerializer| to dispatch a
203 // serialize call on a non-POD type. This template is defined outside 225 // serialize call on a non-POD type. This template is defined outside
204 // |ArraySerializer| since you cannot specialize a struct within a class 226 // |ArraySerializer| since you cannot specialize a struct within a class
205 // definition. 227 // definition.
206 struct SerializeCaller { 228 struct SerializeCaller {
207 // This template needs to be suppressed if |T| is |String|, otherwise it 229 // This template needs to be suppressed if |T| is |String|, otherwise it
208 // takes precedence over the |String|-overloaded Run() below. 230 // takes precedence over the |String|-overloaded Run() below.
209 template <typename T, 231 template <typename T,
210 typename = typename EnableIf<!IsSame<T, String>::value, T>::type> 232 typename = typename EnableIf<!IsSame<T, String>::value, T>::type>
211 static void Run(T* input, 233 static ValidationError Run(T* input,
212 Buffer* buf, 234 Buffer* buf,
213 typename WrapperTraits<T>::DataType* output, 235 typename WrapperTraits<T>::DataType* output,
214 const ArrayValidateParams* validate_params) { 236 const ArrayValidateParams* validate_params) {
215 MOJO_DCHECK(!validate_params) 237 MOJO_DCHECK(!validate_params)
216 << "Struct type should not have array validate params"; 238 << "Struct type should not have array validate params";
217 Serialize_(UnwrapStructPtr<T>::value(*input), buf, output); 239 return Serialize_(UnwrapStructPtr<T>::value(*input), buf, output);
218 } 240 }
219 241
220 static void Run(const String* input, 242 static ValidationError Run(const String* input,
221 Buffer* buf, 243 Buffer* buf,
222 String_Data** output, 244 String_Data** output,
223 const ArrayValidateParams* validate_params) { 245 const ArrayValidateParams* validate_params) {
224 MOJO_DCHECK(validate_params && 246 MOJO_DCHECK(validate_params &&
225 !validate_params->element_validate_params && 247 !validate_params->element_validate_params &&
226 !validate_params->element_is_nullable && 248 !validate_params->element_is_nullable &&
227 validate_params->expected_num_elements == 0) 249 validate_params->expected_num_elements == 0)
228 << "String type has unexpected array validate params"; 250 << "String type has unexpected array validate params";
229 SerializeString_(*input, buf, output); 251 SerializeString_(*input, buf, output);
252 return VALIDATION_ERROR_NONE;
230 } 253 }
231 254
232 template <typename T> 255 template <typename T>
233 static void Run(Array<T>* input, 256 static ValidationError Run(Array<T>* input,
234 Buffer* buf, 257 Buffer* buf,
235 typename Array<T>::Data_** output, 258 typename Array<T>::Data_** output,
236 const ArrayValidateParams* validate_params) { 259 const ArrayValidateParams* validate_params) {
237 SerializeArray_(input, buf, output, validate_params); 260 return SerializeArray_(input, buf, output, validate_params);
238 } 261 }
239 262
240 template <typename Key, typename Value> 263 template <typename Key, typename Value>
241 static void Run(Map<Key, Value>* input, 264 static ValidationError Run(Map<Key, Value>* input,
242 Buffer* buf, 265 Buffer* buf,
243 typename Map<Key, Value>::Data_** output, 266 typename Map<Key, Value>::Data_** output,
244 const ArrayValidateParams* validate_params) { 267 const ArrayValidateParams* validate_params) {
245 SerializeMap_(input, buf, output, validate_params); 268 return SerializeMap_(input, buf, output, validate_params);
246 } 269 }
247 }; 270 };
248 271
249 struct DeserializeCaller { 272 struct DeserializeCaller {
250 template <typename T> 273 template <typename T>
251 static void Run(typename WrapperTraits<T>::DataType input, T* output) { 274 static void Run(typename WrapperTraits<T>::DataType input, T* output) {
252 Deserialize_(input, output); 275 Deserialize_(input, output);
253 } 276 }
254 277
255 // Since Deserialize_ takes in a |Struct*| (not |StructPtr|), we need to 278 // Since Deserialize_ takes in a |Struct*| (not |StructPtr|), we need to
(...skipping 24 matching lines...) Expand all
280 size_t size = sizeof(Array_Data<U_Data>); 303 size_t size = sizeof(Array_Data<U_Data>);
281 for (size_t i = 0; i < input.size(); ++i) { 304 for (size_t i = 0; i < input.size(); ++i) {
282 // GetSerializedSize_ will account for both the data in the union and the 305 // GetSerializedSize_ will account for both the data in the union and the
283 // space in the array used to hold the union. 306 // space in the array used to hold the union.
284 size += GetSerializedSize_(input[i], false); 307 size += GetSerializedSize_(input[i], false);
285 } 308 }
286 return size; 309 return size;
287 } 310 }
288 311
289 template <typename Iterator> 312 template <typename Iterator>
290 static void SerializeElements(Iterator it, 313 static ValidationError SerializeElements(
291 size_t num_elements, 314 Iterator it,
292 Buffer* buf, 315 size_t num_elements,
293 Array_Data<U_Data>* output, 316 Buffer* buf,
294 const ArrayValidateParams* validate_params) { 317 Array_Data<U_Data>* output,
318 const ArrayValidateParams* validate_params) {
295 for (size_t i = 0; i < num_elements; ++i, ++it) { 319 for (size_t i = 0; i < num_elements; ++i, ++it) {
296 U_Data* result = output->storage() + i; 320 U_Data* result = output->storage() + i;
297 SerializeUnion_(it->get(), buf, &result, true); 321 auto retval = SerializeUnion_(it->get(), buf, &result, true);
298 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 322 if (retval != VALIDATION_ERROR_NONE)
299 !validate_params->element_is_nullable && output->at(i).is_null(), 323 return retval;
300 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, 324 if (!validate_params->element_is_nullable && output->at(i).is_null()) {
301 MakeMessageWithArrayIndex("null in array expecting valid unions", 325 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
302 num_elements, i)); 326
327 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
328 MakeMessageWithArrayIndex("null in array expecting valid unions",
329 num_elements, i));
330 return VALIDATION_ERROR_UNEXPECTED_NULL_POINTER;
331 }
303 } 332 }
333
334 return VALIDATION_ERROR_NONE;
304 } 335 }
305 336
306 static void DeserializeElements(Array_Data<U_Data>* input, Array<U>* output) { 337 static void DeserializeElements(Array_Data<U_Data>* input, Array<U>* output) {
307 Array<U> result(input->size()); 338 Array<U> result(input->size());
308 for (size_t i = 0; i < input->size(); ++i) { 339 for (size_t i = 0; i < input->size(); ++i) {
309 auto& elem = input->at(i); 340 auto& elem = input->at(i);
310 if (!elem.is_null()) { 341 if (!elem.is_null()) {
311 using UnwrapedUnionType = typename RemoveStructPtr<U>::type; 342 using UnwrapedUnionType = typename RemoveStructPtr<U>::type;
312 result[i] = UnwrapedUnionType::New(); 343 result[i] = UnwrapedUnionType::New();
313 Deserialize_(&elem, result[i].get()); 344 Deserialize_(&elem, result[i].get());
314 } 345 }
315 } 346 }
316 output->Swap(&result); 347 output->Swap(&result);
317 } 348 }
318 }; 349 };
319 350
320 } // namespace internal 351 } // namespace internal
321 352
322 template <typename E> 353 template <typename E>
323 inline size_t GetSerializedSize_(const Array<E>& input) { 354 inline size_t GetSerializedSize_(const Array<E>& input) {
324 if (!input) 355 if (!input)
325 return 0; 356 return 0;
326 typedef typename internal::WrapperTraits<E>::DataType F; 357 typedef typename internal::WrapperTraits<E>::DataType F;
327 return internal::ArraySerializer<E, F>::GetSerializedSize(input); 358 return internal::ArraySerializer<E, F>::GetSerializedSize(input);
328 } 359 }
329 360
361 // SerializeArray_ will return VALIDATION_ERROR_NONE on success and sets
362 // |output| accordingly. On failure, |input| will be partially serialized into
363 // |output| up until an error occurs (which is propagated up and returned by
364 // SerializeArray_), in which case |buf| is also partially consumed.
330 template <typename E, typename F> 365 template <typename E, typename F>
331 inline void SerializeArray_( 366 inline internal::ValidationError SerializeArray_(
332 Array<E>* input, 367 Array<E>* input,
333 internal::Buffer* buf, 368 internal::Buffer* buf,
334 internal::Array_Data<F>** output, 369 internal::Array_Data<F>** output,
335 const internal::ArrayValidateParams* validate_params) { 370 const internal::ArrayValidateParams* validate_params) {
336 MOJO_DCHECK(input); 371 MOJO_DCHECK(input);
337 if (*input) { 372 if (!*input) {
373 // It is up to the caller to make the given |Array| is not null if it is
viettrungluu 2015/10/09 01:35:19 "is not null" -> "non-null"?
vardhan 2015/10/09 22:31:28 Done. (it was supposed to be "make sure")
374 // not nullable.
375 *output = nullptr;
376 return internal::VALIDATION_ERROR_NONE;
377 }
378
379 if (validate_params->expected_num_elements != 0 &&
380 input->size() != validate_params->expected_num_elements) {
338 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 381 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
339 validate_params->expected_num_elements != 0 &&
340 input->size() != validate_params->expected_num_elements,
341 internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, 382 internal::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER,
342 internal::MakeMessageWithExpectedArraySize( 383 internal::MakeMessageWithExpectedArraySize(
343 "fixed-size array has wrong number of elements", input->size(), 384 "fixed-size array has wrong number of elements", input->size(),
344 validate_params->expected_num_elements)); 385 validate_params->expected_num_elements));
386 return internal::ValidationError::VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER;
387 }
345 388
346 internal::Array_Data<F>* result = 389 internal::Array_Data<F>* result =
347 internal::Array_Data<F>::New(input->size(), buf); 390 internal::Array_Data<F>::New(input->size(), buf);
348 if (result) { 391 auto retval = internal::ArraySerializer<E, F>::SerializeElements(
349 internal::ArraySerializer<E, F>::SerializeElements( 392 input->begin(), input->size(), buf, result, validate_params);
350 input->begin(), input->size(), buf, result, validate_params); 393 if (retval != internal::VALIDATION_ERROR_NONE)
351 } 394 return retval;
352 *output = result; 395
353 } else { 396 *output = result;
354 *output = nullptr; 397 return internal::VALIDATION_ERROR_NONE;
355 }
356 } 398 }
357 399
358 template <typename E, typename F> 400 template <typename E, typename F>
359 inline void Deserialize_(internal::Array_Data<F>* input, Array<E>* output) { 401 inline void Deserialize_(internal::Array_Data<F>* input, Array<E>* output) {
360 if (input) { 402 if (input) {
361 internal::ArraySerializer<E, F>::DeserializeElements(input, output); 403 internal::ArraySerializer<E, F>::DeserializeElements(input, output);
362 } else { 404 } else {
363 output->reset(); 405 output->reset();
364 } 406 }
365 } 407 }
366 408
367 } // namespace mojo 409 } // namespace mojo
368 410
369 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_ 411 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_SERIALIZATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698