| Index: mojo/public/c/bindings/lib/map.c
|
| diff --git a/mojo/public/c/bindings/lib/map.c b/mojo/public/c/bindings/lib/map.c
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..19faa8f8ff6640a6263c47547b2b5282d0cba3bc
|
| --- /dev/null
|
| +++ b/mojo/public/c/bindings/lib/map.c
|
| @@ -0,0 +1,36 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "mojo/public/c/bindings/map.h"
|
| +
|
| +struct MojomMapLayout {
|
| + struct MojomStructHeader header_;
|
| + union MojomArrayHeaderPtr keys;
|
| + union MojomArrayHeaderPtr values;
|
| +};
|
| +MOJO_STATIC_ASSERT(sizeof(struct MojomMapLayout) == 24u,
|
| + "MojomMapLayout is an invalid size.");
|
| +
|
| +MojomValidationResult MojomMap_Validate(
|
| + const struct MojomTypeDescriptorStruct* in_type_desc,
|
| + const struct MojomStructHeader* in_struct,
|
| + uint32_t in_buf_size,
|
| + uint32_t in_num_handles,
|
| + struct MojomValidationContext* inout_context) {
|
| + // A mojom map consists of 2 arrays (pointers), both of equal size.
|
| + const struct MojomMapLayout* map = (const struct MojomMapLayout*)in_struct;
|
| + struct MojomArrayHeader* keys_arr =
|
| + (struct MojomArrayHeader*)((char*)map +
|
| + (offsetof(struct MojomMapLayout, keys) +
|
| + map->keys.offset));
|
| + struct MojomArrayHeader* values_arr =
|
| + (struct MojomArrayHeader*)((char*)map +
|
| + (offsetof(struct MojomMapLayout, values) +
|
| + map->values.offset));
|
| +
|
| + if (keys_arr->num_elements != values_arr->num_elements)
|
| + return MOJOM_VALIDATION_DIFFERENT_SIZED_ARRAYS_IN_MAP;
|
| +
|
| + return MOJOM_VALIDATION_ERROR_NONE;
|
| +}
|
|
|