EmbeddedProto 4.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EmbeddedProto/EmbeddedProto.py +122 -0
- EmbeddedProto/Features.py +255 -0
- EmbeddedProto/Field.py +1295 -0
- EmbeddedProto/Oneof.py +74 -0
- EmbeddedProto/ProtoFile.py +210 -0
- EmbeddedProto/TypeDefinitions.py +367 -0
- EmbeddedProto/__init__.py +0 -0
- EmbeddedProto/__main__.py +28 -0
- EmbeddedProto/config.py +173 -0
- EmbeddedProto/custom_header.py +513 -0
- EmbeddedProto/embedded_proto_options.proto +62 -0
- EmbeddedProto/embedded_proto_options_pb2.py +37 -0
- EmbeddedProto/field_options.py +344 -0
- EmbeddedProto/main.py +316 -0
- EmbeddedProto/src/EmbeddedProto/BytesStringCallback.h +476 -0
- EmbeddedProto/src/EmbeddedProto/Defines.h +118 -0
- EmbeddedProto/src/EmbeddedProto/EmptyArray.h +81 -0
- EmbeddedProto/src/EmbeddedProto/Errors.h +53 -0
- EmbeddedProto/src/EmbeddedProto/FieldStringBytes.h +793 -0
- EmbeddedProto/src/EmbeddedProto/Fields.h +832 -0
- EmbeddedProto/src/EmbeddedProto/Functional.h +412 -0
- EmbeddedProto/src/EmbeddedProto/MessageCallback.h +688 -0
- EmbeddedProto/src/EmbeddedProto/MessageInterface.h +792 -0
- EmbeddedProto/src/EmbeddedProto/MessageSizeCalculator.h +109 -0
- EmbeddedProto/src/EmbeddedProto/MessageState.h +207 -0
- EmbeddedProto/src/EmbeddedProto/ReadBufferFixedSize.h +204 -0
- EmbeddedProto/src/EmbeddedProto/ReadBufferInterface.h +181 -0
- EmbeddedProto/src/EmbeddedProto/ReadBufferSection.h +232 -0
- EmbeddedProto/src/EmbeddedProto/RepeatedField.h +1053 -0
- EmbeddedProto/src/EmbeddedProto/RepeatedFieldCallback.h +432 -0
- EmbeddedProto/src/EmbeddedProto/RepeatedFieldFixedSize.h +367 -0
- EmbeddedProto/src/EmbeddedProto/Version.h +39 -0
- EmbeddedProto/src/EmbeddedProto/WireFormatter.h +852 -0
- EmbeddedProto/src/EmbeddedProto/WriteBufferFixedSize.h +114 -0
- EmbeddedProto/src/EmbeddedProto/WriteBufferInterface.h +134 -0
- EmbeddedProto/src/EmbeddedProto.h +55 -0
- EmbeddedProto/templates/FieldBasic_Deserialize.h.jinja2 +26 -0
- EmbeddedProto/templates/FieldBasic_GetSet.h.jinja2 +89 -0
- EmbeddedProto/templates/FieldBytes_GetSet.h.jinja2 +86 -0
- EmbeddedProto/templates/FieldEnum_Deserialize.h.jinja2 +50 -0
- EmbeddedProto/templates/FieldEnum_GetSet.h.jinja2 +93 -0
- EmbeddedProto/templates/FieldErrorRecursive_GetSet.h.jinja2 +29 -0
- EmbeddedProto/templates/FieldMap_GetSet.h.jinja2 +203 -0
- EmbeddedProto/templates/FieldMsg_Deserialize.h.jinja2 +44 -0
- EmbeddedProto/templates/FieldMsg_GetSet.h.jinja2 +93 -0
- EmbeddedProto/templates/FieldRepeated_GetSet.h.jinja2 +94 -0
- EmbeddedProto/templates/FieldString_GetSet.h.jinja2 +86 -0
- EmbeddedProto/templates/Field_DeserializePartial.h.jinja2 +33 -0
- EmbeddedProto/templates/Field_Serialize.h.jinja2 +112 -0
- EmbeddedProto/templates/Field_SerializePartial.h.jinja2 +119 -0
- EmbeddedProto/templates/Header.h.jinja2 +108 -0
- EmbeddedProto/templates/TypeDefEnum.h.jinja2 +45 -0
- EmbeddedProto/templates/TypeDefMsg.h.jinja2 +791 -0
- EmbeddedProto/templates/TypeOneof.h.jinja2 +178 -0
- EmbeddedProto/version.json +3 -0
- embeddedproto-4.0.0b1.dist-info/METADATA +141 -0
- embeddedproto-4.0.0b1.dist-info/RECORD +63 -0
- embeddedproto-4.0.0b1.dist-info/WHEEL +5 -0
- embeddedproto-4.0.0b1.dist-info/entry_points.txt +3 -0
- embeddedproto-4.0.0b1.dist-info/licenses/LICENSE +30 -0
- embeddedproto-4.0.0b1.dist-info/licenses/LICENSES/GPL-3.0-only.txt +674 -0
- embeddedproto-4.0.0b1.dist-info/licenses/LICENSES/LicenseRef-EmbeddedProto-Commercial.txt +12 -0
- embeddedproto-4.0.0b1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
{#
|
|
2
|
+
Copyright (C) 2020-2026 Embedded AMS B.V. - All Rights Reserved
|
|
3
|
+
|
|
4
|
+
This file is part of Embedded Proto.
|
|
5
|
+
|
|
6
|
+
Embedded Proto is dual licensed. You may use it under the terms of the
|
|
7
|
+
GNU General Public License version 3 (GPLv3) as published by the Free
|
|
8
|
+
Software Foundation, or under a commercial license from Embedded AMS B.V.
|
|
9
|
+
|
|
10
|
+
Under the GPLv3 you must release the source code of
|
|
11
|
+
any product you distribute that includes Embedded Proto or code
|
|
12
|
+
generated by it. A commercial license removes that obligation.
|
|
13
|
+
See <https://embeddedproto.com/pricing/>.
|
|
14
|
+
|
|
15
|
+
Embedded Proto is distributed WITHOUT ANY WARRANTY; without even the
|
|
16
|
+
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
17
|
+
See the LICENSE file in the root of the repository for details.
|
|
18
|
+
|
|
19
|
+
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-EmbeddedProto-Commercial
|
|
20
|
+
|
|
21
|
+
Embedded AMS B.V., Hoorn, the Netherlands - info at EmbeddedProto dot com
|
|
22
|
+
#}
|
|
23
|
+
{% import 'TypeOneof.h.jinja2' as TypeOneof %}
|
|
24
|
+
{% for tmpl_param in typedef.get_templates() %}
|
|
25
|
+
{{"template<\n" if loop.first}} {{tmpl_param['type']}} {{tmpl_param['name']}}{{" = " + tmpl_param['default'] if 'default' in tmpl_param}}{{", " if not loop.last}}{{"\n>" if loop.last}}
|
|
26
|
+
{% endfor %}
|
|
27
|
+
class {{ typedef.get_name() }} final: public ::EmbeddedProto::MessageInterface
|
|
28
|
+
{
|
|
29
|
+
public:
|
|
30
|
+
{% for field in typedef.fields %}
|
|
31
|
+
{% if field.has_custom_storage() %}
|
|
32
|
+
static_assert(::std::is_base_of<{{field.get_storage_base_type()}}, {{field.get_storage_type_param_str()}}>::value,
|
|
33
|
+
"The customStorage type for the field \"{{field.get_name()}}\" must derive from {{field.get_storage_base_type()}}.");
|
|
34
|
+
{% endif %}
|
|
35
|
+
{% endfor %}
|
|
36
|
+
{% for oneof in typedef.oneofs %}
|
|
37
|
+
{% for field in oneof.fields %}
|
|
38
|
+
{% if field.has_custom_storage() %}
|
|
39
|
+
static_assert(::std::is_base_of<{{field.get_storage_base_type()}}, {{field.get_storage_type_param_str()}}>::value,
|
|
40
|
+
"The customStorage type for the field \"{{field.get_name()}}\" must derive from {{field.get_storage_base_type()}}.");
|
|
41
|
+
{% endif %}
|
|
42
|
+
{% endfor %}
|
|
43
|
+
{% endfor %}
|
|
44
|
+
{{ typedef.get_name() }}() = default;
|
|
45
|
+
{{ typedef.get_name() }}(const {{typedef.get_name()}}& rhs )
|
|
46
|
+
{
|
|
47
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0%}
|
|
48
|
+
(void)rhs; // Empty message thus unused.
|
|
49
|
+
{% endif %}
|
|
50
|
+
{% for field in typedef.fields %}
|
|
51
|
+
{% if typedef.optional_fields is defined and field in typedef.optional_fields %}
|
|
52
|
+
if(rhs.has_{{field.get_name()}}())
|
|
53
|
+
{
|
|
54
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
{
|
|
58
|
+
clear_{{ field.get_name() }}();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
{% else %}
|
|
62
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
63
|
+
{% endif %}
|
|
64
|
+
{% endfor %}
|
|
65
|
+
{% for oneof in typedef.oneofs %}
|
|
66
|
+
{{ TypeOneof.assign(oneof)|indent(6) }}
|
|
67
|
+
{% endfor %}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
{{ typedef.get_name() }}(const {{typedef.get_name()}}&& rhs ) noexcept
|
|
71
|
+
{
|
|
72
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0%}
|
|
73
|
+
(void)rhs; // Empty message thus unused.
|
|
74
|
+
{% endif %}
|
|
75
|
+
{% for field in typedef.fields %}
|
|
76
|
+
{% if typedef.optional_fields is defined and field in typedef.optional_fields %}
|
|
77
|
+
if(rhs.has_{{field.get_name()}}())
|
|
78
|
+
{
|
|
79
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
80
|
+
}
|
|
81
|
+
else
|
|
82
|
+
{
|
|
83
|
+
clear_{{ field.get_name() }}();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
{% else %}
|
|
87
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
88
|
+
{% endif %}
|
|
89
|
+
{% endfor %}
|
|
90
|
+
{% for oneof in typedef.oneofs %}
|
|
91
|
+
{{ TypeOneof.assign(oneof)|indent(6) }}
|
|
92
|
+
{% endfor %}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
~{{ typedef.get_name() }}() = default;
|
|
96
|
+
|
|
97
|
+
//! The full protobuf name of this message type, the name used in the type url of a google.protobuf.Any.
|
|
98
|
+
static constexpr char const* MESSAGE_FULL_NAME = "{{ typedef.get_full_name() }}";
|
|
99
|
+
|
|
100
|
+
{% for enum in typedef.nested_enum_definitions %}
|
|
101
|
+
{{ enum.render(environment)|indent(4) }}
|
|
102
|
+
|
|
103
|
+
{% endfor %}
|
|
104
|
+
{% for msg in typedef.nested_msg_definitions %}
|
|
105
|
+
{{ msg.render(environment)|indent(4) }}
|
|
106
|
+
|
|
107
|
+
{% endfor %}
|
|
108
|
+
enum class FieldNumber : uint32_t
|
|
109
|
+
{
|
|
110
|
+
NOT_SET = 0,
|
|
111
|
+
{% for id_set in typedef.field_ids %}
|
|
112
|
+
{{id_set[1]}} = {{id_set[0]}}{{ "," if not loop.last }}
|
|
113
|
+
{% endfor %}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
#ifdef PARTIAL_SERIALIZATION_ENABLED
|
|
117
|
+
//! State depth for partial serialization.
|
|
118
|
+
static constexpr uint32_t STATE_DEPTH = {{ typedef.get_state_depth() }};
|
|
119
|
+
|
|
120
|
+
//! Convenience typedef for the state stack.
|
|
121
|
+
using StateStack = ::EmbeddedProto::MessageStateStack<STATE_DEPTH>;
|
|
122
|
+
#endif
|
|
123
|
+
|
|
124
|
+
{{ typedef.name }}& operator=(const {{ typedef.name }}& rhs)
|
|
125
|
+
{
|
|
126
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0%}
|
|
127
|
+
(void)rhs; // Empty message thus unused.
|
|
128
|
+
{% endif %}
|
|
129
|
+
{% for field in typedef.fields %}
|
|
130
|
+
{% if typedef.optional_fields is defined and field in typedef.optional_fields %}
|
|
131
|
+
if(rhs.has_{{field.get_name()}}())
|
|
132
|
+
{
|
|
133
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
{
|
|
137
|
+
clear_{{ field.get_name() }}();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
{% else %}
|
|
141
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
142
|
+
{% endif %}
|
|
143
|
+
{% endfor %}
|
|
144
|
+
{% for oneof in typedef.oneofs %}
|
|
145
|
+
{{ TypeOneof.assign(oneof)|indent(6) }}
|
|
146
|
+
{% endfor %}
|
|
147
|
+
return *this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
{{ typedef.name }}& operator=(const {{ typedef.name }}&& rhs) noexcept
|
|
151
|
+
{
|
|
152
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0%}
|
|
153
|
+
(void)rhs; // Empty message thus unused.
|
|
154
|
+
{% endif %}
|
|
155
|
+
{% for field in typedef.fields %}
|
|
156
|
+
{% if typedef.optional_fields is defined and field in typedef.optional_fields %}
|
|
157
|
+
if(rhs.has_{{field.get_name()}}())
|
|
158
|
+
{
|
|
159
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
{
|
|
163
|
+
clear_{{ field.get_name() }}();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
{% else %}
|
|
167
|
+
set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
|
|
168
|
+
{% endif %}
|
|
169
|
+
{% endfor %}
|
|
170
|
+
{% for oneof in typedef.oneofs %}
|
|
171
|
+
{{ TypeOneof.assign(oneof)|indent(6) }}
|
|
172
|
+
{% endfor %}
|
|
173
|
+
return *this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
{% for field in typedef.fields %}
|
|
177
|
+
{{ field.render_get_set(environment)|indent(4) }}
|
|
178
|
+
|
|
179
|
+
{% endfor %}
|
|
180
|
+
{% for oneof in typedef.oneofs %}
|
|
181
|
+
FieldNumber get_which_{{oneof.get_name()}}() const { return {{oneof.get_which_oneof()}}; }
|
|
182
|
+
|
|
183
|
+
{% for field in oneof.fields %}
|
|
184
|
+
{{ field.render_get_set(environment)|indent(4) }}
|
|
185
|
+
|
|
186
|
+
{% endfor %}
|
|
187
|
+
{% endfor %}
|
|
188
|
+
|
|
189
|
+
::EmbeddedProto::Error serialize(::EmbeddedProto::WriteBufferInterface& buffer) const override
|
|
190
|
+
{
|
|
191
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0%}
|
|
192
|
+
(void)buffer; // Empty message thus unused.
|
|
193
|
+
{% endif %}
|
|
194
|
+
::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
|
|
195
|
+
|
|
196
|
+
{% for field in typedef.fields %}
|
|
197
|
+
{{ field.render_serialize(environment)|indent(6) }}
|
|
198
|
+
{% endfor %}
|
|
199
|
+
{% for oneof in typedef.oneofs %}
|
|
200
|
+
switch({{oneof.get_which_oneof()}})
|
|
201
|
+
{
|
|
202
|
+
{% for field in oneof.get_fields() %}
|
|
203
|
+
case FieldNumber::{{field.variable_id_name}}:
|
|
204
|
+
{{ field.render_serialize(environment)|indent(10) }}
|
|
205
|
+
break;
|
|
206
|
+
|
|
207
|
+
{% endfor %}
|
|
208
|
+
default:
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
{% endfor %}
|
|
213
|
+
return return_value;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
#ifdef PARTIAL_SERIALIZATION_ENABLED
|
|
217
|
+
::EmbeddedProto::Error deserialize_partial(::EmbeddedProto::ReadBufferInterface& buffer,
|
|
218
|
+
::EmbeddedProto::MessageState& state) override
|
|
219
|
+
{
|
|
220
|
+
::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
|
|
221
|
+
bool continue_deserializing = true;
|
|
222
|
+
|
|
223
|
+
while(continue_deserializing)
|
|
224
|
+
{
|
|
225
|
+
if(::EmbeddedProto::FieldProcessingPhase::TAG == state.phase)
|
|
226
|
+
{
|
|
227
|
+
state.field_id = 0U;
|
|
228
|
+
return_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, state.wire_type, state.field_id);
|
|
229
|
+
if(::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
230
|
+
{
|
|
231
|
+
if(::EmbeddedProto::WireFormatter::WireType::END_GROUP == state.wire_type)
|
|
232
|
+
{
|
|
233
|
+
// End of a DELIMITED (group) message. The END_GROUP tag is consumed and the
|
|
234
|
+
// COMPLETE phase signals completion to the caller owning the framing
|
|
235
|
+
// (deserialize_partial_as_group). Stop the loop here, the completion
|
|
236
|
+
// handling below must not start the next field. Inside a length-delimited
|
|
237
|
+
// field this tag is malformed, deserialize_partial_as_field rejects it.
|
|
238
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
239
|
+
continue_deserializing = false;
|
|
240
|
+
}
|
|
241
|
+
else
|
|
242
|
+
{
|
|
243
|
+
state.phase = (::EmbeddedProto::WireFormatter::WireType::LENGTH_DELIMITED == state.wire_type)
|
|
244
|
+
? ::EmbeddedProto::FieldProcessingPhase::SIZE
|
|
245
|
+
: ::EmbeddedProto::FieldProcessingPhase::DATA;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if((::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
251
|
+
&& ((::EmbeddedProto::FieldProcessingPhase::SIZE == state.phase)
|
|
252
|
+
|| (::EmbeddedProto::FieldProcessingPhase::DATA == state.phase)))
|
|
253
|
+
{
|
|
254
|
+
switch(static_cast<FieldNumber>(state.field_id))
|
|
255
|
+
{
|
|
256
|
+
{% for field in typedef.fields %}
|
|
257
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
258
|
+
{{ field.render_deserialize_partial(environment)|indent(14) }}
|
|
259
|
+
break;
|
|
260
|
+
|
|
261
|
+
{% endfor %}
|
|
262
|
+
{% for oneof in typedef.oneofs %}
|
|
263
|
+
{% for field in oneof.get_fields() %}
|
|
264
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
265
|
+
if(FieldNumber::{{field.get_variable_id_name()}} != {{field.get_which_oneof()}})
|
|
266
|
+
{
|
|
267
|
+
init_{{oneof.get_name()}}(FieldNumber::{{field.get_variable_id_name()}});
|
|
268
|
+
}
|
|
269
|
+
{{ field.render_deserialize_partial(environment)|indent(14) }}
|
|
270
|
+
break;
|
|
271
|
+
|
|
272
|
+
{% endfor %}
|
|
273
|
+
{% endfor %}
|
|
274
|
+
case FieldNumber::NOT_SET:
|
|
275
|
+
return_value = ::EmbeddedProto::Error::INVALID_FIELD_ID;
|
|
276
|
+
break;
|
|
277
|
+
|
|
278
|
+
default:
|
|
279
|
+
return_value = skip_unknown_field_partial(buffer, state);
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if(continue_deserializing
|
|
285
|
+
&& (::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
286
|
+
&& (::EmbeddedProto::FieldProcessingPhase::COMPLETE == state.phase))
|
|
287
|
+
{
|
|
288
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
289
|
+
state.field_id = 0U;
|
|
290
|
+
state.size_value = 0U;
|
|
291
|
+
state.bytes_remaining = 0U;
|
|
292
|
+
state.element_index = 0U;
|
|
293
|
+
if(nullptr != state.child)
|
|
294
|
+
{
|
|
295
|
+
state.child->reset();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
else
|
|
299
|
+
{
|
|
300
|
+
continue_deserializing = false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return return_value;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
::EmbeddedProto::Error serialize_partial(::EmbeddedProto::WriteBufferInterface& buffer,
|
|
308
|
+
::EmbeddedProto::MessageState& state) const override
|
|
309
|
+
{
|
|
310
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0 %}
|
|
311
|
+
(void)buffer; // Empty message thus unused.
|
|
312
|
+
(void)state; // Empty message thus unused.
|
|
313
|
+
{% endif %}
|
|
314
|
+
::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
|
|
315
|
+
|
|
316
|
+
// Get the field id to serialize (from state or start from first field)
|
|
317
|
+
uint32_t field_id = state.field_id;
|
|
318
|
+
|
|
319
|
+
{% set ns = namespace(oneof_field_count=0) %}
|
|
320
|
+
{% for oneof in typedef.oneofs %}
|
|
321
|
+
{% set ns.oneof_field_count = ns.oneof_field_count + (oneof.get_fields()|length) %}
|
|
322
|
+
{% endfor %}
|
|
323
|
+
static constexpr uint32_t STATIC_PARTIAL_ITERATION_BUDGET = {{ (typedef.fields|length) + ns.oneof_field_count + 1 }}U;
|
|
324
|
+
const uint32_t serialized_size_value = max_serialized_size();
|
|
325
|
+
uint32_t max_partial_iterations = STATIC_PARTIAL_ITERATION_BUDGET;
|
|
326
|
+
if((std::numeric_limits<uint32_t>::max() - max_partial_iterations) > serialized_size_value)
|
|
327
|
+
{
|
|
328
|
+
max_partial_iterations += serialized_size_value;
|
|
329
|
+
}
|
|
330
|
+
else
|
|
331
|
+
{
|
|
332
|
+
max_partial_iterations = std::numeric_limits<uint32_t>::max();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Iterate through fields based on state
|
|
336
|
+
for(uint32_t iteration = 0;
|
|
337
|
+
(iteration < max_partial_iterations)
|
|
338
|
+
&& (::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
339
|
+
&& (::EmbeddedProto::FieldProcessingPhase::COMPLETE != state.phase);
|
|
340
|
+
++iteration)
|
|
341
|
+
{
|
|
342
|
+
// Determine which field to serialize based on field_id
|
|
343
|
+
switch(field_id)
|
|
344
|
+
{
|
|
345
|
+
case 0:
|
|
346
|
+
// Start of serialization - initialize state
|
|
347
|
+
{% if typedef.fields|length > 0 %}
|
|
348
|
+
// Start with first regular field.
|
|
349
|
+
// Keep this order aligned with serialize().
|
|
350
|
+
state.field_id = static_cast<uint32_t>(FieldNumber::{{ typedef.fields[0].get_variable_id_name() }});
|
|
351
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
352
|
+
field_id = state.field_id;
|
|
353
|
+
{% elif typedef.oneofs|length > 0 %}
|
|
354
|
+
// No regular fields, start with the set member of the first oneof which has one.
|
|
355
|
+
field_id = first_set_oneof_field(0U);
|
|
356
|
+
state.field_id = field_id;
|
|
357
|
+
state.phase = (0U == field_id) ? ::EmbeddedProto::FieldProcessingPhase::COMPLETE
|
|
358
|
+
: ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
359
|
+
{% else %}
|
|
360
|
+
// No fields to serialize
|
|
361
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
362
|
+
{% endif %}
|
|
363
|
+
break;
|
|
364
|
+
|
|
365
|
+
{% for field in typedef.fields %}
|
|
366
|
+
case static_cast<uint32_t>(FieldNumber::{{field.get_variable_id_name()}}):
|
|
367
|
+
{{ field.render_serialize_partial(environment)|indent(12) }}
|
|
368
|
+
break;
|
|
369
|
+
|
|
370
|
+
{% endfor %}
|
|
371
|
+
{% for oneof in typedef.oneofs %}
|
|
372
|
+
{% for field in oneof.get_fields() %}
|
|
373
|
+
case static_cast<uint32_t>(FieldNumber::{{field.get_variable_id_name()}}):
|
|
374
|
+
// Check if this oneof field is the one that's set
|
|
375
|
+
if(FieldNumber::{{field.get_variable_id_name()}} == {{field.get_which_oneof()}})
|
|
376
|
+
{
|
|
377
|
+
{{ field.render_serialize_partial(environment)|indent(14) }}
|
|
378
|
+
}
|
|
379
|
+
else
|
|
380
|
+
{
|
|
381
|
+
// This oneof field is not set, skip to complete
|
|
382
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
383
|
+
}
|
|
384
|
+
break;
|
|
385
|
+
|
|
386
|
+
{% endfor %}
|
|
387
|
+
{% endfor %}
|
|
388
|
+
default:
|
|
389
|
+
// All fields serialized
|
|
390
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
391
|
+
break;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
// Move to next field when current field is complete
|
|
395
|
+
if((::EmbeddedProto::FieldProcessingPhase::COMPLETE == state.phase) &&
|
|
396
|
+
(::EmbeddedProto::Error::NO_ERRORS == return_value))
|
|
397
|
+
{
|
|
398
|
+
// Reset child state for nested messages before moving to next field
|
|
399
|
+
if(nullptr != state.child)
|
|
400
|
+
{
|
|
401
|
+
state.child->reset();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// The next field starts with a clean count, a packed field otherwise
|
|
405
|
+
// takes over the element index and byte count of the field before it.
|
|
406
|
+
state.element_index = 0U;
|
|
407
|
+
state.bytes_remaining = 0U;
|
|
408
|
+
state.size_value = 0U;
|
|
409
|
+
|
|
410
|
+
// Determine next field using switch-case
|
|
411
|
+
switch(field_id)
|
|
412
|
+
{
|
|
413
|
+
{% for field in typedef.fields %}
|
|
414
|
+
case static_cast<uint32_t>(FieldNumber::{{field.get_variable_id_name()}}):
|
|
415
|
+
{% if not loop.last %}
|
|
416
|
+
field_id = static_cast<uint32_t>(FieldNumber::{{ typedef.fields[loop.index].get_variable_id_name() }});
|
|
417
|
+
state.field_id = field_id;
|
|
418
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
419
|
+
{% elif typedef.oneofs|length > 0 %}
|
|
420
|
+
// Move on to the set member of the first oneof which has one.
|
|
421
|
+
field_id = first_set_oneof_field(0U);
|
|
422
|
+
state.field_id = field_id;
|
|
423
|
+
state.phase = (0U == field_id) ? ::EmbeddedProto::FieldProcessingPhase::COMPLETE
|
|
424
|
+
: ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
425
|
+
{% else %}
|
|
426
|
+
// Last field - we're done
|
|
427
|
+
field_id = 0;
|
|
428
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
429
|
+
{% endif %}
|
|
430
|
+
break;
|
|
431
|
+
|
|
432
|
+
{% endfor %}
|
|
433
|
+
{% for oneof_idx in range(typedef.oneofs|length) %}
|
|
434
|
+
{% set oneof = typedef.oneofs[oneof_idx] %}
|
|
435
|
+
{% for field_idx in range(oneof.get_fields()|length) %}
|
|
436
|
+
{% set field = oneof.get_fields()[field_idx] %}
|
|
437
|
+
case static_cast<uint32_t>(FieldNumber::{{field.get_variable_id_name()}}):
|
|
438
|
+
// Move on to the set member of the next oneof which has one.
|
|
439
|
+
field_id = first_set_oneof_field({{ oneof_idx + 1 }}U);
|
|
440
|
+
state.field_id = field_id;
|
|
441
|
+
state.phase = (0U == field_id) ? ::EmbeddedProto::FieldProcessingPhase::COMPLETE
|
|
442
|
+
: ::EmbeddedProto::FieldProcessingPhase::TAG;
|
|
443
|
+
break;
|
|
444
|
+
|
|
445
|
+
{% endfor %}
|
|
446
|
+
{% endfor %}
|
|
447
|
+
default:
|
|
448
|
+
// Unknown field_id, mark complete
|
|
449
|
+
state.phase = ::EmbeddedProto::FieldProcessingPhase::COMPLETE;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if((::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
456
|
+
&& (::EmbeddedProto::FieldProcessingPhase::COMPLETE != state.phase))
|
|
457
|
+
{
|
|
458
|
+
return_value = ::EmbeddedProto::Error::STATE_MISMATCH;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return return_value;
|
|
462
|
+
}
|
|
463
|
+
#endif
|
|
464
|
+
|
|
465
|
+
::EmbeddedProto::Error deserialize(::EmbeddedProto::ReadBufferInterface& buffer) override
|
|
466
|
+
{
|
|
467
|
+
::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
|
|
468
|
+
FieldNumber id_tag = FieldNumber::NOT_SET;
|
|
469
|
+
|
|
470
|
+
// If we did not already deserialize a tag, obtain the next one. When we did remember a tag
|
|
471
|
+
// have been deserializing a field which was not yet fully received in the read buffer.
|
|
472
|
+
if(0 == deserialize_id_number_)
|
|
473
|
+
{
|
|
474
|
+
return_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, deserialize_wire_type_, deserialize_id_number_);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
bool continue_deserializing = ::EmbeddedProto::Error::NO_ERRORS == return_value;
|
|
478
|
+
while(continue_deserializing)
|
|
479
|
+
{
|
|
480
|
+
// A DELIMITED (group) message terminates at its matching END_GROUP tag,
|
|
481
|
+
// which has just been consumed. For a normal message this never occurs.
|
|
482
|
+
if(::EmbeddedProto::WireFormatter::WireType::END_GROUP == deserialize_wire_type_)
|
|
483
|
+
{
|
|
484
|
+
deserialize_id_number_ = 0;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
id_tag = static_cast<FieldNumber>(deserialize_id_number_);
|
|
489
|
+
switch(id_tag)
|
|
490
|
+
{
|
|
491
|
+
{% for field in typedef.fields %}
|
|
492
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
493
|
+
{{ field.render_deserialize(environment)|indent(12) }}
|
|
494
|
+
break;
|
|
495
|
+
|
|
496
|
+
{% endfor %}
|
|
497
|
+
{% for oneof in typedef.oneofs %}
|
|
498
|
+
{% for field in oneof.get_fields() %}
|
|
499
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
500
|
+
{% endfor %}
|
|
501
|
+
return_value = deserialize_{{oneof.get_name()}}(id_tag, buffer);
|
|
502
|
+
break;
|
|
503
|
+
|
|
504
|
+
{% endfor %}
|
|
505
|
+
case FieldNumber::NOT_SET:
|
|
506
|
+
return_value = ::EmbeddedProto::Error::INVALID_FIELD_ID;
|
|
507
|
+
break;
|
|
508
|
+
|
|
509
|
+
default:
|
|
510
|
+
return_value = skip_unknown_field(buffer, deserialize_wire_type_);
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if(::EmbeddedProto::Error::NO_ERRORS == return_value)
|
|
515
|
+
{
|
|
516
|
+
// Read the next tag but first reset the state such that in the case of an error reading
|
|
517
|
+
// the tag we will try again on the next call of this function.
|
|
518
|
+
deserialize_id_number_ = 0;
|
|
519
|
+
return_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, deserialize_wire_type_, deserialize_id_number_);
|
|
520
|
+
|
|
521
|
+
if(::EmbeddedProto::Error::NO_ERRORS != return_value)
|
|
522
|
+
{
|
|
523
|
+
// If we reached the end of the buffer here assume the message is complete.
|
|
524
|
+
if(::EmbeddedProto::Error::END_OF_BUFFER == return_value)
|
|
525
|
+
{
|
|
526
|
+
return_value = ::EmbeddedProto::Error::NO_ERRORS;
|
|
527
|
+
}
|
|
528
|
+
continue_deserializing = false;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
else
|
|
532
|
+
{
|
|
533
|
+
continue_deserializing = false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return return_value;
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
void clear() override
|
|
541
|
+
{
|
|
542
|
+
deserialize_id_number_ = 0;
|
|
543
|
+
deserialize_wire_type_ = ::EmbeddedProto::WireFormatter::WireType::VARINT;
|
|
544
|
+
{% for field in typedef.fields %}
|
|
545
|
+
clear_{{field.get_name()}}();
|
|
546
|
+
{% endfor %}
|
|
547
|
+
{% for oneof in typedef.oneofs %}
|
|
548
|
+
clear_{{oneof.get_name()}}();
|
|
549
|
+
{% endfor %}
|
|
550
|
+
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
#ifndef DISABLE_FIELD_NUMBER_TO_NAME
|
|
554
|
+
|
|
555
|
+
static char const* field_number_to_name(const FieldNumber fieldNumber)
|
|
556
|
+
{
|
|
557
|
+
char const* name = nullptr;
|
|
558
|
+
switch(fieldNumber)
|
|
559
|
+
{
|
|
560
|
+
{% for field in typedef.fields %}
|
|
561
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
562
|
+
name = {{field.get_name()|upper}}_NAME;
|
|
563
|
+
break;
|
|
564
|
+
{% endfor %}
|
|
565
|
+
{% for oneof in typedef.oneofs %}
|
|
566
|
+
{% for field in oneof.fields %}
|
|
567
|
+
case FieldNumber::{{field.get_variable_id_name()}}:
|
|
568
|
+
name = {{field.get_name()|upper}}_NAME;
|
|
569
|
+
break;
|
|
570
|
+
{% endfor %}
|
|
571
|
+
{% endfor %}
|
|
572
|
+
default:
|
|
573
|
+
name = "Invalid FieldNumber";
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
return name;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
#endif
|
|
580
|
+
|
|
581
|
+
//! Calculate the maximum number of bytes required to serialize this type of message.
|
|
582
|
+
/*!
|
|
583
|
+
This function does not take into account a possible id of this message object is self.
|
|
584
|
+
\return The number of bytes required at most to serialize this message type.
|
|
585
|
+
*/
|
|
586
|
+
static constexpr uint32_t max_serialized_size()
|
|
587
|
+
{
|
|
588
|
+
using namespace ::EmbeddedProto;
|
|
589
|
+
return
|
|
590
|
+
{% for field in typedef.fields %}
|
|
591
|
+
{{"+ " if not loop.first }}{{field.get_type()}}::max_serialized_size(static_cast<uint32_t>(FieldNumber::{{field.variable_id_name}}))
|
|
592
|
+
{% endfor %}
|
|
593
|
+
{% for oneof in typedef.oneofs %}
|
|
594
|
+
{{"+ " if not loop.first or typedef.fields|length != 0}}max_serialized_size_{{oneof.get_name()}}()
|
|
595
|
+
{% endfor %}
|
|
596
|
+
{% if typedef.fields|length == 0 and typedef.oneofs|length == 0 %}
|
|
597
|
+
0
|
|
598
|
+
{% endif %}
|
|
599
|
+
;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
//! Calculate the maximum number of bytes required to serialize this message including the field id number and tag.
|
|
603
|
+
/*!
|
|
604
|
+
\return The number of bytes required at most to serialize this message type.
|
|
605
|
+
*/
|
|
606
|
+
static constexpr uint32_t max_serialized_size(const uint32_t field_number)
|
|
607
|
+
{
|
|
608
|
+
using namespace ::EmbeddedProto;
|
|
609
|
+
return WireFormatter::VarintSize(WireFormatter::MakeTag(field_number, WireFormatter::WireType::LENGTH_DELIMITED)) // Size of the tag
|
|
610
|
+
+ WireFormatter::VarintSize(max_serialized_size()) // Length delimted value
|
|
611
|
+
+ max_serialized_size(); // Length of the serialized content
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
#ifdef MSG_TO_STRING
|
|
615
|
+
|
|
616
|
+
::EmbeddedProto::string_view to_string(::EmbeddedProto::string_view& str) const
|
|
617
|
+
{
|
|
618
|
+
return this->to_string(str, 0, nullptr, true);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
::EmbeddedProto::string_view to_string(::EmbeddedProto::string_view& str, const uint32_t indent_level, char const* name, const bool first_field) const override
|
|
622
|
+
{
|
|
623
|
+
::EmbeddedProto::string_view left_chars = str;
|
|
624
|
+
int32_t n_chars_used = 0;
|
|
625
|
+
|
|
626
|
+
if(!first_field)
|
|
627
|
+
{
|
|
628
|
+
// Add a comma behind the previous field.
|
|
629
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, ",\n");
|
|
630
|
+
if(0 < n_chars_used)
|
|
631
|
+
{
|
|
632
|
+
// Update the character pointer and characters left in the array.
|
|
633
|
+
const int32_t actual_chars_used = EmbeddedProto::min(n_chars_used, left_chars.size);
|
|
634
|
+
left_chars.data += actual_chars_used;
|
|
635
|
+
left_chars.size -= actual_chars_used;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
if(nullptr != name)
|
|
640
|
+
{
|
|
641
|
+
if( 0 == indent_level)
|
|
642
|
+
{
|
|
643
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "\"%s\": {\n", name);
|
|
644
|
+
}
|
|
645
|
+
else
|
|
646
|
+
{
|
|
647
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "%*s\"%s\": {\n", indent_level, " ", name);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
else
|
|
651
|
+
{
|
|
652
|
+
if( 0 == indent_level)
|
|
653
|
+
{
|
|
654
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "{\n");
|
|
655
|
+
}
|
|
656
|
+
else
|
|
657
|
+
{
|
|
658
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "%*s{\n", indent_level, " ");
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if(0 < n_chars_used)
|
|
663
|
+
{
|
|
664
|
+
const int32_t actual_chars_used = EmbeddedProto::min(n_chars_used, left_chars.size);
|
|
665
|
+
left_chars.data += actual_chars_used;
|
|
666
|
+
left_chars.size -= actual_chars_used;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
{% for field in typedef.fields %}
|
|
670
|
+
{%if "FieldErrorRecursive" != field.descriptor.type_name %}{# Test if this is an FieldErrorRecursive #}
|
|
671
|
+
left_chars = {{field.get_variable_name()}}.to_string(left_chars, indent_level + 2, {{field.get_name()|upper}}_NAME, {{ loop.first|lower }});
|
|
672
|
+
{% endif %}
|
|
673
|
+
{% endfor %}
|
|
674
|
+
{% for oneof in typedef.oneofs %}
|
|
675
|
+
left_chars = to_string_{{oneof.get_name()}}(left_chars, indent_level + 2, {{((typedef.fields|length == 0) and loop.first)|lower }});
|
|
676
|
+
{% endfor %}
|
|
677
|
+
if( 0 == indent_level)
|
|
678
|
+
{
|
|
679
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "\n}");
|
|
680
|
+
}
|
|
681
|
+
else
|
|
682
|
+
{
|
|
683
|
+
n_chars_used = snprintf(left_chars.data, left_chars.size, "\n%*s}", indent_level, " ");
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if(0 < n_chars_used)
|
|
687
|
+
{
|
|
688
|
+
const int32_t actual_chars_used = EmbeddedProto::min(n_chars_used, left_chars.size);
|
|
689
|
+
left_chars.data += actual_chars_used;
|
|
690
|
+
left_chars.size -= actual_chars_used;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return left_chars;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
#endif // End of MSG_TO_STRING
|
|
697
|
+
|
|
698
|
+
private:
|
|
699
|
+
|
|
700
|
+
{% if typedef.oneofs|length > 0 %}
|
|
701
|
+
#ifdef PARTIAL_SERIALIZATION_ENABLED
|
|
702
|
+
//! The field number of the set member of the first oneof at or after the given oneof index, zero when none is set.
|
|
703
|
+
uint32_t first_set_oneof_field(const uint32_t oneof_index) const
|
|
704
|
+
{
|
|
705
|
+
uint32_t field_number = 0U;
|
|
706
|
+
{% for oneof in typedef.oneofs %}
|
|
707
|
+
if((0U == field_number) && (oneof_index <= {{ loop.index0 }}U))
|
|
708
|
+
{
|
|
709
|
+
field_number = static_cast<uint32_t>({{ oneof.get_which_oneof() }});
|
|
710
|
+
}
|
|
711
|
+
{% endfor %}
|
|
712
|
+
return field_number;
|
|
713
|
+
}
|
|
714
|
+
#endif // PARTIAL_SERIALIZATION_ENABLED
|
|
715
|
+
{% endif %}
|
|
716
|
+
|
|
717
|
+
{% if typedef.optional_fields is defined and typedef.optional_fields|length > 0 %}
|
|
718
|
+
// Define constants for tracking the presence of fields.
|
|
719
|
+
// Use a struct to scope the variables from user fields as namespaces are not allowed within classes.
|
|
720
|
+
struct presence
|
|
721
|
+
{
|
|
722
|
+
// An enumeration with all the fields for which presence has to be tracked.
|
|
723
|
+
enum class fields : uint32_t
|
|
724
|
+
{
|
|
725
|
+
{% for field in typedef.optional_fields %}
|
|
726
|
+
{{field.get_name().upper()}}{{ "," if not loop.last }}
|
|
727
|
+
{% endfor %}
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// The number of fields for which presence has to be tracked.
|
|
731
|
+
static constexpr uint32_t N_FIELDS = {{typedef.optional_fields|length}};
|
|
732
|
+
|
|
733
|
+
// Which type are we using to track presence.
|
|
734
|
+
using TYPE = uint32_t;
|
|
735
|
+
|
|
736
|
+
// How many bits are there in the presence type.
|
|
737
|
+
static constexpr uint32_t N_BITS = std::numeric_limits<TYPE>::digits;
|
|
738
|
+
|
|
739
|
+
// How many variables of TYPE do we need to bit mask all presence fields.
|
|
740
|
+
static constexpr uint32_t SIZE = (N_FIELDS / N_BITS) + ((N_FIELDS % N_BITS) > 0 ? 1 : 0);
|
|
741
|
+
|
|
742
|
+
// Obtain the index of a given field in the presence array.
|
|
743
|
+
static constexpr uint32_t index(const fields& field) { return static_cast<uint32_t>(field) / N_BITS; }
|
|
744
|
+
|
|
745
|
+
// Obtain the bit mask for the given field assuming we are at the correct index in the presence array.
|
|
746
|
+
static constexpr TYPE mask(const fields& field)
|
|
747
|
+
{
|
|
748
|
+
return static_cast<uint32_t>(0x01) << (static_cast<uint32_t>(field) % N_BITS);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
|
|
752
|
+
// Create an array in which the presence flags are stored.
|
|
753
|
+
typename presence::TYPE presence_[presence::SIZE] = {0};
|
|
754
|
+
{% endif %}
|
|
755
|
+
|
|
756
|
+
//! The last id number deserialized from a tag. This is used as the internal state of the deserialize function.
|
|
757
|
+
uint32_t deserialize_id_number_ = 0;
|
|
758
|
+
//! The last wire type deserialized from a tag. This is used as the internal state of the deserialize function.
|
|
759
|
+
::EmbeddedProto::WireFormatter::WireType deserialize_wire_type_ = ::EmbeddedProto::WireFormatter::WireType::VARINT;
|
|
760
|
+
|
|
761
|
+
{% for field in typedef.fields %}
|
|
762
|
+
{% if field.get_default_value() %}
|
|
763
|
+
{{field.get_type()}} {{field.get_variable_name()}} = {{field.get_default_value()}};
|
|
764
|
+
{% else %}
|
|
765
|
+
{{field.get_type()}} {{field.get_variable_name()}};
|
|
766
|
+
{% endif %}
|
|
767
|
+
{% endfor %}
|
|
768
|
+
|
|
769
|
+
{% for oneof in typedef.oneofs %}
|
|
770
|
+
FieldNumber {{oneof.get_which_oneof()}} = FieldNumber::NOT_SET;
|
|
771
|
+
union {{oneof.get_name()}}
|
|
772
|
+
{
|
|
773
|
+
{{oneof.get_name()}}() {}
|
|
774
|
+
~{{oneof.get_name()}}() {}
|
|
775
|
+
{% for field in oneof.fields %}
|
|
776
|
+
{# Here we use the field name variable instead of the get_ function as the get function will add the oneof
|
|
777
|
+
name. This is the only place where this is required. #}
|
|
778
|
+
{{field.get_type()}} {{field.variable_name}};
|
|
779
|
+
{% endfor %}
|
|
780
|
+
};
|
|
781
|
+
{{oneof.get_name()}} {{oneof.get_variable_name()}};
|
|
782
|
+
|
|
783
|
+
{{ TypeOneof.init(oneof)|indent(6) }}
|
|
784
|
+
{{ TypeOneof.clear(oneof)|indent(6) }}
|
|
785
|
+
{{ TypeOneof.deserialize(oneof, environment)|indent(6) }}
|
|
786
|
+
{{ TypeOneof.max_serialized_size(oneof)|indent(6) }}
|
|
787
|
+
#ifdef MSG_TO_STRING
|
|
788
|
+
{{ TypeOneof.to_string(oneof)|indent(6) }}
|
|
789
|
+
#endif // End of MSG_TO_STRING
|
|
790
|
+
{% endfor %}
|
|
791
|
+
};
|