OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/public/c/bindings/map.h" | |
6 | |
7 struct MojomMapLayout { | |
8 struct MojomStructHeader header_; | |
9 union MojomArrayHeaderPtr keys; | |
10 union MojomArrayHeaderPtr values; | |
11 }; | |
12 MOJO_STATIC_ASSERT(sizeof(struct MojomMapLayout) == 24u, | |
13 "MojomMapLayout is an invalid size."); | |
14 | |
15 MojomValidationResult MojomMap_Validate( | |
16 const struct MojomTypeDescriptorStruct* in_type_desc, | |
17 const struct MojomStructHeader* in_struct, | |
18 uint32_t in_buf_size, | |
19 uint32_t in_num_handles, | |
20 struct MojomValidationContext* inout_context) { | |
21 // A mojom map consists of 2 arrays (pointers), both of equal size. | |
22 const struct MojomMapLayout* map = (const struct MojomMapLayout*)in_struct; | |
23 struct MojomArrayHeader* keys_arr = | |
24 (struct MojomArrayHeader*)((char*)map + | |
25 (offsetof(struct MojomMapLayout, keys) + | |
26 map->keys.offset)); | |
27 struct MojomArrayHeader* values_arr = | |
28 (struct MojomArrayHeader*)((char*)map + | |
29 (offsetof(struct MojomMapLayout, values) + | |
30 map->values.offset)); | |
31 | |
32 if (keys_arr->num_elements != values_arr->num_elements) | |
33 return MOJOM_VALIDATION_DIFFERENT_SIZED_ARRAYS_IN_MAP; | |
34 | |
35 return MOJOM_VALIDATION_ERROR_NONE; | |
36 } | |
OLD | NEW |