Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl

Issue 1867483002: Mojo: Align string sizes when serializing a native type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 size_t GetSerializedSize_(const {{struct.name}}Ptr& input, 1 size_t GetSerializedSize_(const {{struct.name}}Ptr& input,
2 mojo::internal::SerializationContext* context); 2 mojo::internal::SerializationContext* context);
3 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buffer, 3 void Serialize_({{struct.name}}Ptr input, mojo::internal::Buffer* buffer,
4 internal::{{struct.name}}_Data** output, 4 internal::{{struct.name}}_Data** output,
5 mojo::internal::SerializationContext* context); 5 mojo::internal::SerializationContext* context);
6 bool Deserialize_(internal::{{struct.name}}_Data* input, 6 bool Deserialize_(internal::{{struct.name}}_Data* input,
7 {{struct.name}}Ptr* output, 7 {{struct.name}}Ptr* output,
8 mojo::internal::SerializationContext* context); 8 mojo::internal::SerializationContext* context);
9 9
10 {%- if struct|is_native_only_kind and struct|is_typemapped_kind %} 10 {%- if struct|is_native_only_kind and struct|is_typemapped_kind %}
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static size_t GetSize(const NativeType& input) { 93 static size_t GetSize(const NativeType& input) {
94 size_t size = sizeof(internal::{{struct.name}}_Data); 94 size_t size = sizeof(internal::{{struct.name}}_Data);
95 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} 95 {%- for pf in struct.packed.packed_fields_in_ordinal_order %}
96 do { 96 do {
97 {%- if pf.field.kind|is_nullable_kind %} 97 {%- if pf.field.kind|is_nullable_kind %}
98 if (!mojo::StructTraits<{{struct.name}}, NativeType> 98 if (!mojo::StructTraits<{{struct.name}}, NativeType>
99 ::has_{{pf.field.name}}(input)) 99 ::has_{{pf.field.name}}(input))
100 break; 100 break;
101 {%- endif %} 101 {%- endif %}
102 {%- if pf.field.kind|is_string_kind %} 102 {%- if pf.field.kind|is_string_kind %}
103 size += mojo::internal::String_Data::Traits::GetStorageSize( 103 size += mojo::internal::Align(
104 static_cast<uint32_t>(mojo::StructTraits<{{struct.name}}, NativeType> 104 mojo::internal::String_Data::Traits::GetStorageSize(
105 ::{{pf.field.name}}(input).size())); 105 static_cast<uint32_t>(
106 mojo::StructTraits<{{struct.name}}, NativeType>
107 ::{{pf.field.name}}(input).size())));
106 {%- elif pf.field.kind|is_object_kind %} 108 {%- elif pf.field.kind|is_object_kind %}
107 NOTREACHED() << "Unsupported field type for StructTraits: " 109 NOTREACHED() << "Unsupported field type for StructTraits: "
108 << "{{pf.field.name}}"; 110 << "{{pf.field.name}}";
109 {%- endif %} 111 {%- endif %}
110 } while (false); 112 } while (false);
111 {%- endfor %} 113 {%- endfor %}
112 return size; 114 return size;
113 } 115 }
114 116
115 static void Serialize(const NativeType& input, 117 static void Serialize(const NativeType& input,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 149
148 static bool Deserialize(internal::{{struct.name}}_Data* input, 150 static bool Deserialize(internal::{{struct.name}}_Data* input,
149 NativeType* output, 151 NativeType* output,
150 mojo::internal::SerializationContext* context) { 152 mojo::internal::SerializationContext* context) {
151 return mojo::StructTraits<{{struct.name}}, NativeType>::Read( 153 return mojo::StructTraits<{{struct.name}}, NativeType>::Read(
152 {{struct.name}}_Reader(input, context), output); 154 {{struct.name}}_Reader(input, context), output);
153 } 155 }
154 }; 156 };
155 157
156 {%- endif %} {# not variant #} 158 {%- endif %} {# not variant #}
OLDNEW
« mojo/public/tools/bindings/bindings.gyp ('K') | « mojo/public/tools/bindings/bindings.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698