OLD | NEW |
---|---|
1 {# TODO(yzshen): Make these templates more readable. #} | 1 {# TODO(yzshen): Make these templates more readable. #} |
2 | 2 |
3 {# Computes the serialized size for the specified struct. | 3 {# Computes the serialized size for the specified struct. |
4 |struct| is the struct definition. | 4 |struct| is the struct definition. |
5 |input_field_pattern| should be a pattern that contains one string | 5 |input_field_pattern| should be a pattern that contains one string |
6 placeholder, for example, "input->%s", "p_%s". The placeholder will be | 6 placeholder, for example, "input->%s", "p_%s". The placeholder will be |
7 substituted with struct field names to refer to the input fields. | 7 substituted with struct field names to refer to the input fields. |
8 This macro is expanded to compute seriailized size for both: | 8 This macro is expanded to compute seriailized size for both: |
9 - user-defined structs: the input is an instance of the corresponding struct | 9 - user-defined structs: the input is an instance of the corresponding struct |
10 wrapper class. | 10 wrapper class. |
11 - method parameters/response parameters: the input is a list of | 11 - method parameters/response parameters: the input is a list of |
12 arguments. | 12 arguments. |
13 It declares |size| of type size_t to store the resulting size. #} | 13 It declares |size| of type size_t to store the resulting size. #} |
14 {%- macro get_serialized_size(struct, input_field_pattern) -%} | 14 {%- macro get_serialized_size(struct, input_field_pattern) -%} |
15 size_t size = sizeof(internal::{{struct.name}}_Data); | 15 size_t size = sizeof(internal::{{struct.name}}_Data); |
16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is _object_kind %} | 16 {%- for pf in struct.packed.packed_fields_in_ordinal_order if pf.field.kind|is _object_kind %} |
17 {%- if pf.field.kind|is_union_kind %} | 17 {%- if pf.field.kind|is_union_kind %} |
18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true ); | 18 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}, true ); |
19 {%- elif pf.field.kind|is_struct_kind %} | |
20 size += {{input_field_pattern|format(pf.field.name)}}.is_null() ? 0 : GetSeria lizedSize_(*{{input_field_pattern|format(pf.field.name)}}.get()); | |
viettrungluu
2015/09/23 23:20:24
Can you break this line in some reasonable way?
A
vardhan
2015/09/25 19:33:05
Done.
| |
19 {%- else %} | 21 {%- else %} |
20 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); | 22 size += GetSerializedSize_({{input_field_pattern|format(pf.field.name)}}); |
21 {%- endif %} | 23 {%- endif %} |
22 {%- endfor %} | 24 {%- endfor %} |
23 {%- endmacro -%} | 25 {%- endmacro -%} |
24 | 26 |
25 {# Serializes the specified struct. | 27 {# Serializes the specified struct. |
26 |struct| is the struct definition. | 28 |struct| is the struct definition. |
27 |struct_display_name| is the display name for the struct that can be showed | 29 |struct_display_name| is the display name for the struct that can be showed |
28 in error/log messages, for example, "FooStruct", "FooMethod request". | 30 in error/log messages, for example, "FooStruct", "FooMethod request". |
(...skipping 11 matching lines...) Expand all Loading... | |
40 internal::{{struct.name}}_Data* {{output}} = | 42 internal::{{struct.name}}_Data* {{output}} = |
41 internal::{{struct.name}}_Data::New({{buffer}}); | 43 internal::{{struct.name}}_Data::New({{buffer}}); |
42 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 44 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
43 {%- set input_field = input_field_pattern|format(pf.field.name) %} | 45 {%- set input_field = input_field_pattern|format(pf.field.name) %} |
44 {%- set name = pf.field.name %} | 46 {%- set name = pf.field.name %} |
45 {%- set kind = pf.field.kind %} | 47 {%- set kind = pf.field.kind %} |
46 {%- if kind|is_object_kind %} | 48 {%- if kind|is_object_kind %} |
47 {%- if kind|is_array_kind %} | 49 {%- if kind|is_array_kind %} |
48 const mojo::internal::ArrayValidateParams {{name}}_validate_params( | 50 const mojo::internal::ArrayValidateParams {{name}}_validate_params( |
49 {{kind|get_array_validate_params_ctor_args|indent(10)}}); | 51 {{kind|get_array_validate_params_ctor_args|indent(10)}}); |
50 mojo::SerializeArray_(mojo::internal::Forward({{input_field}}), {{buffer}}, | 52 mojo::SerializeArray_(&{{input_field}}, {{buffer}}, |
51 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); | 53 &{{output}}->{{name}}.ptr, &{{name}}_validate_params); |
52 {%- elif kind|is_map_kind %} | 54 {%- elif kind|is_map_kind %} |
53 const mojo::internal::ArrayValidateParams {{name}}_validate_params( | 55 const mojo::internal::ArrayValidateParams {{name}}_validate_params( |
54 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); | 56 {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); |
55 mojo::SerializeMap_( | 57 mojo::SerializeMap_( |
56 mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name} }.ptr, | 58 &{{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr, |
57 &{{name}}_validate_params); | 59 &{{name}}_validate_params); |
58 {%- elif kind|is_union_kind %} | 60 {%- elif kind|is_union_kind %} |
59 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; | 61 internal::{{kind.name}}_Data* {{name}}_ptr = &{{output}}->{{name}}; |
60 SerializeUnion_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{name} }_ptr, true); | 62 SerializeUnion_({{input_field}}.get(), {{buffer}}, &{{name}}_ptr, true); |
63 {%- elif kind|is_string_kind %} | |
64 SerializeString_({{input_field}}, {{buffer}}, &{{output}}->{{name}}.ptr); | |
61 {%- else %} | 65 {%- else %} |
62 Serialize_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}-> {{name}}.ptr); | 66 Serialize_({{input_field}}.get(), {{buffer}}, &{{output}}->{{name}}.ptr); |
63 {%- endif %} | 67 {%- endif %} |
64 {%- if not kind|is_nullable_kind %} | 68 {%- if not kind|is_nullable_kind %} |
65 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( | 69 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
66 {%- if kind|is_union_kind %} | 70 {%- if kind|is_union_kind %} |
67 {{output}}->{{name}}.is_null(), | 71 {{output}}->{{name}}.is_null(), |
68 {%- else %} | 72 {%- else %} |
69 !{{output}}->{{name}}.ptr, | 73 !{{output}}->{{name}}.ptr, |
70 {%- endif %} | 74 {%- endif %} |
71 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, | 75 mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
72 "null {{name}} in {{struct_display_name}}"); | 76 "null {{name}} in {{struct_display_name}}"); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 {%- set output_field = output_field_pattern|format(pf.field.name) %} | 123 {%- set output_field = output_field_pattern|format(pf.field.name) %} |
120 {%- set name = pf.field.name %} | 124 {%- set name = pf.field.name %} |
121 {%- set kind = pf.field.kind %} | 125 {%- set kind = pf.field.kind %} |
122 {%- if pf.min_version > last_checked_version %} | 126 {%- if pf.min_version > last_checked_version %} |
123 {%- set last_checked_version = pf.min_version %} | 127 {%- set last_checked_version = pf.min_version %} |
124 if ({{input}}->header_.version < {{pf.min_version}}) | 128 if ({{input}}->header_.version < {{pf.min_version}}) |
125 break; | 129 break; |
126 {%- endif %} | 130 {%- endif %} |
127 {%- if kind|is_object_kind %} | 131 {%- if kind|is_object_kind %} |
128 {%- if kind|is_union_kind %} | 132 {%- if kind|is_union_kind %} |
129 Deserialize_(&{{input}}->{{name}}, &{{output_field}}); | 133 {{output_field}} = {{kind|get_name_for_kind}}::New(); |
134 Deserialize_(&{{input}}->{{name}}, {{output_field}}.get()); | |
135 {%- elif kind|is_struct_kind %} | |
136 if ({{input}}->{{name}}.ptr) { | |
137 {{output_field}} = {{kind|get_name_for_kind}}::New(); | |
138 Deserialize_({{input}}->{{name}}.ptr, {{output_field}}.get()); | |
139 } | |
130 {%- else %} | 140 {%- else %} |
141 {#- Arrays and Maps #} | |
131 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); | 142 Deserialize_({{input}}->{{name}}.ptr, &{{output_field}}); |
132 {%- endif %} | 143 {%- endif %} |
133 {%- elif kind|is_interface_kind %} | 144 {%- elif kind|is_interface_kind %} |
134 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); | 145 mojo::internal::InterfaceDataToPointer(&{{input}}->{{name}}, &{{output_field }}); |
135 {%- elif kind|is_interface_request_kind %} | 146 {%- elif kind|is_interface_request_kind %} |
136 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); | 147 {{output_field}}.Bind(mojo::MakeScopedHandle(mojo::internal::FetchAndReset(& {{input}}->{{name}}))); |
137 {%- elif kind|is_any_handle_kind %} | 148 {%- elif kind|is_any_handle_kind %} |
138 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); | 149 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); |
139 {%- elif kind|is_enum_kind %} | 150 {%- elif kind|is_enum_kind %} |
140 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); | 151 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); |
141 {%- else %} | 152 {%- else %} |
142 {{output_field}} = {{input}}->{{name}}; | 153 {{output_field}} = {{input}}->{{name}}; |
143 {%- endif %} | 154 {%- endif %} |
144 {%- endfor %} | 155 {%- endfor %} |
145 } while (false); | 156 } while (false); |
146 {%- endmacro %} | 157 {%- endmacro %} |
OLD | NEW |