OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "mojo/public/c/bindings/union.h" | 5 #include <mojo/bindings/union.h> |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <mojo/bindings/internal/type_descriptor.h> |
8 #include <string.h> | 9 #include <string.h> |
9 | 10 |
10 #include "mojo/public/c/bindings/lib/type_descriptor.h" | |
11 | |
12 #define UNION_TAG_UNKNOWN ((uint32_t)0xFFFFFFFF) | 11 #define UNION_TAG_UNKNOWN ((uint32_t)0xFFFFFFFF) |
13 | 12 |
14 size_t MojomUnion_ComputeSerializedSize( | 13 size_t MojomUnion_ComputeSerializedSize( |
15 const struct MojomTypeDescriptorUnion* in_type_desc, | 14 const struct MojomTypeDescriptorUnion* in_type_desc, |
16 const struct MojomUnionLayout* in_union_data) { | 15 const struct MojomUnionLayout* in_union_data) { |
17 assert(in_type_desc); | 16 assert(in_type_desc); |
18 assert(in_union_data); | 17 assert(in_union_data); |
19 | 18 |
20 for (size_t i = 0; i < in_type_desc->num_entries; i++) { | 19 for (size_t i = 0; i < in_type_desc->num_entries; i++) { |
21 const struct MojomTypeDescriptorUnionEntry* entry = | 20 const struct MojomTypeDescriptorUnionEntry* entry = |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 buffer, entry->elem_type, entry->elem_descriptor, | 150 buffer, entry->elem_type, entry->elem_descriptor, |
152 &(in_union_data->data), &(out_union_data->data)); | 151 &(in_union_data->data), &(out_union_data->data)); |
153 } | 152 } |
154 // We reach here if we don't recognize the tag. If it's the UNKNOWN tag, it's | 153 // We reach here if we don't recognize the tag. If it's the UNKNOWN tag, it's |
155 // not a failure. If it's an unrecognized tag (erroneous or because this union | 154 // not a failure. If it's an unrecognized tag (erroneous or because this union |
156 // is from a future-version), we don't know how to copy it, so the copy is a | 155 // is from a future-version), we don't know how to copy it, so the copy is a |
157 // failure. | 156 // failure. |
158 return in_union_data->tag < in_type_desc->num_fields || | 157 return in_union_data->tag < in_type_desc->num_fields || |
159 in_union_data->tag == UNION_TAG_UNKNOWN; | 158 in_union_data->tag == UNION_TAG_UNKNOWN; |
160 } | 159 } |
OLD | NEW |