{%- set class_name = struct.name ~ "_Data" -%} class {{export_attribute}} {{class_name}} { public: class BufferWriter { public: BufferWriter() = default; void Allocate(mojo::internal::Buffer* serialization_buffer) { serialization_buffer_ = serialization_buffer; index_ = serialization_buffer_->Allocate(sizeof({{class_name}})); new (data()) {{class_name}}(); } bool is_null() const { return !serialization_buffer_; } {{class_name}}* data() { DCHECK(!is_null()); return serialization_buffer_->Get<{{class_name}}>(index_); } {{class_name}}* operator->() { return data(); } private: mojo::internal::Buffer* serialization_buffer_ = nullptr; size_t index_ = 0; DISALLOW_COPY_AND_ASSIGN(BufferWriter); }; static bool Validate(const void* data, mojo::internal::ValidationContext* validation_context); mojo::internal::StructHeader header_; {%- for packed_field in struct.packed.packed_fields %} {%- set name = packed_field.field.name %} {%- set kind = packed_field.field.kind %} {%- if kind.spec == 'b' %} uint8_t {{name}} : 1; {%- else %} {{kind|cpp_field_type}} {{name}}; {%- endif %} {%- if not loop.last %} {%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %} {%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %} {%- if pad > 0 %} uint8_t pad{{loop.index0}}_[{{pad}}]; {%- endif %} {%- endif %} {%- endfor %} {%- set num_fields = struct.versions[-1].num_fields %} {%- if num_fields > 0 %} {%- set last_field = struct.packed.packed_fields[num_fields - 1] %} {%- set offset = last_field.offset + last_field.size %} {%- set pad = offset|get_pad(8) %} {%- if pad > 0 %} uint8_t padfinal_[{{pad}}]; {%- endif %} {%- endif %} private: {{class_name}}(); ~{{class_name}}() = delete; }; static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}}, "Bad sizeof({{class_name}})");