summaryrefslogtreecommitdiff
path: root/mojo/public/tools/bindings/generators/cpp_templates/enum_serialization_declaration.tmpl
blob: d7d0e5d8738a86f3b0bab4931a3d3a68282ba0ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{%- set mojom_type = enum|get_qualified_name_for_kind(
        flatten_nested_kind=True) %}

template <>
struct EnumTraits<{{mojom_type}}, {{mojom_type}}> {
  static {{mojom_type}} ToMojom({{mojom_type}} input) { return input; }
  static bool FromMojom({{mojom_type}} input, {{mojom_type}}* output) {
    *output = input;
    return true;
  }
};

namespace internal {

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

  static void Serialize(UserType input, int32_t* output) {
    *output = static_cast<int32_t>(Traits::ToMojom(input));
  }

  static bool Deserialize(int32_t input, UserType* output) {
    return Traits::FromMojom(static_cast<{{mojom_type}}>(input), output);
  }
};

}  // namespace internal