README.md
1# Mojom IDL and Bindings Generator
2This document is a subset of the [Mojo documentation](/mojo/README.md).
3
4[TOC]
5
6## Overview
7
8Mojom is the IDL for Mojo bindings interfaces. Given a `.mojom` file, the
9[bindings
10generator](https://cs.chromium.org/chromium/src/mojo/public/tools/bindings/)
11outputs bindings for all supported languages: **C++**, **JavaScript**, and
12**Java**.
13
14For a trivial example consider the following hypothetical Mojom file we write to
15`//services/widget/public/interfaces/frobinator.mojom`:
16
17```
18module widget.mojom;
19
20interface Frobinator {
21 Frobinate();
22};
23```
24
25This defines a single [interface](#Interfaces) named `Frobinator` in a
26[module](#Modules) named `widget.mojom` (and thus fully qualified in Mojom as
27`widget.mojom.Frobinator`.) Note that many interfaces and/or other types of
28definitions may be included in a single Mojom file.
29
30If we add a corresponding GN target to
31`//services/widget/public/interfaces/BUILD.gn`:
32
33```
34import("mojo/public/tools/bindings/mojom.gni")
35
36mojom("interfaces") {
37 sources = [
38 "frobinator.mojom",
39 ]
40}
41```
42
43and then build this target:
44
45```
46ninja -C out/r services/widget/public/interfaces
47```
48
49we'll find several generated sources in our output directory:
50
51```
52out/r/gen/services/widget/public/interfaces/frobinator.mojom.cc
53out/r/gen/services/widget/public/interfaces/frobinator.mojom.h
54out/r/gen/services/widget/public/interfaces/frobinator.mojom.js
55out/r/gen/services/widget/public/interfaces/frobinator.mojom.srcjar
56...
57```
58
59Each of these generated source modules includes a set of definitions
60representing the Mojom contents within the target language. For more details
61regarding the generated outputs please see
62[documentation for individual target languages](#Generated-Code-For-Target-Languages).
63
64## Mojom Syntax
65
66Mojom IDL allows developers to define **structs**, **unions**, **interfaces**,
67**constants**, and **enums**, all within the context of a **module**. These
68definitions are used to generate code in the supported target languages at build
69time.
70
71Mojom files may **import** other Mojom files in order to reference their
72definitions.
73
74### Primitive Types
75Mojom supports a few basic data types which may be composed into structs or used
76for message parameters.
77
78| Type | Description
79|-------------------------------|-------------------------------------------------------|
80| `bool` | Boolean type (`true` or `false`.)
81| `int8`, `uint8` | Signed or unsigned 8-bit integer.
82| `int16`, `uint16` | Signed or unsigned 16-bit integer.
83| `int32`, `uint32` | Signed or unsigned 32-bit integer.
84| `int64`, `uint64` | Signed or unsigned 64-bit integer.
85| `float`, `double` | 32- or 64-bit floating point number.
86| `string` | UTF-8 encoded string.
87| `array<T>` | Array of any Mojom type *T*; for example, `array<uint8>` or `array<array<string>>`.
88| `array<T, N>` | Fixed-length array of any Mojom type *T*. The parameter *N* must be an integral constant.
89| `map<S, T>` | Associated array maping values of type *S* to values of type *T*. *S* may be a `string`, `enum`, or numeric type.
90| `handle` | Generic Mojo handle. May be any type of handle, including a wrapped native platform handle.
91| `handle<message_pipe>` | Generic message pipe handle.
92| `handle<shared_buffer>` | Shared buffer handle.
93| `handle<data_pipe_producer>` | Data pipe producer handle.
94| `handle<data_pipe_consumer>` | Data pipe consumer handle.
95| *`InterfaceType`* | Any user-defined Mojom interface type. This is sugar for a strongly-typed message pipe handle which should eventually be used to make outgoing calls on the interface.
96| *`InterfaceType&`* | An interface request for any user-defined Mojom interface type. This is sugar for a more strongly-typed message pipe handle which is expected to receive request messages and should therefore eventually be bound to an implementation of the interface.
97| *`associated InterfaceType`* | An associated interface handle. See [Associated Interfaces](#Associated-Interfaces)
98| *`associated InterfaceType&`* | An associated interface request. See [Associated Interfaces](#Associated-Interfaces)
99| *T*? | An optional (nullable) value. Primitive numeric types (integers, floats, booleans, and enums) are not nullable. All other types are nullable.
100
101### Modules
102
103Every Mojom file may optionally specify a single **module** to which it belongs.
104
105This is used strictly for aggregaging all defined symbols therein within a
106common Mojom namespace. The specific impact this has on generated binidngs code
107varies for each target language. For example, if the following Mojom is used to
108generate bindings:
109
110```
111module business.stuff;
112
113interface MoneyGenerator {
114 GenerateMoney();
115};
116```
117
118Generated C++ bindings will define a class interface `MoneyGenerator` in the
119`business::stuff` namespace, while Java bindings will define an interface
120`MoneyGenerator` in the `org.chromium.business.stuff` package. JavaScript
121bindings at this time are unaffected by module declarations.
122
123**NOTE:** By convention in the Chromium codebase, **all** Mojom files should
124declare a module name with at least (and preferrably exactly) one top-level name
125as well as an inner `mojom` module suffix. *e.g.*, `chrome.mojom`,
126`business.mojom`, *etc.*
127
128This convention makes it easy to tell which symbols are generated by Mojom when
129reading non-Mojom code, and it also avoids namespace collisions in the fairly
130common scenario where you have a real C++ or Java `Foo` along with a
131corresponding Mojom `Foo` for its serialized representation.
132
133### Imports
134
135If your Mojom references definitions from other Mojom files, you must **import**
136those files. Import syntax is as follows:
137
138```
139import "services/widget/public/interfaces/frobinator.mojom";
140```
141
142Import paths are always relative to the top-level directory.
143
144Note that circular imports are **not** supported.
145
146### Structs
147
148Structs are defined using the **struct** keyword, and they provide a way to
149group related fields together:
150
151``` cpp
152struct StringPair {
153 string first;
154 string second;
155};
156```
157
158Struct fields may be comprised of any of the types listed above in the
159[Primitive Types](#Primitive-Types) section.
160
161Default values may be specified as long as they are constant:
162
163``` cpp
164struct Request {
165 int32 id = -1;
166 string details;
167};
168```
169
170What follows is a fairly
171comprehensive example using the supported field types:
172
173``` cpp
174struct StringPair {
175 string first;
176 string second;
177};
178
179enum AnEnum {
180 YES,
181 NO
182};
183
184interface SampleInterface {
185 DoStuff();
186};
187
188struct AllTheThings {
189 // Note that these types can never be marked nullable!
190 bool boolean_value;
191 int8 signed_8bit_value = 42;
192 uint8 unsigned_8bit_value;
193 int16 signed_16bit_value;
194 uint16 unsigned_16bit_value;
195 int32 signed_32bit_value;
196 uint32 unsigned_32bit_value;
197 int64 signed_64bit_value;
198 uint64 unsigned_64bit_value;
199 float float_value_32bit;
200 double float_value_64bit;
201 AnEnum enum_value = AnEnum.YES;
202
203 // Strings may be nullable.
204 string? maybe_a_string_maybe_not;
205
206 // Structs may contain other structs. These may also be nullable.
207 StringPair some_strings;
208 StringPair? maybe_some_more_strings;
209
210 // In fact structs can also be nested, though in practice you must always make
211 // such fields nullable -- otherwise messages would need to be infinitely long
212 // in order to pass validation!
213 AllTheThings? more_things;
214
215 // Arrays may be templated over any Mojom type, and are always nullable:
216 array<int32> numbers;
217 array<int32>? maybe_more_numbers;
218
219 // Arrays of arrays of arrays... are fine.
220 array<array<array<AnEnum>>> this_works_but_really_plz_stop;
221
222 // The element type may be nullable if it's a type which is allowed to be
223 // nullable.
224 array<AllTheThings?> more_maybe_things;
225
226 // Fixed-size arrays get some extra validation on the receiving end to ensure
227 // that the correct number of elements is always received.
228 array<uint64, 2> uuid;
229
230 // Maps follow many of the same rules as arrays. Key types may be any
231 // non-handle, non-collection type, and value types may be any supported
232 // struct field type. Maps may also be nullable.
233 map<string, int32> one_map;
234 map<AnEnum, string>? maybe_another_map;
235 map<StringPair, AllTheThings?>? maybe_a_pretty_weird_but_valid_map;
236 map<StringPair, map<int32, array<map<string, string>?>?>?> ridiculous;
237
238 // And finally, all handle types are valid as struct fields and may be
239 // nullable. Note that interfaces and interface requests (the "Foo" and
240 // "Foo&" type syntax respectively) are just strongly-typed message pipe
241 // handles.
242 handle generic_handle;
243 handle<data_pipe_consumer> reader;
244 handle<data_pipe_producer>? maybe_writer;
245 handle<shared_buffer> dumping_ground;
246 handle<message_pipe> raw_message_pipe;
247 SampleInterface? maybe_a_sample_interface_client_pipe;
248 SampleInterface& non_nullable_sample_interface_request;
249 SampleInterface&? nullable_sample_interface_request;
250 associated SampleInterface associated_interface_client;
251 associated SampleInterface& associated_interface_request;
252 associated SampleInterface&? maybe_another_associated_request;
253};
254```
255
256For details on how all of these different types translate to usable generated
257code, see
258[documentation for individual target languages](#Generated-Code-For-Target-Languages).
259
260### Unions
261
262Mojom supports tagged unions using the **union** keyword. A union is a
263collection of fields which may taken the value of any single one of those fields
264at a time. Thus they provide a way to represent a variant value type while
265minimizing storage requirements.
266
267Union fields may be of any type supported by [struct](#Structs) fields. For
268example:
269
270```cpp
271union ExampleUnion {
272 string str;
273 StringPair pair;
274 int64 id;
275 array<uint64, 2> guid;
276 SampleInterface iface;
277};
278```
279
280For details on how unions like this translate to generated bindings code, see
281[documentation for individual target languages](#Generated-Code-For-Target-Languages).
282
283### Enumeration Types
284
285Enumeration types may be defined using the **enum** keyword either directly
286within a module or within the namespace of some struct or interface:
287
288```
289module business.mojom;
290
291enum Department {
292 SALES = 0,
293 DEV,
294};
295
296struct Employee {
297 enum Type {
298 FULL_TIME,
299 PART_TIME,
300 };
301
302 Type type;
303 // ...
304};
305```
306
307That that similar to C-style enums, individual values may be explicitly assigned
308within an enum definition. By default values are based at zero and incremenet by
3091 sequentially.
310
311The effect of nested definitions on generated bindings varies depending on the
312target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages)
313
314### Constants
315
316Constants may be defined using the **const** keyword either directly within a
317module or within the namespace of some struct or interface:
318
319```
320module business.mojom;
321
322const string kServiceName = "business";
323
324struct Employee {
325 const uint64 kInvalidId = 0;
326
327 enum Type {
328 FULL_TIME,
329 PART_TIME,
330 };
331
332 uint64 id = kInvalidId;
333 Type type;
334};
335```
336
337The effect of nested definitions on generated bindings varies depending on the
338target language. See [documentation for individual target languages](#Generated-Code-For-Target-Languages)
339
340### Interfaces
341
342An **interface** is a logical bundle of parameterized request messages. Each
343request message may optionally define a parameterized response message. Here's
344syntax to define an interface `Foo` with various kinds of requests:
345
346```
347interface Foo {
348 // A request which takes no arguments and expects no response.
349 MyMessage();
350
351 // A request which has some arguments and expects no response.
352 MyOtherMessage(string name, array<uint8> bytes);
353
354 // A request which expects a single-argument response.
355 MyMessageWithResponse(string command) => (bool success);
356
357 // A request which expects a response with multiple arguments.
358 MyMessageWithMoarResponse(string a, string b) => (int8 c, int8 d);
359};
360```
361
362Anything which is a valid struct field type (see [Structs](#Structs)) is also a
363valid request or response argument type. The type notation is the same for both.
364
365### Attributes
366
367Mojom definitions may have their meaning altered by **attributes**, specified
368with a syntax similar to Java or C# attributes. There are a handle of
369interesting attributes supported today.
370
371**`[Sync]`**
372: The `Sync` attribute may be specified for any interface method which expects
373 a response. This makes it so that callers of the method can wait
374 synchronously for a response. See
375 [Synchronous Calls](/mojo/public/cpp/bindings/README.md#Synchronous-Calls)
376 in the C++ bindings documentation. Note that sync calls are not currently
377 supported in other target languages.
378
379**`[Extensible]`**
380: The `Extensible` attribute may be specified for any enum definition. This
381 essentially disables builtin range validation when receiving values of the
382 enum type in a message, allowing older bindings to tolerate unrecognized
383 values from newer versions of the enum.
384
385**`[Native]`**
386: The `Native` attribute may be specified for an empty struct declaration to
387 provide a nominal bridge between Mojo IPC and legacy `IPC::ParamTraits` or
388 `IPC_STRUCT_TRAITS*` macros.
389 See [Using Legacy IPC Traits](/ipc/README.md#Using-Legacy-IPC-Traits) for
390 more details. Note support for this attribute is strictly limited to C++
391 bindings generation.
392
393**`[MinVersion=N]`**
394: The `MinVersion` attribute is used to specify the version at which a given
395 field, enum value, interface method, or method parameter was introduced.
396 See [Versioning](#Versioning) for more details.
397
398**`[Uuid=<UUID>]`**
399: Specifies a UUID to be associated with a given interface. The UUID is
400 intended to remain stable across all changes to the interface definition,
401 including name changes. The value given for this attribute should be a
402 standard UUID string representation as specified by RFC 4122. New UUIDs can
403 be generated with common tools such as `uuidgen`.
404
405**`[EnableIf=value]`**
406: The `EnableIf` attribute is used to conditionally enable definitions when
407 the mojom is parsed. If the `mojom` target in the GN file does not include
408 the matching `value` in the list of `enabled_features`, the definition
409 will be disabled. This is useful for mojom definitions that only make
410 sense on one platform. Note that the `EnableIf` attribute can only be set
411 once per definition.
412
413## Generated Code For Target Languages
414
415When the bindings generator successfully processes an input Mojom file, it emits
416corresponding code for each supported target language. For more details on how
417Mojom concepts translate to a given target langauge, please refer to the
418bindings API documentation for that language:
419
420* [C++ Bindings](/mojo/public/cpp/bindings/README.md)
421* [JavaScript Bindings](/mojo/public/js/README.md)
422* [Java Bindings](/mojo/public/java/bindings/README.md)
423
424## Message Validation
425
426Regardless of target language, all interface messages are validated during
427deserialization before they are dispatched to a receiving implementation of the
428interface. This helps to ensure consitent validation across interfaces without
429leaving the burden to developers and security reviewers every time a new message
430is added.
431
432If a message fails validation, it is never dispatched. Instead a **connection
433error** is raised on the binding object (see
434[C++ Connection Errors](/mojo/public/cpp/bindings/README.md#Connection-Errors),
435[Java Connection Errors](/mojo/public/java/bindings/README.md#Connection-Errors),
436or
437[JavaScript Connection Errors](/mojo/public/js/README.md#Connection-Errors) for
438details.)
439
440Some baseline level of validation is done automatically for primitive Mojom
441types.
442
443### Non-Nullable Objects
444
445Mojom fields or parameter values (*e.g.*, structs, interfaces, arrays, *etc.*)
446may be marked nullable in Mojom definitions (see
447[Primitive Types](#Primitive-Types).) If a field or parameter is **not** marked
448nullable but a message is received with a null value in its place, that message
449will fail validation.
450
451### Enums
452
453Enums declared in Mojom are automatically validated against the range of legal
454values. For example if a Mojom declares the enum:
455
456``` cpp
457enum AdvancedBoolean {
458 TRUE = 0,
459 FALSE = 1,
460 FILE_NOT_FOUND = 2,
461};
462```
463
464and a message is received with the integral value 3 (or anything other than 0,
4651, or 2) in place of some `AdvancedBoolean` field or parameter, the message will
466fail validation.
467
468*** note
469NOTE: It's possible to avoid this type of validation error by explicitly marking
470an enum as [Extensible](#Attributes) if you anticipate your enum being exchanged
471between two different versions of the binding interface. See
472[Versioning](#Versioning).
473***
474
475### Other failures
476
477There are a host of internal validation errors that may occur when a malformed
478message is received, but developers should not be concerned with these
479specifically; in general they can only result from internal bindings bugs,
480compromised processes, or some remote endpoint making a dubious effort to
481manually encode their own bindings messages.
482
483### Custom Validation
484
485It's also possible for developers to define custom validation logic for specific
486Mojom struct types by exploiting the
487[type mapping](/mojo/public/cpp/bindings/README.md#Type-Mapping) system for C++
488bindings. Messages rejected by custom validation logic trigger the same
489validation failure behavior as the built-in type validation routines.
490
491## Associated Interfaces
492
493As mentioned in the [Primitive Types](#Primitive-Types) section above, interface
494and interface request fields and parameters may be marked as `associated`. This
495essentially means that they are piggy-backed on some other interface's message
496pipe.
497
498Because individual interface message pipes operate independently there can be no
499relative ordering guarantees among them. Associated interfaces are useful when
500one interface needs to guarantee strict FIFO ordering with respect to one or
501more other interfaces, as they allow interfaces to share a single pipe.
502
503Currenly associated interfaces are only supported in generated C++ bindings.
504See the documentation for
505[C++ Associated Interfaces](/mojo/public/cpp/bindings/README.md#Associated-Interfaces).
506
507## Versioning
508
509### Overview
510
511*** note
512**NOTE:** You don't need to worry about versioning if you don't care about
513backwards compatibility. Specifically, all parts of Chrome are updated
514atomically today and there is not yet any possibility of any two Chrome
515processes communicating with two different versions of any given Mojom
516interface.
517***
518
519Services extend their interfaces to support new features over time, and clients
520want to use those new features when they are available. If services and clients
521are not updated at the same time, it's important for them to be able to
522communicate with each other using different snapshots (versions) of their
523interfaces.
524
525This document shows how to extend Mojom interfaces in a backwards-compatible
526way. Changing interfaces in a non-backwards-compatible way is not discussed,
527because in that case communication between different interface versions is
528impossible anyway.
529
530### Versioned Structs
531
532You can use the `MinVersion` [attribute](#Attributes) to indicate from which
533version a struct field is introduced. Assume you have the following struct:
534
535``` cpp
536struct Employee {
537 uint64 employee_id;
538 string name;
539};
540```
541
542and you would like to add a birthday field. You can do:
543
544``` cpp
545struct Employee {
546 uint64 employee_id;
547 string name;
548 [MinVersion=1] Date? birthday;
549};
550```
551
552By default, fields belong to version 0. New fields must be appended to the
553struct definition (*i.e*., existing fields must not change **ordinal value**)
554with the `MinVersion` attribute set to a number greater than any previous
555existing versions.
556
557**Ordinal value** refers to the relative positional layout of a struct's fields
558(and an interface's methods) when encoded in a message. Implicitly, ordinal
559numbers are assigned to fields according to lexical position. In the example
560above, `employee_id` has an ordinal value of 0 and `name` has an ordinal value
561of 1.
562
563Ordinal values can be specified explicitly using `**@**` notation, subject to
564the following hard constraints:
565
566* For any given struct or interface, if any field or method explicitly specifies
567 an ordinal value, all fields or methods must explicitly specify an ordinal
568 value.
569* For an *N*-field struct or *N*-method interface, the set of explicitly
570 assigned ordinal values must be limited to the range *[0, N-1]*.
571
572You may reorder fields, but you must ensure that the ordinal values of existing
573fields remain unchanged. For example, the following struct remains
574backwards-compatible:
575
576``` cpp
577struct Employee {
578 uint64 employee_id@0;
579 [MinVersion=1] Date? birthday@2;
580 string name@1;
581};
582```
583
584*** note
585**NOTE:** Newly added fields of Mojo object or handle types MUST be nullable.
586See [Primitive Types](#Primitive-Types).
587***
588
589### Versioned Interfaces
590
591There are two dimensions on which an interface can be extended
592
593**Appending New Parameters To Existing Methods**
594: Parameter lists are treated as structs internally, so all the rules of
595 versioned structs apply to method parameter lists. The only difference is
596 that the version number is scoped to the whole interface rather than to any
597 individual parameter list.
598
599 Please note that adding a response to a message which did not previously
600 expect a response is a not a backwards-compatible change.
601
602**Appending New Methods**
603: Similarly, you can reorder methods with explicit ordinal values as long as
604 the ordinal values of existing methods are unchanged.
605
606For example:
607
608``` cpp
609// Old version:
610interface HumanResourceDatabase {
611 AddEmployee(Employee employee) => (bool success);
612 QueryEmployee(uint64 id) => (Employee? employee);
613};
614
615// New version:
616interface HumanResourceDatabase {
617 AddEmployee(Employee employee) => (bool success);
618
619 QueryEmployee(uint64 id, [MinVersion=1] bool retrieve_finger_print)
620 => (Employee? employee,
621 [MinVersion=1] array<uint8>? finger_print);
622
623 [MinVersion=1]
624 AttachFingerPrint(uint64 id, array<uint8> finger_print)
625 => (bool success);
626};
627```
628
629Similar to [versioned structs](#Versioned-Structs), when you pass the parameter
630list of a request or response method to a destination using an older version of
631an interface, unrecognized fields are silently discarded. However, if the method
632call itself is not recognized, it is considered a validation error and the
633receiver will close its end of the interface pipe. For example, if a client on
634version 1 of the above interface sends an `AttachFingerPrint` request to an
635implementation of version 0, the client will be disconnected.
636
637Bindings target languages that support versioning expose means to query or
638assert the remote version from a client handle (*e.g.*, an
639`InterfacePtr<T>` in C++ bindings.)
640
641See
642[C++ Versioning Considerations](/mojo/public/cpp/bindings/README.md#Versioning-Considerations)
643and
644[Java Versioning Considerations](/mojo/public/java/bindings/README.md#Versioning-Considerations)
645
646### Versioned Enums
647
648**By default, enums are non-extensible**, which means that generated message
649validation code does not expect to see new values in the future. When an unknown
650value is seen for a non-extensible enum field or parameter, a validation error
651is raised.
652
653If you want an enum to be extensible in the future, you can apply the
654`[Extensible]` [attribute](#Attributes):
655
656``` cpp
657[Extensible]
658enum Department {
659 SALES,
660 DEV,
661};
662```
663
664And later you can extend this enum without breaking backwards compatibility:
665
666``` cpp
667[Extensible]
668enum Department {
669 SALES,
670 DEV,
671 [MinVersion=1] RESEARCH,
672};
673```
674
675*** note
676**NOTE:** For versioned enum definitions, the use of a `[MinVersion]` attribute
677is strictly for documentation purposes. It has no impact on the generated code.
678***
679
680With extensible enums, bound interface implementations may receive unknown enum
681values and will need to deal with them gracefully. See
682[C++ Versioning Considerations](/mojo/public/cpp/bindings/README.md#Versioning-Considerations)
683for details.
684
685## Grammar Reference
686
687Below is the (BNF-ish) context-free grammar of the Mojom language:
688
689```
690MojomFile = StatementList
691StatementList = Statement StatementList | Statement
692Statement = ModuleStatement | ImportStatement | Definition
693
694ModuleStatement = AttributeSection "module" Identifier ";"
695ImportStatement = "import" StringLiteral ";"
696Definition = Struct Union Interface Enum Const
697
698AttributeSection = "[" AttributeList "]"
699AttributeList = <empty> | NonEmptyAttributeList
700NonEmptyAttributeList = Attribute
701 | Attribute "," NonEmptyAttributeList
702Attribute = Name
703 | Name "=" Name
704 | Name "=" Literal
705
706Struct = AttributeSection "struct" Name "{" StructBody "}" ";"
707 | AttributeSection "struct" Name ";"
708StructBody = <empty>
709 | StructBody Const
710 | StructBody Enum
711 | StructBody StructField
712StructField = AttributeSection TypeSpec Name Orginal Default ";"
713
714Union = AttributeSection "union" Name "{" UnionBody "}" ";"
715UnionBody = <empty> | UnionBody UnionField
716UnionField = AttributeSection TypeSpec Name Ordinal ";"
717
718Interface = AttributeSection "interface" Name "{" InterfaceBody "}" ";"
719InterfaceBody = <empty>
720 | InterfaceBody Const
721 | InterfaceBody Enum
722 | InterfaceBody Method
723Method = AttributeSection Name Ordinal "(" ParamterList ")" Response ";"
724ParameterList = <empty> | NonEmptyParameterList
725NonEmptyParameterList = Parameter
726 | Parameter "," NonEmptyParameterList
727Parameter = AttributeSection TypeSpec Name Ordinal
728Response = <empty> | "=>" "(" ParameterList ")"
729
730TypeSpec = TypeName "?" | TypeName
731TypeName = BasicTypeName
732 | Array
733 | FixedArray
734 | Map
735 | InterfaceRequest
736BasicTypeName = Identifier | "associated" Identifier | HandleType | NumericType
737NumericType = "bool" | "int8" | "uint8" | "int16" | "uint16" | "int32"
738 | "uint32" | "int64" | "uint64" | "float" | "double"
739HandleType = "handle" | "handle" "<" SpecificHandleType ">"
740SpecificHandleType = "message_pipe"
741 | "shared_buffer"
742 | "data_pipe_consumer"
743 | "data_pipe_producer"
744Array = "array" "<" TypeSpec ">"
745FixedArray = "array" "<" TypeSpec "," IntConstDec ">"
746Map = "map" "<" Identifier "," TypeSpec ">"
747InterfaceRequest = Identifier "&" | "associated" Identifier "&"
748
749Ordinal = <empty> | OrdinalValue
750
751Default = <empty> | "=" Constant
752
753Enum = AttributeSection "enum" Name "{" NonEmptyEnumValueList "}" ";"
754 | AttributeSection "enum" Name "{" NonEmptyEnumValueList "," "}" ";"
755NonEmptyEnumValueList = EnumValue | NonEmptyEnumValueList "," EnumValue
756EnumValue = AttributeSection Name
757 | AttributeSection Name "=" Integer
758 | AttributeSection Name "=" Identifier
759
760Const = "const" TypeSpec Name "=" Constant ";"
761
762Constant = Literal | Identifier ";"
763
764Identifier = Name | Name "." Identifier
765
766Literal = Integer | Float | "true" | "false" | "default" | StringLiteral
767
768Integer = IntConst | "+" IntConst | "-" IntConst
769IntConst = IntConstDec | IntConstHex
770
771Float = FloatConst | "+" FloatConst | "-" FloatConst
772
773; The rules below are for tokens matched strictly according to the given regexes
774
775Identifier = /[a-zA-Z_][0-9a-zA-Z_]*/
776IntConstDec = /0|(1-9[0-9]*)/
777IntConstHex = /0[xX][0-9a-fA-F]+/
778OrdinalValue = /@(0|(1-9[0-9]*))/
779FloatConst = ... # Imagine it's close enough to C-style float syntax.
780StringLiteral = ... # Imagine it's close enough to C-style string literals, including escapes.
781```
782
783## Additional Documentation
784
785[Mojom Message Format](https://docs.google.com/document/d/13pv9cFh5YKuBggDBQ1-AL8VReF-IYpFOFpRfvWFrwio/edit)
786: Describes the wire format used by Mojo bindings interfaces over message
787 pipes.
788
789[Input Format of Mojom Message Validation Tests](https://docs.google.com/document/d/1-y-2IYctyX2NPaLxJjpJfzVNWCC2SR2MJAD9MpIytHQ/edit)
790: Describes a text format used to facilitate bindings message validation
791 tests.
792