OLD | NEW |
1 class {{struct.name}}DataView { | 1 class {{struct.name}}DataView { |
2 public: | 2 public: |
3 {{struct.name}}DataView() {} | 3 {{struct.name}}DataView() {} |
4 | 4 |
5 {{struct.name}}DataView( | 5 {{struct.name}}DataView( |
6 internal::{{struct.name}}_Data* data, | 6 internal::{{struct.name}}_Data* data, |
7 mojo::internal::SerializationContext* context) | 7 mojo::internal::SerializationContext* context) |
8 {%- if struct|requires_context_for_data_view %} | 8 {%- if struct|requires_context_for_data_view %} |
9 : data_(data), context_(context) {} | 9 : data_(data), context_(context) {} |
10 {%- else %} | 10 {%- else %} |
11 : data_(data) {} | 11 : data_(data) {} |
12 {%- endif %} | 12 {%- endif %} |
13 | 13 |
14 bool is_null() const { return !data_; } | 14 bool is_null() const { return !data_; } |
15 | 15 |
16 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} | 16 {%- for pf in struct.packed.packed_fields_in_ordinal_order %} |
17 {%- set kind = pf.field.kind %} | 17 {%- set kind = pf.field.kind %} |
18 {%- set name = pf.field.name %} | 18 {%- set name = pf.field.name %} |
19 {%- if kind|is_union_kind %} | 19 {%- if kind|is_union_kind %} |
20 inline void Get{{name|under_to_camel}}DataView( | 20 inline void Get{{name|under_to_camel}}DataView( |
21 {{kind|cpp_data_view_type}}* output); | 21 {{kind|cpp_data_view_type}}* output); |
22 | 22 |
23 template <typename UserType> | 23 template <typename UserType> |
24 bool Read{{name|under_to_camel}}(UserType* output) { | 24 WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) { |
25 {%- if pf.min_version != 0 %} | 25 {%- if pf.min_version != 0 %} |
26 auto pointer = data_->header_.version >= {{pf.min_version}} | 26 auto* pointer = data_->header_.version >= {{pf.min_version}} |
27 ? &data_->{{name}} : nullptr; | 27 ? &data_->{{name}} : nullptr; |
28 {%- else %} | 28 {%- else %} |
29 auto pointer = &data_->{{name}}; | 29 auto* pointer = &data_->{{name}}; |
30 {%- endif %} | 30 {%- endif %} |
31 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( | 31 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( |
32 pointer, output, context_); | 32 pointer, output, context_); |
33 } | 33 } |
34 | 34 |
35 {%- elif kind|is_object_kind %} | 35 {%- elif kind|is_object_kind %} |
36 inline void Get{{name|under_to_camel}}DataView( | 36 inline void Get{{name|under_to_camel}}DataView( |
37 {{kind|cpp_data_view_type}}* output); | 37 {{kind|cpp_data_view_type}}* output); |
38 | 38 |
39 template <typename UserType> | 39 template <typename UserType> |
40 bool Read{{name|under_to_camel}}(UserType* output) { | 40 WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) { |
41 {%- if pf.min_version != 0 %} | 41 {%- if pf.min_version != 0 %} |
42 auto pointer = data_->header_.version >= {{pf.min_version}} | 42 auto* pointer = data_->header_.version >= {{pf.min_version}} |
43 ? data_->{{name}}.Get() : nullptr; | 43 ? data_->{{name}}.Get() : nullptr; |
44 {%- else %} | 44 {%- else %} |
45 auto pointer = data_->{{name}}.Get(); | 45 auto* pointer = data_->{{name}}.Get(); |
46 {%- endif %} | 46 {%- endif %} |
47 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( | 47 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( |
48 pointer, output, context_); | 48 pointer, output, context_); |
49 } | 49 } |
50 | 50 |
51 {%- elif kind|is_enum_kind %} | 51 {%- elif kind|is_enum_kind %} |
52 template <typename UserType> | 52 template <typename UserType> |
53 bool Read{{name|under_to_camel}}(UserType* output) const { | 53 WARN_UNUSED_RESULT bool Read{{name|under_to_camel}}(UserType* output) const { |
54 {%- if pf.min_version != 0 %} | 54 {%- if pf.min_version != 0 %} |
55 auto data_value = data_->header_.version >= {{pf.min_version}} | 55 auto data_value = data_->header_.version >= {{pf.min_version}} |
56 ? data_->{{name}} : 0; | 56 ? data_->{{name}} : 0; |
57 {%- else %} | 57 {%- else %} |
58 auto data_value = data_->{{name}}; | 58 auto data_value = data_->{{name}}; |
59 {%- endif %} | 59 {%- endif %} |
60 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( | 60 return mojo::internal::Deserialize<{{kind|unmapped_type_for_serializer}}>( |
61 data_value, output); | 61 data_value, output); |
62 } | 62 } |
63 | 63 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 {%- endif %} | 110 {%- endif %} |
111 {%- endfor %} | 111 {%- endfor %} |
112 private: | 112 private: |
113 internal::{{struct.name}}_Data* data_ = nullptr; | 113 internal::{{struct.name}}_Data* data_ = nullptr; |
114 {%- if struct|requires_context_for_data_view %} | 114 {%- if struct|requires_context_for_data_view %} |
115 mojo::internal::SerializationContext* context_ = nullptr; | 115 mojo::internal::SerializationContext* context_ = nullptr; |
116 {%- endif %} | 116 {%- endif %} |
117 }; | 117 }; |
118 | 118 |
OLD | NEW |