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**`[EnableIf=value]`** 399: The `EnableIf` attribute is used to conditionally enable definitions when 400 the mojom is parsed. If the `mojom` target in the GN file does not include 401 the matching `value` in the list of `enabled_features`, the definition 402 will be disabled. This is useful for mojom definitions that only make 403 sense on one platform. Note that the `EnableIf` attribute can only be set 404 once per definition. 405 406## Generated Code For Target Languages 407 408When the bindings generator successfully processes an input Mojom file, it emits 409corresponding code for each supported target language. For more details on how 410Mojom concepts translate to a given target langauge, please refer to the 411bindings API documentation for that language: 412 413* [C++ Bindings](/mojo/public/cpp/bindings/README.md) 414* [JavaScript Bindings](/mojo/public/js/README.md) 415* [Java Bindings](/mojo/public/java/bindings/README.md) 416 417## Message Validation 418 419Regardless of target language, all interface messages are validated during 420deserialization before they are dispatched to a receiving implementation of the 421interface. This helps to ensure consitent validation across interfaces without 422leaving the burden to developers and security reviewers every time a new message 423is added. 424 425If a message fails validation, it is never dispatched. Instead a **connection 426error** is raised on the binding object (see 427[C++ Connection Errors](/mojo/public/cpp/bindings/README.md#Connection-Errors), 428[Java Connection Errors](/mojo/public/java/bindings/README.md#Connection-Errors), 429or 430[JavaScript Connection Errors](/mojo/public/js/README.md#Connection-Errors) for 431details.) 432 433Some baseline level of validation is done automatically for primitive Mojom 434types. 435 436### Non-Nullable Objects 437 438Mojom fields or parameter values (*e.g.*, structs, interfaces, arrays, *etc.*) 439may be marked nullable in Mojom definitions (see 440[Primitive Types](#Primitive-Types).) If a field or parameter is **not** marked 441nullable but a message is received with a null value in its place, that message 442will fail validation. 443 444### Enums 445 446Enums declared in Mojom are automatically validated against the range of legal 447values. For example if a Mojom declares the enum: 448 449``` cpp 450enum AdvancedBoolean { 451 TRUE = 0, 452 FALSE = 1, 453 FILE_NOT_FOUND = 2, 454}; 455``` 456 457and a message is received with the integral value 3 (or anything other than 0, 4581, or 2) in place of some `AdvancedBoolean` field or parameter, the message will 459fail validation. 460 461*** note 462NOTE: It's possible to avoid this type of validation error by explicitly marking 463an enum as [Extensible](#Attributes) if you anticipate your enum being exchanged 464between two different versions of the binding interface. See 465[Versioning](#Versioning). 466*** 467 468### Other failures 469 470There are a host of internal validation errors that may occur when a malformed 471message is received, but developers should not be concerned with these 472specifically; in general they can only result from internal bindings bugs, 473compromised processes, or some remote endpoint making a dubious effort to 474manually encode their own bindings messages. 475 476### Custom Validation 477 478It's also possible for developers to define custom validation logic for specific 479Mojom struct types by exploiting the 480[type mapping](/mojo/public/cpp/bindings/README.md#Type-Mapping) system for C++ 481bindings. Messages rejected by custom validation logic trigger the same 482validation failure behavior as the built-in type validation routines. 483 484## Associated Interfaces 485 486As mentioned in the [Primitive Types](#Primitive-Types) section above, interface 487and interface request fields and parameters may be marked as `associated`. This 488essentially means that they are piggy-backed on some other interface's message 489pipe. 490 491Because individual interface message pipes operate independently there can be no 492relative ordering guarantees among them. Associated interfaces are useful when 493one interface needs to guarantee strict FIFO ordering with respect to one or 494more other interfaces, as they allow interfaces to share a single pipe. 495 496Currenly associated interfaces are only supported in generated C++ bindings. 497See the documentation for 498[C++ Associated Interfaces](/mojo/public/cpp/bindings/README.md#Associated-Interfaces). 499 500## Versioning 501 502### Overview 503 504*** note 505**NOTE:** You don't need to worry about versioning if you don't care about 506backwards compatibility. Specifically, all parts of Chrome are updated 507atomically today and there is not yet any possibility of any two Chrome 508processes communicating with two different versions of any given Mojom 509interface. 510*** 511 512Services extend their interfaces to support new features over time, and clients 513want to use those new features when they are available. If services and clients 514are not updated at the same time, it's important for them to be able to 515communicate with each other using different snapshots (versions) of their 516interfaces. 517 518This document shows how to extend Mojom interfaces in a backwards-compatible 519way. Changing interfaces in a non-backwards-compatible way is not discussed, 520because in that case communication between different interface versions is 521impossible anyway. 522 523### Versioned Structs 524 525You can use the `MinVersion` [attribute](#Attributes) to indicate from which 526version a struct field is introduced. Assume you have the following struct: 527 528``` cpp 529struct Employee { 530 uint64 employee_id; 531 string name; 532}; 533``` 534 535and you would like to add a birthday field. You can do: 536 537``` cpp 538struct Employee { 539 uint64 employee_id; 540 string name; 541 [MinVersion=1] Date? birthday; 542}; 543``` 544 545By default, fields belong to version 0. New fields must be appended to the 546struct definition (*i.e*., existing fields must not change **ordinal value**) 547with the `MinVersion` attribute set to a number greater than any previous 548existing versions. 549 550**Ordinal value** refers to the relative positional layout of a struct's fields 551(and an interface's methods) when encoded in a message. Implicitly, ordinal 552numbers are assigned to fields according to lexical position. In the example 553above, `employee_id` has an ordinal value of 0 and `name` has an ordinal value 554of 1. 555 556Ordinal values can be specified explicitly using `**@**` notation, subject to 557the following hard constraints: 558 559* For any given struct or interface, if any field or method explicitly specifies 560 an ordinal value, all fields or methods must explicitly specify an ordinal 561 value. 562* For an *N*-field struct or *N*-method interface, the set of explicitly 563 assigned ordinal values must be limited to the range *[0, N-1]*. 564 565You may reorder fields, but you must ensure that the ordinal values of existing 566fields remain unchanged. For example, the following struct remains 567backwards-compatible: 568 569``` cpp 570struct Employee { 571 uint64 employee_id@0; 572 [MinVersion=1] Date? birthday@2; 573 string name@1; 574}; 575``` 576 577*** note 578**NOTE:** Newly added fields of Mojo object or handle types MUST be nullable. 579See [Primitive Types](#Primitive-Types). 580*** 581 582### Versioned Interfaces 583 584There are two dimensions on which an interface can be extended 585 586**Appending New Parameters To Existing Methods** 587: Parameter lists are treated as structs internally, so all the rules of 588 versioned structs apply to method parameter lists. The only difference is 589 that the version number is scoped to the whole interface rather than to any 590 individual parameter list. 591 592 Please note that adding a response to a message which did not previously 593 expect a response is a not a backwards-compatible change. 594 595**Appending New Methods** 596: Similarly, you can reorder methods with explicit ordinal values as long as 597 the ordinal values of existing methods are unchanged. 598 599For example: 600 601``` cpp 602// Old version: 603interface HumanResourceDatabase { 604 AddEmployee(Employee employee) => (bool success); 605 QueryEmployee(uint64 id) => (Employee? employee); 606}; 607 608// New version: 609interface HumanResourceDatabase { 610 AddEmployee(Employee employee) => (bool success); 611 612 QueryEmployee(uint64 id, [MinVersion=1] bool retrieve_finger_print) 613 => (Employee? employee, 614 [MinVersion=1] array<uint8>? finger_print); 615 616 [MinVersion=1] 617 AttachFingerPrint(uint64 id, array<uint8> finger_print) 618 => (bool success); 619}; 620``` 621 622Similar to [versioned structs](#Versioned-Structs), when you pass the parameter 623list of a request or response method to a destination using an older version of 624an interface, unrecognized fields are silently discarded. However, if the method 625call itself is not recognized, it is considered a validation error and the 626receiver will close its end of the interface pipe. For example, if a client on 627version 1 of the above interface sends an `AttachFingerPrint` request to an 628implementation of version 0, the client will be disconnected. 629 630Bindings target languages that support versioning expose means to query or 631assert the remote version from a client handle (*e.g.*, an 632`InterfacePtr<T>` in C++ bindings.) 633 634See 635[C++ Versioning Considerations](/mojo/public/cpp/bindings/README.md#Versioning-Considerations) 636and 637[Java Versioning Considerations](/mojo/public/java/bindings/README.md#Versioning-Considerations) 638 639### Versioned Enums 640 641**By default, enums are non-extensible**, which means that generated message 642validation code does not expect to see new values in the future. When an unknown 643value is seen for a non-extensible enum field or parameter, a validation error 644is raised. 645 646If you want an enum to be extensible in the future, you can apply the 647`[Extensible]` [attribute](#Attributes): 648 649``` cpp 650[Extensible] 651enum Department { 652 SALES, 653 DEV, 654}; 655``` 656 657And later you can extend this enum without breaking backwards compatibility: 658 659``` cpp 660[Extensible] 661enum Department { 662 SALES, 663 DEV, 664 [MinVersion=1] RESEARCH, 665}; 666``` 667 668*** note 669**NOTE:** For versioned enum definitions, the use of a `[MinVersion]` attribute 670is strictly for documentation purposes. It has no impact on the generated code. 671*** 672 673With extensible enums, bound interface implementations may receive unknown enum 674values and will need to deal with them gracefully. See 675[C++ Versioning Considerations](/mojo/public/cpp/bindings/README.md#Versioning-Considerations) 676for details. 677 678## Grammar Reference 679 680Below is the (BNF-ish) context-free grammar of the Mojom language: 681 682``` 683MojomFile = StatementList 684StatementList = Statement StatementList | Statement 685Statement = ModuleStatement | ImportStatement | Definition 686 687ModuleStatement = AttributeSection "module" Identifier ";" 688ImportStatement = "import" StringLiteral ";" 689Definition = Struct Union Interface Enum Const 690 691AttributeSection = "[" AttributeList "]" 692AttributeList = <empty> | NonEmptyAttributeList 693NonEmptyAttributeList = Attribute 694 | Attribute "," NonEmptyAttributeList 695Attribute = Name 696 | Name "=" Name 697 | Name "=" Literal 698 699Struct = AttributeSection "struct" Name "{" StructBody "}" ";" 700 | AttributeSection "struct" Name ";" 701StructBody = <empty> 702 | StructBody Const 703 | StructBody Enum 704 | StructBody StructField 705StructField = AttributeSection TypeSpec Name Orginal Default ";" 706 707Union = AttributeSection "union" Name "{" UnionBody "}" ";" 708UnionBody = <empty> | UnionBody UnionField 709UnionField = AttributeSection TypeSpec Name Ordinal ";" 710 711Interface = AttributeSection "interface" Name "{" InterfaceBody "}" ";" 712InterfaceBody = <empty> 713 | InterfaceBody Const 714 | InterfaceBody Enum 715 | InterfaceBody Method 716Method = AttributeSection Name Ordinal "(" ParamterList ")" Response ";" 717ParameterList = <empty> | NonEmptyParameterList 718NonEmptyParameterList = Parameter 719 | Parameter "," NonEmptyParameterList 720Parameter = AttributeSection TypeSpec Name Ordinal 721Response = <empty> | "=>" "(" ParameterList ")" 722 723TypeSpec = TypeName "?" | TypeName 724TypeName = BasicTypeName 725 | Array 726 | FixedArray 727 | Map 728 | InterfaceRequest 729BasicTypeName = Identifier | "associated" Identifier | HandleType | NumericType 730NumericType = "bool" | "int8" | "uint8" | "int16" | "uint16" | "int32" 731 | "uint32" | "int64" | "uint64" | "float" | "double" 732HandleType = "handle" | "handle" "<" SpecificHandleType ">" 733SpecificHandleType = "message_pipe" 734 | "shared_buffer" 735 | "data_pipe_consumer" 736 | "data_pipe_producer" 737Array = "array" "<" TypeSpec ">" 738FixedArray = "array" "<" TypeSpec "," IntConstDec ">" 739Map = "map" "<" Identifier "," TypeSpec ">" 740InterfaceRequest = Identifier "&" | "associated" Identifier "&" 741 742Ordinal = <empty> | OrdinalValue 743 744Default = <empty> | "=" Constant 745 746Enum = AttributeSection "enum" Name "{" NonEmptyEnumValueList "}" ";" 747 | AttributeSection "enum" Name "{" NonEmptyEnumValueList "," "}" ";" 748NonEmptyEnumValueList = EnumValue | NonEmptyEnumValueList "," EnumValue 749EnumValue = AttributeSection Name 750 | AttributeSection Name "=" Integer 751 | AttributeSection Name "=" Identifier 752 753Const = "const" TypeSpec Name "=" Constant ";" 754 755Constant = Literal | Identifier ";" 756 757Identifier = Name | Name "." Identifier 758 759Literal = Integer | Float | "true" | "false" | "default" | StringLiteral 760 761Integer = IntConst | "+" IntConst | "-" IntConst 762IntConst = IntConstDec | IntConstHex 763 764Float = FloatConst | "+" FloatConst | "-" FloatConst 765 766; The rules below are for tokens matched strictly according to the given regexes 767 768Identifier = /[a-zA-Z_][0-9a-zA-Z_]*/ 769IntConstDec = /0|(1-9[0-9]*)/ 770IntConstHex = /0[xX][0-9a-fA-F]+/ 771OrdinalValue = /@(0|(1-9[0-9]*))/ 772FloatConst = ... # Imagine it's close enough to C-style float syntax. 773StringLiteral = ... # Imagine it's close enough to C-style string literals, including escapes. 774``` 775 776## Additional Documentation 777 778[Mojom Message Format](https://docs.google.com/document/d/13pv9cFh5YKuBggDBQ1-AL8VReF-IYpFOFpRfvWFrwio/edit) 779: Describes the wire format used by Mojo bindings interfaces over message 780 pipes. 781 782[Input Format of Mojom Message Validation Tests](https://docs.google.com/document/d/1-y-2IYctyX2NPaLxJjpJfzVNWCC2SR2MJAD9MpIytHQ/edit) 783: Describes a text format used to facilitate bindings message validation 784 tests. 785