// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
syntax = "proto2";
package mojolpm.{{module.mojom_namespace|replace("/",".")}};
{% for proto_import in proto_imports %}
import "{{proto_import}}";
{%- endfor %}
{%- set module_prefix = "%s"|format(namespaces_as_array|join(".")) %}
{%- macro optional_or_required(kind) %}
{%- if kind|is_nullable_kind %}optional
{%- else -%}required
{%- endif %}
{%- endmacro -%}
{%- for enum in enums %}
{%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %}
{%- if enum|is_native_only_kind %}
// WARNING Native only enum support {{enum_name}} is very basic.
enum {{enum.name}} {
{{enum.name}}_0 = 0;
{{enum.name}}_1 = 1;
{{enum.name}}_2 = 2;
{{enum.name}}_3 = 3;
{{enum.name}}_4 = 4;
{{enum.name}}_5 = 5;
{{enum.name}}_6 = 6;
{{enum.name}}_7 = 7;
{{enum.name}}_8 = 8;
{{enum.name}}_9 = 9;
{{enum.name}}_10 = 10;
{{enum.name}}_11 = 11;
{{enum.name}}_12 = 12;
{{enum.name}}_13 = 13;
{{enum.name}}_14 = 14;
{{enum.name}}_15 = 15;
}
{%- else %}
enum {{enum_name}} {
{%- if enum|has_duplicate_values %}
option allow_alias = true;
{%- endif %}
{%- set i = 0 %}
{%- for field in enum.fields %}
MojoLPM_{{enum.name}}_{{field.name|enum_field_name(enum)}} = {{field.numeric_value}};
{%- endfor %}
}
{%- endif %}
{%- endfor %}
{%- macro forward_declare_field_types_inner(kind, name) %}
{%- if kind|is_array_kind %}
{%- set entry_name = name ~ "Entry" -%}
{%- if (kind.kind|is_array_kind or kind.kind|is_map_kind) %}
{{forward_declare_field_types_inner(kind.kind, entry_name)}}
{%- else %}
message {{entry_name}} {
{{kind.kind|proto_field_type}} value = 1;
}
{%- endif %}
message {{name}} {
repeated {{entry_name}} values = 1;
}
{%- elif kind|is_map_kind %}
{%- set entry_name = name ~ "Entry" %}
{%- set key_name = name ~ "Key" %}
{%- set value_name = name ~ "Value" -%}
{%- if (kind.key_kind|is_array_kind or kind.key_kind|is_map_kind) -%}
{{forward_declare_field_types_inner(kind.key_kind, key_name)}}
{%- else %}
message {{key_name}} {
{{kind.key_kind|proto_field_type}} value = 1;
}
{% endif %}
{%- if (kind.value_kind|is_array_kind or kind.value_kind|is_map_kind) -%}
{{forward_declare_field_types_inner(kind.value_kind, value_name)}}
{%- else %}
message {{value_name}} {
{{kind.value_kind|proto_field_type}} value = 1;
}
{% endif %}
message {{entry_name}} {
required {{key_name}} key = 1;
required {{value_name}} value = 2;
}
message {{name}} {
repeated {{entry_name}} values = 1;
}
{%- endif %}
{% endmacro %}
{%- macro forward_declare_field_types(kind, name) %}
{%- if kind|is_array_kind %}
{%- set array_name = (name|under_to_camel) ~ "_Array" -%}
{{ forward_declare_field_types_inner(kind, array_name) }}
{%- elif kind|is_map_kind %}
{%- set map_name = (name|under_to_camel) ~ "_Map" %}
{{ forward_declare_field_types_inner(kind, map_name) }}
{%- endif %}
{% endmacro %}
{%- for struct in structs %}
{%- set struct_name = struct|get_name_for_kind(flatten_nested_kind=True) %}
{%- if struct|is_native_only_kind %}
message {{struct_name}}_ProtoStruct {
// native-only struct
required uint32 id = 1;
required bytes native_bytes = 2;
}
{%- else %}
message {{struct_name}}_ProtoStruct {
required uint32 id = 1;
{%- for pf in struct.packed.packed_fields_in_ordinal_order -%}
{%- set name = pf.field.name|camel_to_under %}
{%- set kind = pf.field.kind %}
{%- if (kind|is_array_kind or kind|is_map_kind) -%}
{{forward_declare_field_types(kind, name)}}
{%- endif %}
{%- endfor %}
{%- for pf in struct.packed.packed_fields_in_ordinal_order %}
{%- if pf|is_nullable_value_kind_packed_field %}
{%- if pf|is_primary_nullable_value_kind_packed_field %}
{%- set original_field = pf.original_field %}
{%- set kind = original_field.kind %}
{%- set name = original_field.name %}
{{kind|proto_field_type}} m_{{name}} = {{name|proto_id(kind)}};
{%- endif %}
{%- else %}
{%- set name = pf.field.name|camel_to_under %}
{%- set kind = pf.field.kind %}
{%- if kind|is_array_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Array m_{{name}} = {{name|proto_id(kind)}};
{%- elif kind|is_map_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Map m_{{name}} = {{name|proto_id(kind)}};
{%- else %}
{{kind|proto_field_type}} m_{{name}} = {{name|proto_id(kind)}};
{%- endif %}
{%- endif %}
{%- endfor %}
}
{%- endif %}
message {{struct_name}} {
{%- for enum in struct.enums %}
{%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %}
{%- if enum|is_native_only_kind %}
// WARNING Native only enum support {{enum_name}} is very basic.
enum {{enum.name}} {
{{enum.name}}_0 = 0;
{{enum.name}}_1 = 1;
{{enum.name}}_2 = 2;
{{enum.name}}_3 = 3;
{{enum.name}}_4 = 4;
{{enum.name}}_5 = 5;
{{enum.name}}_6 = 6;
{{enum.name}}_7 = 7;
{{enum.name}}_8 = 8;
{{enum.name}}_9 = 9;
{{enum.name}}_10 = 10;
{{enum.name}}_11 = 11;
{{enum.name}}_12 = 12;
{{enum.name}}_13 = 13;
{{enum.name}}_14 = 14;
{{enum.name}}_15 = 15;
}
{%- else %}
enum {{enum.name}} {
{%- if enum|has_duplicate_values %}
option allow_alias = true;
{%- endif %}
{%- set i = 0 %}
{%- for field in enum.fields %}
{{enum_name}}_{{field.name}} = {{field.numeric_value}};
{%- endfor %}
}
{%- endif %}
{%- endfor %}
oneof instance {
uint32 old = 1;
{{struct_name}}_ProtoStruct new = 2;
}
}
{%- endfor %}
{%- for union in unions %}
{%- set union_name = union|get_name_for_kind(flatten_nested_kind=True) %}
{%- if union|is_native_only_kind %}
// ERROR native-only union kind
{%- else %}
message {{union_name}}_ProtoUnion {
required uint32 id = 1;
{%- for field in union.fields %}
{%- set name = field.name|camel_to_under %}
{%- set kind = field.kind %}
{%- if (kind|is_array_kind or kind|is_map_kind) -%}
{{forward_declare_field_types(kind, name)}}
{%- endif %}
{%- endfor %}
oneof union_member {
{%- for field in union.fields %}
{%- set name = field.name|lower %}
{%- set kind = field.kind %}
{%- if kind|is_array_kind %}
{{name|under_to_camel}}_Array m_{{name}} = {{name|proto_id(kind)}};
{%- elif kind|is_map_kind %}
{{name|under_to_camel}}_Map m_{{name}} = {{name|proto_id(kind)}};
{%- else %}
{{kind|proto_field_type(quantified=False)}} m_{{name}} = {{name|proto_id(kind)}};
{%- endif %}
{%- endfor %}
}
}
message {{union_name}} {
oneof instance {
uint32 old = 1;
{{union_name}}_ProtoUnion new = 2;
}
}
{%- endif %}
{%- endfor %}
{%- for interface in interfaces %}
message {{interface.name}} {
message Reset {
}
{%- for enum in interface.enums %}
{%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %}
{%- if enum|is_native_only_kind %}
// WARNING Native only enum support {{enum_name}} is very basic.
enum {{enum.name}} {
{{enum.name}}_0 = 0;
{{enum.name}}_1 = 1;
{{enum.name}}_2 = 2;
{{enum.name}}_3 = 3;
{{enum.name}}_4 = 4;
{{enum.name}}_5 = 5;
{{enum.name}}_6 = 6;
{{enum.name}}_7 = 7;
{{enum.name}}_8 = 8;
{{enum.name}}_9 = 9;
{{enum.name}}_10 = 10;
{{enum.name}}_11 = 11;
{{enum.name}}_12 = 12;
{{enum.name}}_13 = 13;
{{enum.name}}_14 = 14;
{{enum.name}}_15 = 15;
}
{%- else %}
enum {{enum.name}} {
{%- if enum|has_duplicate_values %}
option allow_alias = true;
{%- endif %}
{%- set i = 0 %}
{%- for field in enum.fields %}
{{enum.name}}_{{field.name}} = {{field.numeric_value}};
{%- endfor %}
}
{%- endif %}
{%- endfor %}
{%- for method in interface.methods %}
message {{interface.name}}_{{method.name}} {
{%- for parameter in method.parameters %}
{%- set name = parameter.name|camel_to_under %}
{%- set kind = parameter.kind %}
{%- if (kind|is_array_kind or kind|is_map_kind) -%}
{{forward_declare_field_types(kind, name)|indent(width=2)}}
{%- endif %}
{%- endfor %}
{%- for parameter in method.parameters %}
{%- set name = parameter.name|camel_to_under %}
{%- set kind = parameter.kind %}
{%- if kind|is_array_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Array m_{{name}} = {{name|proto_id(kind)}};
{%- elif kind|is_map_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Map m_{{name}} = {{name|proto_id(kind)}};
{%- else %}
{{kind|proto_field_type}} m_{{name}} = {{name|proto_id(kind)}};
{%- endif %}
{%- endfor %}
}
message {{interface.name}}_{{method.name}}Response {
{%- if method.response_parameters %}
{%- for parameter in method.response_parameters %}
{%- set name = parameter.name|camel_to_under %}
{%- set kind = parameter.kind %}
{%- if (kind|is_array_kind or kind|is_map_kind) -%}
{{forward_declare_field_types(kind, name)|indent(width=2)}}
{%- endif %}
{%- endfor %}
{%- for parameter in method.response_parameters %}
{%- set name = parameter.name|camel_to_under %}
{%- set kind = parameter.kind %}
{%- if kind|is_array_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Array m_{{name}} = {{name|proto_id(kind)}};
{%- elif kind|is_map_kind %}
{{optional_or_required(kind)}} {{name|under_to_camel}}_Map m_{{name}} = {{name|proto_id(kind)}};
{%- else %}
{{kind|proto_field_type}} m_{{name}} = {{name|proto_id(kind)}};
{%- endif %}
{%- endfor %}
{%- endif %}
}
{%- endfor%}
{%- if interface.methods|length %}
message RemoteAction {
required uint32 id = 1;
oneof method {
Reset reset = 2;
{%- for method in interface.methods %}
{{interface.name}}_{{method.name}} m_{{method.name|camel_to_under}} = {{loop.index + 2}};
{%- endfor %}
}
}
message AssociatedRemoteAction {
required uint32 id = 1;
oneof method {
Reset reset = 2;
{%- for method in interface.methods %}
{{interface.name}}_{{method.name}} m_{{method.name|camel_to_under}} = {{loop.index + 2}};
{%- endfor %}
}
}
message ReceiverAction {
required uint32 id = 1;
oneof response {
{%- for method in interface.methods %}
{{interface.name}}_{{method.name}}Response m_{{method.name|camel_to_under}}_response = {{loop.index + 2}};
{%- endfor %}
}
}
{%- endif %}
}
{%- endfor %}