def BuildTestModule(): module = mojom.Module('test', 'testspace') struct = module.AddStruct('teststruct') struct.AddField('testfield1', mojom.INT32) struct.AddField('testfield2', mojom.Array(mojom.INT32), 42) interface = module.AddInterface('Server') method = interface.AddMethod('Foo', 42) method.AddParameter('foo', mojom.INT32) method.AddParameter('bar', mojom.Array(struct)) return module
def ModuleFromData(data): kinds = {} for kind in mojom.PRIMITIVES: kinds[kind.spec] = kind module = mojom.Module() module.name = data['name'] module.namespace = data['namespace'] module.structs = map(lambda struct: StructFromData(kinds, struct), data['structs']) module.interfaces = map( lambda interface: InterfaceFromData(kinds, interface), data['interfaces']) return module
def ModuleFromData(data): module = mojom.Module() module.kinds = {} for kind in mojom.PRIMITIVES: module.kinds[kind.spec] = kind module.constants = {} module.name = data['name'] module.namespace = data['namespace'] # Imports must come first, because they add to module.kinds which is used # by by the others. module.imports = map( lambda import_data: ImportFromData(module, import_data), data['imports']) module.enums = map(lambda enum: EnumFromData(module, enum, None), data['enums']) module.structs = map(lambda struct: StructFromData(module, struct), data['structs']) module.interfaces = map( lambda interface: InterfaceFromData(module, interface), data['interfaces']) return module