chromium/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl

{%- import "struct_macros.tmpl" as struct_macros %}
{%- set data_view = struct|get_qualified_name_for_kind ~ "DataView" %}
{%- set data_type = struct|get_qualified_name_for_kind(internal=True) %}

{%- if not struct|use_custom_serializer %}

namespace internal {

template <typename MaybeConstUserType>
struct Serializer<{{data_view}}, MaybeConstUserType> {
  using UserType = typename std::remove_const<MaybeConstUserType>::type;
  using Traits = StructTraits<{{data_view}}, UserType>;

  static void Serialize(
      MaybeConstUserType& input,
      mojo::internal::MessageFragment<{{data_type}}>& fragment) {
    if (CallIsNullIfExists<Traits>(input))
      return;
    {{struct_macros.serialize(
          struct, struct.name ~ " struct", "Traits::%s(input)", "fragment",
          True)|indent(2)}}
  }

  static bool Deserialize({{data_type}}* input,
                          UserType* output,
                          Message* message) {
    if (!input)
      return CallSetToNullIfExists<Traits>(output);

    {{data_view}} data_view(input, message);
    return Traits::Read(data_view, output);
  }
};

}  // namespace internal

{%- endif %}