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

Side by Side Diff: mojo/public/c/include/mojo/bindings/union.h

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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
(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 #ifndef MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_UNION_H_
6 #define MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_UNION_H_
7
8 #include <mojo/bindings/buffer.h>
9 #include <mojo/bindings/internal/type_descriptor.h>
10 #include <mojo/bindings/internal/util.h>
11 #include <mojo/macros.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 MOJO_BEGIN_EXTERN_C
16
17 struct MojomUnionLayout {
18 // |num_bytes|, the number of bytes used in this union, includes the size of
19 // the |num_bytes| and |tag| fields, along with data.
20 uint32_t size;
21 uint32_t tag;
22 union {
23 // To be used when the data is a pointer.
24 union MojomPointer pointer;
25
26 // This is here to force this union data to be at least 8 bytes.
27 uint64_t force_size_;
28 } data;
29 };
30 MOJO_STATIC_ASSERT(sizeof(struct MojomUnionLayout) == 16,
31 "struct MojomUnionLayout must be 16 bytes.");
32
33 // Returns the number of bytes required to serialize |in_union_data|'s active
34 // field, not including the union layout (as described by |struct
35 // MojomUnionLayout|) itself.
36 // |in_type_desc| is the generated type that describes the tags of the pointer
37 // and handle types in the given union.
38 size_t MojomUnion_ComputeSerializedSize(
39 const struct MojomTypeDescriptorUnion* in_type_desc,
40 const struct MojomUnionLayout* in_union_data);
41
42 // Encodes the mojom union described by the |inout_union| buffer; note that any
43 // references from the union are also in the buffer backed by |inout_union|, and
44 // they are recursively encoded. Encodes all pointers to relative offsets, and
45 // encodes all handles by moving them into |inout_handles_buffer| and encoding
46 // the index into the handle.
47 // |in_type_desc|: Describes the pointer and handle fields of the mojom union.
48 // |inout_union|: Contains the union, and any other references outside the
49 // union.
50 // |in_union_size|: Size of the buffer backed by |inout_union| in bytes.
51 // |inout_handles_buffer|:
52 // A buffer used to record handles during encoding. The |num_handles_used|
53 // field can be used to determine how many handles were moved into this
54 // buffer.
55 void MojomUnion_EncodePointersAndHandles(
56 const struct MojomTypeDescriptorUnion* in_type_desc,
57 struct MojomUnionLayout* inout_union,
58 uint32_t in_union_size,
59 struct MojomHandleBuffer* inout_handles_buffer);
60
61 // Decodes the mojom union described by the |inout_union| buffer; note that any
62 // references from the union are also in the buffer backed by |inout_union|, and
63 // they are recursively decoded. Decodes all offsets to pointers, and decodes
64 // all handles by moving them out of |inout_handles| using the encoded index.
65 // |in_type_desc|: Describes the pointer and handle fields of the mojom union.
66 // |inout_union|: Contains the union, and any other references outside the
67 // union.
68 // |in_union_size|: Size of the buffer backed by |inout_union| in bytes.
69 // |inout_handles|: Mojo handles are moved out of this array and into
70 // |inout_union|, using the encoded index into this array.
71 // |in_num_handles|: Size in # of number elements available in |inout_handles|.
72 void MojomUnion_DecodePointersAndHandles(
73 const struct MojomTypeDescriptorUnion* in_type_desc,
74 struct MojomUnionLayout* inout_union,
75 uint32_t in_union_size,
76 MojoHandle* inout_handles,
77 uint32_t in_num_handles);
78
79 // Validates the mojom union described by the |in_union| buffer. Any
80 // references from the union are also recursively validated, and are expected to
81 // be in the same buffer backing |in_union|.
82 // |in_type_desc|: Describes the pointer and handle fields of the mojom union.
83 // |in_union|: Buffer containing the union, and any other references
84 // outside of the union.
85 // |in_union_size|: Size of the buffer backed by |in_union| in bytes.
86 // |in_num_handles|: Number of valid handles expected to be referenced from
87 // |in_union|.
88 // |inout_context|: An initialized context that contains the expected location
89 // of the next pointer and next offset. This is used to
90 // validate that no two pointers or handles are shared.
91 MojomValidationResult MojomUnion_Validate(
92 const struct MojomTypeDescriptorUnion* in_type_desc,
93 bool in_nullable,
94 const struct MojomUnionLayout* in_union,
95 uint32_t in_union_size,
96 uint32_t in_num_handles,
97 struct MojomValidationContext* inout_context);
98
99 // Copies over |in_union_data| into |out_union_data|, recursively copying any
100 // references from |in_union_data| using |buffer| to allocate space, and
101 // updating the references to point to the new copies. Note that a space is
102 // never allocated for the new union data in this function -- |out_union_data|
103 // should already be allocated for this function ahead of time. Returns false if
104 // the copy couldn't be made (insufficient space, or unrecognized tag), in which
105 // case the buffer may be partially used.
106 // |buffer|: A mojom buffer used to allocate space for any references from the
107 // union.
108 // |in_type_desc|: Describes the pointer and handle fields of the mojom union.
109 // |in_union_data|: The unencoded mojom union to be copied.
110 // |out_union_data|: Where |in_union_data| should be copied to.
111 bool MojomUnion_DeepCopy(struct MojomBuffer* buffer,
112 const struct MojomTypeDescriptorUnion* in_type_desc,
113 const struct MojomUnionLayout* in_union_data,
114 struct MojomUnionLayout* out_union_data);
115
116 MOJO_END_EXTERN_C
117
118 #endif // MOJO_PUBLIC_C_INCLUDE_MOJO_BINDINGS_UNION_H_
OLDNEW
« no previous file with comments | « mojo/public/c/include/mojo/bindings/struct.h ('k') | mojo/public/c/include/mojo/bindings/validation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698