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

Side by Side Diff: docs/intro/mojom_idl.md

Issue 1762503002: Add some docs about mojom (files/IDL). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review Created 4 years, 9 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 # Mojom IDL
2
3 The Mojom IDL (interface definition language) is primarily used to describe
4 *interfaces* to be used on [message pipes](message_pipes.md). Below, we describe
5 practical aspects of the Mojom language. Elsewhere, we describe the [Mojom
6 protocol](mojom_protocol.md). (**TODO(vtl)**: Also, serialization format?
7 Versioning?)
8
9 Text files written in Mojom IDL are given the `.mojom` extension by convention
10 (and are usually referred to as Mojom/mojom/`.mojom` files). The Mojom bindings
11 generator (**TODO(vtl)**: link?) may be used to generate code in a variety of
12 languages (including C++, Dart, and Go) from a Mojom file. Such generated code
13 "implements" the things specified in the Mojom file, in a way that's appropriate
14 for the particular target language.
15
16 ## Interfaces
17
18 A Mojom *interface* is (typically) used to describe communication on a message
19 pipe. Typically, message pipes are created with a particular interface in mind,
20 with one endpoint designated the *client* (which sends *request* messages and
21 receives *response* messages) and the other designed that *server* or *impl*
22 (which receives request messages and sends response messages).
23
24 For example, take the following Mojom interface definition:
25 ```mojom
26 interface MyInterface {
27 Foo(int32 a, string b);
28 Bar() => (bool x, uint32 y);
29 Baz() => ();
30 };
31 ```
32 This specifies a Mojom interface in which the client may send three types of
33 messages, namely `Foo`, `Bar`, and `Baz` (see the note below about names in
34 Mojom). The first does not have a response message defined, whereas the latter
35 two do. Whenever the server receives a `Bar` or `Baz` message, it *must*
36 (eventually) send a (single) corresponding response message.
37
38 The `Foo` request message contains two pieces of data: a signed (two's
39 complement) 32-bit integer called `a` and a Unicode string called `b`. On the
40 "wire", the message basically consists of metadata and a (serialized) *struct*
41 (see below) containing `a` and `b`.
42
43 The `Bar` request message contains no data, so on the wire it's just metadata
44 and an empty struct. It has a response message, containing a boolean value `x`
45 and an unsigned 32-bit integer `y`, which on the wire consists of metadata and a
46 struct with `x` and `y`. Each time the server receives a `Bar` message, it is
47 supposed to (eventually) respond by sending the response message. (Note: The
48 client may include as part of the request message's metadata an identifier for
49 the request; the response's metadata will then include this identifier, allowing
50 it to match responses to requests.)
51
52 The `Baz` request message also contains no data. It requires a response, also
53 containing no data. Note that even though the response has no data, a response
54 message must nonetheless be sent, functioning as an "ack". (Thus this is
55 different from not having a response, as was the case for `Foo`.)
56
57 ### Names in Mojom
58
59 Names in Mojom are not important. Except in affecting compatibility at level of
60 source code (when generating bindings), names in a Mojom file may be changed
61 arbitrarily without any effect on the "meaning" of the Mojom file (subject to
62 basic language requirements, e.g., avoiding collisions with keywords and other
63 names). E.g., the following is completely equivalent to the interface discussed
64 above:
65 ```mojom
66 interface Something {
67 One(int32 an_integer, string a_string);
68 Two() => (bool a_boolean, uint32 an_unsigned);
69 Three() => ();
70 };
71 ```
72 The `Something` interface is compatible at a binary level with `MyInterface`. A
73 client using the `Something` interface may communicate with a server
74 implementing the `MyInterface` with no issues, and vice versa.
75
76 The reason for this is that elements (messages, parameters, struct members,
77 etc.) are actually identified by *ordinal* value. They may be specified
78 explicitly (using `@123` notation; see below). If they are not specified
79 explicitly, they are automatically assigned. (The ordinal values for each
80 interface/struct/etc. must assign distinct values for each item, in a
81 consecutive range starting at 0.)
82
83 Explicitly assigning ordinals allows Mojom files to be rearranged "physically"
84 without changing their meaning. E.g., perhaps one would write:
85 ```mojom
86 interface MyInterface {
87 Bar@1() => (bool x@0, uint32 y@1);
88 Baz@2() => ();
89
90 // Please don't use this in new code!
91 FooDeprecated@0(int32 a@0, string b@1);
92 };
93 ```
94
95 Ordinals also tie into the versioning scheme (**TODO(vtl)**: link?), which
96 allows Mojom files to be evolved in a backwards-compatible way. We will not
97 discuss this matter further here.
98
99 **TODO(vtl)**: Maybe mention exceptions to this in attributes (e.g.,
100 `ServiceName`).
101
102
103 **TODO(vtl)**: Write/(re)organize the sections below.
104
105 ## Structs
106
107 ## Modules
108
109 ## Data types
110
111 ### Primitive types
112
113 ### Enums
114
115 ### Strings
116
117 ### Nullability
118
119 ### Structs
120
121 ### Arrays
122
123 ### Maps
124
125 ### Unions
126
127 ### Handle values
128
129 ### Interface values
130
131 ### Interface requests
132
133 ## Consts
134
135 ## Annotations
136
137 ## Pipelining
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698