1// Used by {{struct.name}}::WrapAsMessage to lazily serialize the struct.
2template <typename UserType, typename DataView>
3struct {{struct.name}}_UnserializedMessageContext
4    : public mojo::internal::UnserializedMessageContext {
5 public:
6  static const mojo::internal::UnserializedMessageContext::Tag kMessageTag;
7
8  {{struct.name}}_UnserializedMessageContext(
9    uint32_t message_name,
10    uint32_t message_flags,
11    UserType input)
12      : mojo::internal::UnserializedMessageContext(&kMessageTag, message_name, message_flags)
13      , user_data_(std::move(input)) {}
14  ~{{struct.name}}_UnserializedMessageContext() override = default;
15
16  UserType TakeData() {
17    return std::move(user_data_);
18  }
19
20 private:
21  // mojo::internal::UnserializedMessageContext:
22  void Serialize(mojo::internal::SerializationContext* context,
23                 mojo::internal::Buffer* buffer) override {
24    {{struct.name}}_Data::BufferWriter writer;
25    mojo::internal::Serialize<DataView>(user_data_, buffer, &writer, context);
26  }
27
28  UserType user_data_;
29};
30
31template <typename UserType, typename DataView>
32const mojo::internal::UnserializedMessageContext::Tag
33    {{struct.name}}_UnserializedMessageContext<UserType, DataView>::kMessageTag = {};
34