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

Unified Diff: mojo/public/c/bindings/lib/map.c

Issue 2163793002: C bindings: Implement _Validate(), and some pre-requisites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address comments Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/c/bindings/lib/array.c ('k') | mojo/public/c/bindings/lib/message.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
+}
« no previous file with comments | « mojo/public/c/bindings/lib/array.c ('k') | mojo/public/c/bindings/lib/message.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698