summaryrefslogtreecommitdiffstats
path: root/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl
blob: 8ad699bad15aa6f40f69d24f8602962537791f4c (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
{%- import "interface_macros.tmpl" as interface_macros %}
{%- import "struct_macros.tmpl" as struct_macros %}

{%- set class_name = interface.name %}
{%- set proxy_name = interface.name ~ "Proxy" %}
{%- set namespace_as_string = "%s"|format(namespace|replace(".","::")) %}

{%- macro alloc_params(struct, params, message, method_number, is_response) %}
  mojo::internal::SerializationContext serialization_context;
  serialization_context.TakeHandlesFromMessage({{message}});
  bool success = true;
{%-   for param in struct.packed.packed_fields_in_ordinal_order %}
  {{param.field.kind|cpp_wrapper_call_type}} p_{{param.field.name}}{};
{%-   endfor %}
  {{struct.name}}DataView input_data_view({{params}}, &serialization_context);
  {{struct_macros.deserialize(struct, "input_data_view", "p_%s", "success")}}
  if (!success) {
    ReportValidationErrorForMessage(
        {{message}},
        mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
        {{class_name}}::Name_, {{method_number}}, {{is_response}});
    return false;
  }
{%- endmacro %}

{%- macro pass_params(parameters) %}
{%-   for param in parameters %}
std::move(p_{{param.name}})
{%-     if not loop.last %}, {% endif %}
{%-   endfor %}
{%- endmacro %}

{#--- Begin #}
const char {{class_name}}::Name_[] = "{{module_namespace}}.{{class_name}}";

{#--- Constants #}
{%-  for constant in interface.constants %}
{%-   if constant.kind|is_string_kind %}
const char {{interface.name}}::{{constant.name}}[] = {{constant|constant_value}};
{%-   else %}
constexpr {{constant.kind|cpp_pod_type}} {{interface.name}}::{{constant.name}};
{%-   endif %}
{%- endfor %}


{%- for method in interface.methods %}
{%-   if method.sync %}
bool {{class_name}}::{{method.name}}({{interface_macros.declare_sync_method_params("", method)}}) {
  NOTREACHED();
  return false;
}
{%-   endif %}
{%- endfor %}

{#--- ForwardToCallback definition #}
{%- for method in interface.methods -%}
{%-   if method.response_parameters != None %}
{%-     if method.sync %}
class {{class_name}}_{{method.name}}_HandleSyncResponse
    : public mojo::MessageReceiver {
 public:
  {{class_name}}_{{method.name}}_HandleSyncResponse(
      bool* result
{%-       for param in method.response_parameters -%}
      , {{param.kind|cpp_wrapper_call_type}}* out_{{param.name}}
{%-       endfor %})
      : result_(result)
{%-       for param in method.response_parameters -%}
        , out_{{param.name}}_(out_{{param.name}})
{%-       endfor %} {
    DCHECK(!*result_);
  }
  bool Accept(mojo::Message* message) override;
 private:
  bool* result_;
{%-       for param in method.response_parameters %}
  {{param.kind|cpp_wrapper_call_type}}* out_{{param.name}}_;
{%-       endfor -%}
  DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_HandleSyncResponse);
};
{%-     endif %}

class {{class_name}}_{{method.name}}_ForwardToCallback
    : public mojo::MessageReceiver {
 public:
  {{class_name}}_{{method.name}}_ForwardToCallback(
      {{class_name}}::{{method.name}}Callback callback
      ) : callback_(std::move(callback)) {
  }
  bool Accept(mojo::Message* message) override;
 private:
  {{class_name}}::{{method.name}}Callback callback_;
  DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ForwardToCallback);
};
{%-   endif %}
{%- endfor %}

{{proxy_name}}::{{proxy_name}}(mojo::MessageReceiverWithResponder* receiver)
    : receiver_(receiver) {
}

{#--- Proxy definitions #}

{%- for method in interface.methods %}
{%-   set message_name =
          "internal::k%s_%s_Name"|format(interface.name, method.name) %}
{%-   set params_struct = method.param_struct %}
{%-   set params_description =
          "%s.%s request"|format(interface.name, method.name) %}
{%-   set message_typename = "%s_%s_Message"|format(proxy_name, method.name) %}

{%-   if method|method_supports_lazy_serialization %}
{{interface_macros.define_message_type(
    interface, message_typename, message_name, False, method, method.parameters,
    params_struct, params_description)}}
{%-   endif %}

{%-   if method.sync %}
bool {{proxy_name}}::{{method.name}}(
    {{interface_macros.declare_sync_method_params("param_", method)}}) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "{{namespace_as_string}}::{{class_name}}::{{method.name}}");
#endif
  const bool kExpectsResponse = true;
  const bool kIsSync = true;
{%-   if method|method_supports_lazy_serialization %}
  const bool kSerialize = receiver_->PrefersSerializedMessages();
  auto message = {{message_typename}}::Build(
      kSerialize, kExpectsResponse, kIsSync
{%-     for param in method.parameters -%}
      , std::move(param_{{param.name}})
{%-     endfor %});
{%-   else %}
  {{interface_macros.build_message_flags(False, "kIsSync", "kExpectsResponse",
                                         "kFlags")}}
  {{interface_macros.build_serialized_message(
      message_name, "param_%s", params_struct, params_description, "kFlags",
      "message")}}
{%-   endif %}

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name({{class_name}}::Name_);
  message.set_method_name("{{method.name}}");
#endif

  bool result = false;
  std::unique_ptr<mojo::MessageReceiver> responder(
      new {{class_name}}_{{method.name}}_HandleSyncResponse(
          &result
{%-     for param in method.response_parameters -%}
          , out_param_{{param.name}}
{%-     endfor %}));
  ignore_result(receiver_->AcceptWithResponder(&message, std::move(responder)));
  return result;
}
{%-   endif %}

void {{proxy_name}}::{{method.name}}(
    {{interface_macros.declare_request_params("in_", method)}}) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "{{namespace_as_string}}::{{class_name}}::{{method.name}}");
#endif
{%- if method.response_parameters != None %}
  const bool kExpectsResponse = true;
{%- else %}
  const bool kExpectsResponse = false;
{%- endif %}
  const bool kIsSync = false;
{%-   if method|method_supports_lazy_serialization %}
  const bool kSerialize = receiver_->PrefersSerializedMessages();
  auto message = {{message_typename}}::Build(
      kSerialize, kExpectsResponse, kIsSync
{%-     for param in method.parameters -%}
      , std::move(in_{{param.name}})
{%-     endfor %});
{%-   else %}
  {{interface_macros.build_message_flags(False, "kIsSync", "kExpectsResponse",
                                         "kFlags")}}
  {{interface_macros.build_serialized_message(
      message_name, "in_%s", params_struct, params_description, "kFlags",
      "message")}}
{%-   endif %}

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name({{class_name}}::Name_);
  message.set_method_name("{{method.name}}");
#endif

{%- if method.response_parameters != None %}
  std::unique_ptr<mojo::MessageReceiver> responder(
      new {{class_name}}_{{method.name}}_ForwardToCallback(
          std::move(callback)));
  ignore_result(receiver_->AcceptWithResponder(&message, std::move(responder)));
{%- else %}
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ignore_result(receiver_->Accept(&message));
{%- endif %}
}
{%- endfor %}

{#--- ProxyToResponder definition #}
{%- for method in interface.methods -%}
{%-   if method.response_parameters != None %}
{%-     set message_name =
            "internal::k%s_%s_Name"|format(interface.name, method.name) %}
{%-     set response_params_struct = method.response_param_struct %}
{%-     set params_description =
            "%s.%s response"|format(interface.name, method.name) %}
{%-     set response_message_typename =
            "%s_%s_Response_Message"|format(interface.name, method.name) %}
class {{class_name}}_{{method.name}}_ProxyToResponder {
 public:
  static {{class_name}}::{{method.name}}Callback CreateCallback(
      uint64_t request_id,
      bool is_sync,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
    std::unique_ptr<{{class_name}}_{{method.name}}_ProxyToResponder> proxy(
        new {{class_name}}_{{method.name}}_ProxyToResponder(
            request_id, is_sync, std::move(responder)));
    return base::BindOnce(&{{class_name}}_{{method.name}}_ProxyToResponder::Run,
                          std::move(proxy));
  }

  ~{{class_name}}_{{method.name}}_ProxyToResponder() {
#if DCHECK_IS_ON()
    if (responder_) {
      // If we're being destroyed without being run, we want to ensure the
      // binding endpoint has been closed. This checks for that asynchronously.
      // We pass a bound generated callback to handle the response so that any
      // resulting DCHECK stack will have useful interface type information.
      responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
    }
#endif
    // If the Callback was dropped then deleting the responder will close
    // the pipe so the calling application knows to stop waiting for a reply.
    responder_ = nullptr;
  }

 private:
  {{class_name}}_{{method.name}}_ProxyToResponder(
      uint64_t request_id,
      bool is_sync,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
      : request_id_(request_id),
        is_sync_(is_sync),
        responder_(std::move(responder)) {
  }

#if DCHECK_IS_ON()
  static void OnIsConnectedComplete(bool connected) {
    DCHECK(!connected)
        << "{{class_name}}::{{method.name}}Callback was destroyed without "
        << "first either being run or its corresponding binding being closed. "
        << "It is an error to drop response callbacks which still correspond "
        << "to an open interface pipe.";
  }
#endif

  void Run(
      {{interface_macros.declare_params("in_", method.response_parameters)}});

  uint64_t request_id_;
  bool is_sync_;
  std::unique_ptr<mojo::MessageReceiverWithStatus> responder_;

  DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ProxyToResponder);
};

{%-     if method|method_supports_lazy_serialization %}
{{interface_macros.define_message_type(
    interface, response_message_typename, message_name, True, method,
    method.response_parameters, response_params_struct, params_description)}}
{%-     endif %}

bool {{class_name}}_{{method.name}}_ForwardToCallback::Accept(
    mojo::Message* message) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1("mojom", "{{namespace_as_string}}::{{class_name}}::{{method.name}}Callback",
               "message", message->name());
#endif
  mojo::internal::MessageDispatchContext dispatch_context(message);
{%-     if method|method_supports_lazy_serialization %}
  if (!message->is_serialized()) {
    auto context =
        message->TakeUnserializedContext<{{response_message_typename}}>();
    if (!context) {
      // The Message was not of the expected type. It may be a valid message
      // which was build using a different variant of these bindings. Force
      // serialization before dispatch in this case.
      message->SerializeIfNecessary();
    } else {
      if (!callback_.is_null())
        context->Dispatch(message, &callback_);
      return true;
    }
  }
{%-     endif %}

  DCHECK(message->is_serialized());
  internal::{{class_name}}_{{method.name}}_ResponseParams_Data* params =
      reinterpret_cast<
          internal::{{class_name}}_{{method.name}}_ResponseParams_Data*>(
              message->mutable_payload());

{%-     set desc = class_name~"::"~method.name~" response" %}
  {{alloc_params(method.response_param_struct, "params", "message", method.sequential_ordinal, "true")}}
  if (!callback_.is_null())
    std::move(callback_).Run({{pass_params(method.response_parameters)}});
  return true;
}

void {{class_name}}_{{method.name}}_ProxyToResponder::Run(
    {{interface_macros.declare_params("in_", method.response_parameters)}}) {
{%-   if method|method_supports_lazy_serialization %}
  const bool kSerialize = responder_->PrefersSerializedMessages();
  auto message = {{response_message_typename}}::Build(kSerialize, is_sync_
{%-     for param in method.response_parameters -%}
      , std::move(in_{{param.name}})
{%-     endfor %});
{%-   else %}
  {{interface_macros.build_message_flags(True, "is_sync_", "false", "kFlags")}}
  {{interface_macros.build_serialized_message(
      message_name, "in_%s", response_params_struct,
      response_params_description, "kFlags", "message")}}
{%-   endif %}

#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1("mojom", "(Impl){{namespace_as_string}}::{{class_name}}::{{method.name}}Callback",
               "message", message.name());
#endif

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name({{class_name}}::Name_);
  message.set_method_name("{{method.name}}");
#endif

  message.set_request_id(request_id_);
  ignore_result(responder_->Accept(&message));
  // TODO(darin): Accept() returning false indicates a malformed message, and
  // that may be good reason to close the connection. However, we don't have a
  // way to do that from here. We should add a way.
  responder_ = nullptr;
}
{%-   endif -%}

{%-   if method.sync %}
bool {{class_name}}_{{method.name}}_HandleSyncResponse::Accept(
    mojo::Message* message) {
{%-     if method|method_supports_lazy_serialization %}
  if (!message->is_serialized()) {
    auto context =
        message->TakeUnserializedContext<{{response_message_typename}}>();
    if (!context) {
      // The Message was not of the expected type. It may be a valid message
      // which was built using a different variant of these bindings. Force
      // serialization before dispatch in this case.
      message->SerializeIfNecessary();
    } else {
      context->HandleSyncResponse(
          message
{%-       for param in method.response_parameters %},
          out_{{param.name}}_
{%-       endfor %});
      *result_ = true;
      mojo::internal::SyncMessageResponseSetup::SetCurrentSyncResponseMessage(
          message);
      return true;
    }
  }
{%-     endif %}

  DCHECK(message->is_serialized());
  internal::{{class_name}}_{{method.name}}_ResponseParams_Data* params =
      reinterpret_cast<internal::{{class_name}}_{{method.name}}_ResponseParams_Data*>(
          message->mutable_payload());

{%-       set desc = class_name~"::"~method.name~" response" %}
  {{alloc_params(method.response_param_struct, "params", "message", method.sequential_ordinal, "true")}}

{%-       for param in method.response_parameters %}
  *out_{{param.name}}_ = std::move(p_{{param.name}});
{%-       endfor %}
  mojo::internal::SyncMessageResponseSetup::SetCurrentSyncResponseMessage(
      message);
  *result_ = true;
  return true;
}
{%- endif %}

{%- endfor %}

{#--- StubDispatch definition #}

// static
bool {{class_name}}StubDispatch::Accept(
    {{interface.name}}* impl,
    mojo::Message* message) {
{%- if interface.methods %}
  switch (message->header()->name) {
{%-   for method in interface.methods %}
    case internal::k{{class_name}}_{{method.name}}_Name: {
{%-     if method.response_parameters == None %}
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      TRACE_EVENT1(
          "mojom",
          "(Impl){{namespace_as_string}}::{{class_name}}::{{method.name}}",
          "message", message->name());
#endif
      static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
              "(Impl){{namespace_as_string}}::{{class_name}}::{{method.name}}");
      base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);
      mojo::internal::MessageDispatchContext context(message);
{%-       if method|method_supports_lazy_serialization %}
      if (!message->is_serialized()) {
        auto context = message->TakeUnserializedContext<
            {{proxy_name}}_{{method.name}}_Message>();
        if (!context) {
          // The Message was not of the expected type. It may be a valid message
          // which was serialized using a different variant of these bindings.
          // Force serialization before dispatch in this case.
          message->SerializeIfNecessary();
        } else {
          context->Dispatch(message, impl);
          return true;
        }
      }
{%-       endif %}

      DCHECK(message->is_serialized());
      internal::{{class_name}}_{{method.name}}_Params_Data* params =
          reinterpret_cast<internal::{{class_name}}_{{method.name}}_Params_Data*>(
              message->mutable_payload());

{%-       set desc = class_name~"::"~method.name %}
      {{alloc_params(method.param_struct, "params", "message", method.sequential_ordinal, "false")|
          indent(4)}}
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->{{method.name}}({{pass_params(method.parameters)}});
      return true;
{%-     else %}
      break;
{%-     endif %}
    }
{%-   endfor %}
  }
{%- endif %}
  return false;
}

// static
bool {{class_name}}StubDispatch::AcceptWithResponder(
    {{interface.name}}* impl,
    mojo::Message* message,
    std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
{%- if interface.methods %}
  switch (message->header()->name) {
{%-   for method in interface.methods %}
    case internal::k{{class_name}}_{{method.name}}_Name: {
{%-     if method.response_parameters != None %}
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      TRACE_EVENT1(
          "mojom",
          "(Impl){{namespace_as_string}}::{{class_name}}::{{method.name}}",
          "message", message->name());
#endif
      static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
              "(Impl){{namespace_as_string}}::{{class_name}}::{{method.name}}");
      base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);
      mojo::internal::MessageDispatchContext context(message);
{%-       if method|method_supports_lazy_serialization %}
      if (!message->is_serialized()) {
        auto context = message->TakeUnserializedContext<
            {{proxy_name}}_{{method.name}}_Message>();
        if (!context) {
          // The Message was not of the expected type. It may be a valid message
          // which was built using a different variant of these bindings. Force
          // serialization before dispatch in this case.
          message->SerializeIfNecessary();
        } else {
          {{class_name}}::{{method.name}}Callback callback =
              {{class_name}}_{{method.name}}_ProxyToResponder::CreateCallback(
                  message->request_id(),
                  message->has_flag(mojo::Message::kFlagIsSync),
                  std::move(responder));
          context->Dispatch(message, impl, std::move(callback));
          return true;
        }
      }
{%-       endif %}

      internal::{{class_name}}_{{method.name}}_Params_Data* params =
          reinterpret_cast<
              internal::{{class_name}}_{{method.name}}_Params_Data*>(
                  message->mutable_payload());

{%-       set desc = class_name~"::"~method.name %}
      {{alloc_params(method.param_struct, "params", "message", method.sequential_ordinal, "false")|
          indent(4)}}
      {{class_name}}::{{method.name}}Callback callback =
          {{class_name}}_{{method.name}}_ProxyToResponder::CreateCallback(
              message->request_id(),
              message->has_flag(mojo::Message::kFlagIsSync),
              std::move(responder));
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->{{method.name}}(
{%- if method.parameters -%}{{pass_params(method.parameters)}}, {% endif -%}std::move(callback));
      return true;
{%-     else %}
      break;
{%-     endif %}
    }
{%-   endfor %}
  }
{%- endif %}
  return false;
}

{#--- Request validator definitions #}

bool {{class_name}}RequestValidator::Accept(mojo::Message* message) {
  if (!message->is_serialized() ||
      mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
    return true;
  }

  mojo::internal::ValidationContext validation_context(
    message->payload(), message->payload_num_bytes(),
    message->handles()->size(), message->payload_num_interface_ids(), message,
    "{{class_name}} RequestValidator");

  switch (message->header()->name) {
{%- for method in interface.methods %}
    case internal::k{{class_name}}_{{method.name}}_Name: {
{%-   if method.response_parameters != None %}
      if (!mojo::internal::ValidateMessageIsRequestExpectingResponse(
              message, &validation_context)) {
        return false;
      }
{%-   else %}
      if (!mojo::internal::ValidateMessageIsRequestWithoutResponse(
              message, &validation_context)) {
        return false;
      }
{%-   endif %}
      if (!mojo::internal::ValidateMessagePayload<
               internal::{{class_name}}_{{method.name}}_Params_Data>(
                  message, &validation_context)) {
        return false;
      }
      return true;
    }
{%- endfor %}
    default:
      break;
  }

  // Unrecognized message.
  ReportValidationError(
      &validation_context,
      mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
  return false;
}

{#--- Response validator definitions #}
{% if interface|has_callbacks %}
bool {{class_name}}ResponseValidator::Accept(mojo::Message* message) {
  if (!message->is_serialized() ||
      mojo::internal::ControlMessageHandler::IsControlMessage(message)) {
    return true;
  }

  mojo::internal::ValidationContext validation_context(
    message->payload(), message->payload_num_bytes(),
    message->handles()->size(), message->payload_num_interface_ids(), message,
    "{{class_name}} ResponseValidator");

  if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context))
    return false;
  switch (message->header()->name) {
{%- for method in interface.methods if method.response_parameters != None %}
    case internal::k{{class_name}}_{{method.name}}_Name: {
      if (!mojo::internal::ValidateMessagePayload<
               internal::{{class_name}}_{{method.name}}_ResponseParams_Data>(
                    message, &validation_context)) {
        return false;
      }
      return true;
    }
{%- endfor %}
    default:
      break;
  }

  // Unrecognized message.
  ReportValidationError(
      &validation_context,
      mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD);
  return false;
}
{%- endif -%}