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,367 @@
|
|
|
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
|
+
|
|
24
|
+
#ifndef _REPEATED_FIELD_SIZE_H_
|
|
25
|
+
#define _REPEATED_FIELD_SIZE_H_
|
|
26
|
+
|
|
27
|
+
#include "RepeatedField.h"
|
|
28
|
+
#include "EmptyArray.h"
|
|
29
|
+
#include "Errors.h"
|
|
30
|
+
|
|
31
|
+
#include <cstdint>
|
|
32
|
+
#include <cstring>
|
|
33
|
+
#include <algorithm>
|
|
34
|
+
#include <array>
|
|
35
|
+
#include <type_traits>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
namespace EmbeddedProto
|
|
39
|
+
{
|
|
40
|
+
|
|
41
|
+
//! A template class that actually holds some data.
|
|
42
|
+
/*!
|
|
43
|
+
This is a separate class to make it possible to not have the size defined in every function or
|
|
44
|
+
class using this type of object.
|
|
45
|
+
*/
|
|
46
|
+
template<class DATA_TYPE, uint32_t MAX_LENGTH>
|
|
47
|
+
class RepeatedFieldFixedSize : public RepeatedField<DATA_TYPE>
|
|
48
|
+
{
|
|
49
|
+
static constexpr uint32_t BYTES_PER_ELEMENT = sizeof(DATA_TYPE);
|
|
50
|
+
|
|
51
|
+
//! Element storage, an empty stand-in when MAX_LENGTH is zero, see EmptyArray.
|
|
52
|
+
using Storage = typename std::conditional<(0U < MAX_LENGTH),
|
|
53
|
+
std::array<DATA_TYPE, MAX_LENGTH>,
|
|
54
|
+
internal::EmptyArray<DATA_TYPE>>::type;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
|
|
58
|
+
RepeatedFieldFixedSize() = default;
|
|
59
|
+
~RepeatedFieldFixedSize() = default;
|
|
60
|
+
|
|
61
|
+
RepeatedFieldFixedSize(const RepeatedFieldFixedSize<DATA_TYPE, MAX_LENGTH>& rhs) :
|
|
62
|
+
current_length_(rhs.get_length()),
|
|
63
|
+
data_(rhs.get_data_const())
|
|
64
|
+
{
|
|
65
|
+
// Use the initializer list.
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
template<uint32_t MAX_LENGTH_RHS, typename std::enable_if<(MAX_LENGTH_RHS < MAX_LENGTH), int>::type = 0>
|
|
69
|
+
explicit RepeatedFieldFixedSize(const RepeatedFieldFixedSize<DATA_TYPE, MAX_LENGTH_RHS>& rhs) :
|
|
70
|
+
current_length_(rhs.get_length())
|
|
71
|
+
{
|
|
72
|
+
const auto& rhs_data = rhs.get_data_const();
|
|
73
|
+
std::copy(rhs_data.begin(), rhs_data.end(), data_.begin());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
template<uint32_t MAX_LENGTH_RHS, typename std::enable_if<(MAX_LENGTH_RHS < MAX_LENGTH), int>::type = 0>
|
|
77
|
+
explicit RepeatedFieldFixedSize(const RepeatedFieldFixedSize<DATA_TYPE, MAX_LENGTH_RHS>&& rhs) :
|
|
78
|
+
current_length_(rhs.get_length())
|
|
79
|
+
{
|
|
80
|
+
const auto& rhs_data = rhs.get_data_const();
|
|
81
|
+
std::copy(rhs_data.begin(), rhs_data.end(), data_.begin());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//! Assign one repieted field to the other, but only when the length and type matches.
|
|
85
|
+
RepeatedFieldFixedSize<DATA_TYPE, MAX_LENGTH>& operator=(const
|
|
86
|
+
RepeatedFieldFixedSize<DATA_TYPE, MAX_LENGTH>& rhs)
|
|
87
|
+
{
|
|
88
|
+
for(uint32_t i = 0; i < rhs.get_length(); ++i)
|
|
89
|
+
{
|
|
90
|
+
data_[i] = rhs.get_const(i);
|
|
91
|
+
}
|
|
92
|
+
current_length_ = rhs.get_length();
|
|
93
|
+
|
|
94
|
+
return *this;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//! Obtain the total number of DATA_TYPE items in the array.
|
|
98
|
+
uint32_t get_length() const override { return current_length_; }
|
|
99
|
+
|
|
100
|
+
//! Obtain the maximum number of DATA_TYPE items which can at most be stored in the array.
|
|
101
|
+
uint32_t get_max_length() const override { return MAX_LENGTH; }
|
|
102
|
+
|
|
103
|
+
//! Obtain the total number of bytes currently stored in the array.
|
|
104
|
+
uint32_t get_size() const override { return BYTES_PER_ELEMENT * current_length_; }
|
|
105
|
+
|
|
106
|
+
//! Obtain the maximum number of bytes which can at most be stored in the array.
|
|
107
|
+
uint32_t get_max_size() const override { return BYTES_PER_ELEMENT * MAX_LENGTH; }
|
|
108
|
+
|
|
109
|
+
DATA_TYPE& get(uint32_t index) override
|
|
110
|
+
{
|
|
111
|
+
uint32_t limited_index = clamp_index(index);
|
|
112
|
+
// Check if we need to update the number of elements in the array.
|
|
113
|
+
if(limited_index >= current_length_) {
|
|
114
|
+
current_length_ = std::min(limited_index + 1U, MAX_LENGTH);
|
|
115
|
+
}
|
|
116
|
+
return data_[limited_index];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const DATA_TYPE& get_const(uint32_t index) const override
|
|
120
|
+
{
|
|
121
|
+
uint32_t limited_index = clamp_index(index);
|
|
122
|
+
return data_[limited_index];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Error get_const(const uint32_t index, DATA_TYPE& value) const override
|
|
126
|
+
{
|
|
127
|
+
Error result = Error::NO_ERRORS;
|
|
128
|
+
if(index < current_length_)
|
|
129
|
+
{
|
|
130
|
+
value = data_[index];
|
|
131
|
+
}
|
|
132
|
+
else
|
|
133
|
+
{
|
|
134
|
+
result = Error::INDEX_OUT_OF_BOUND;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void set(uint32_t index, const DATA_TYPE& value) override
|
|
140
|
+
{
|
|
141
|
+
uint32_t limited_index = clamp_index(index);
|
|
142
|
+
// Check if we need to update the number of elements in the array.
|
|
143
|
+
if(limited_index >= current_length_) {
|
|
144
|
+
current_length_ = std::min(limited_index + 1U, MAX_LENGTH);
|
|
145
|
+
}
|
|
146
|
+
data_[limited_index] = value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//! Keep the pointer and length form of set_data() reachable next to the override below.
|
|
150
|
+
using RepeatedField<DATA_TYPE>::set_data;
|
|
151
|
+
|
|
152
|
+
Error set_data(const array_view<const DATA_TYPE>& data) override
|
|
153
|
+
{
|
|
154
|
+
Error return_value = Error::NO_ERRORS;
|
|
155
|
+
if(MAX_LENGTH >= data.size)
|
|
156
|
+
{
|
|
157
|
+
for(uint32_t i = 0; i < data.size; ++i)
|
|
158
|
+
{
|
|
159
|
+
data_[i] = data.data[i];
|
|
160
|
+
}
|
|
161
|
+
current_length_ = data.size;
|
|
162
|
+
}
|
|
163
|
+
else
|
|
164
|
+
{
|
|
165
|
+
return_value = Error::ARRAY_FULL;
|
|
166
|
+
}
|
|
167
|
+
return return_value;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
Error add(const DATA_TYPE& value) override
|
|
171
|
+
{
|
|
172
|
+
Error return_value = Error::NO_ERRORS;
|
|
173
|
+
if(MAX_LENGTH > current_length_)
|
|
174
|
+
{
|
|
175
|
+
data_[current_length_] = value;
|
|
176
|
+
++current_length_;
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
{
|
|
180
|
+
return_value = Error::ARRAY_FULL;
|
|
181
|
+
}
|
|
182
|
+
return return_value;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
Error erase(const uint32_t index) override
|
|
186
|
+
{
|
|
187
|
+
Error return_value = Error::INDEX_OUT_OF_BOUND;
|
|
188
|
+
if(index < current_length_)
|
|
189
|
+
{
|
|
190
|
+
for(uint32_t i = index; (i + 1U) < current_length_; ++i)
|
|
191
|
+
{
|
|
192
|
+
data_[i] = data_[i + 1U];
|
|
193
|
+
}
|
|
194
|
+
--current_length_;
|
|
195
|
+
// Leave no stale copy of the last element behind in the vacated slot.
|
|
196
|
+
data_[current_length_].clear();
|
|
197
|
+
return_value = Error::NO_ERRORS;
|
|
198
|
+
}
|
|
199
|
+
return return_value;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
void clear() override
|
|
203
|
+
{
|
|
204
|
+
for(auto& d : data_)
|
|
205
|
+
{
|
|
206
|
+
d.clear();
|
|
207
|
+
}
|
|
208
|
+
current_length_ = 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
//! Serialize all elements (packed), batching fixed-width payloads.
|
|
212
|
+
/*!
|
|
213
|
+
For packed fixed-width scalar element types (fixed32/sfixed32/float and
|
|
214
|
+
fixed64/sfixed64/double) the contiguous backing array is written to the
|
|
215
|
+
buffer as a single whole-block push(const_bytes_view) on a little-endian
|
|
216
|
+
target instead of one virtual call per byte. All other element types
|
|
217
|
+
fall back to the element-by-element base implementation.
|
|
218
|
+
*/
|
|
219
|
+
Error serialize(WriteBufferInterface& buffer) const override
|
|
220
|
+
{
|
|
221
|
+
return serialize_packed_(buffer,
|
|
222
|
+
std::integral_constant<bool,
|
|
223
|
+
RepeatedField<DATA_TYPE>::REPEATED_FIELD_IS_PACKED
|
|
224
|
+
&& ::EmbeddedProto::internal::PackedFixedTraits<DATA_TYPE>::is_fixed_width>{});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
//! Deserialize all elements, batching packed fixed-width payloads into one read.
|
|
228
|
+
/*!
|
|
229
|
+
Reuses the existing Field::deserialize vtable slot (no new virtual). For
|
|
230
|
+
packed fixed-width scalar element types the whole little-endian block is
|
|
231
|
+
read straight into the contiguous backing array with a single batched
|
|
232
|
+
pop, instead of one virtual call per byte. Misaligned / oversized /
|
|
233
|
+
truncated blocks, and non-fixed-width / non-packed element types, fall
|
|
234
|
+
back to the base implementation so their existing behaviour is preserved.
|
|
235
|
+
*/
|
|
236
|
+
Error deserialize(::EmbeddedProto::ReadBufferInterface& buffer) override
|
|
237
|
+
{
|
|
238
|
+
return deserialize_(buffer,
|
|
239
|
+
std::integral_constant<bool,
|
|
240
|
+
RepeatedField<DATA_TYPE>::REPEATED_FIELD_IS_PACKED
|
|
241
|
+
&& ::EmbeddedProto::internal::PackedFixedTraits<DATA_TYPE>::is_fixed_width>{});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
//! Return a reference to the internal data storage array.
|
|
245
|
+
const Storage& get_data_const() const { return data_; }
|
|
246
|
+
|
|
247
|
+
//! When serialized with the most unfavrouble value how much bytes does this field need.
|
|
248
|
+
/*!
|
|
249
|
+
This function takes into account the field number and tag combination.
|
|
250
|
+
\param[in] field_number We need to include the field number. This because large field numbers require more bytes.
|
|
251
|
+
\return The number of bytes required at most.
|
|
252
|
+
*/
|
|
253
|
+
static constexpr uint32_t max_serialized_size(const uint32_t field_number)
|
|
254
|
+
{
|
|
255
|
+
return RepeatedField<DATA_TYPE>::REPEATED_FIELD_IS_PACKED
|
|
256
|
+
? max_packed_serialized_size(field_number)
|
|
257
|
+
: max_unpacked_serialized_size(field_number);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
static constexpr uint32_t max_packed_serialized_size(const uint32_t field_number)
|
|
261
|
+
{
|
|
262
|
+
return WireFormatter::VarintSize(WireFormatter::MakeTag(field_number,
|
|
263
|
+
WireFormatter::WireType::LENGTH_DELIMITED))
|
|
264
|
+
+ WireFormatter::VarintSize(MAX_LENGTH)
|
|
265
|
+
+ (MAX_LENGTH * DATA_TYPE::max_serialized_size());
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static constexpr uint32_t max_unpacked_serialized_size(const uint32_t field_number)
|
|
269
|
+
{
|
|
270
|
+
return MAX_LENGTH * DATA_TYPE::max_serialized_size(field_number);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
private:
|
|
275
|
+
|
|
276
|
+
//! Whole-block batched deserialize for packed fixed-width scalar elements.
|
|
277
|
+
Error deserialize_(::EmbeddedProto::ReadBufferInterface& buffer, std::true_type)
|
|
278
|
+
{
|
|
279
|
+
#if EMBEDDED_PROTO_LITTLE_ENDIAN
|
|
280
|
+
using VAR = typename ::EmbeddedProto::internal::PackedFixedTraits<DATA_TYPE>::scalar_type;
|
|
281
|
+
static_assert(sizeof(DATA_TYPE) == sizeof(VAR),
|
|
282
|
+
"Fixed-width field must be layout-compatible with its scalar type.");
|
|
283
|
+
static_assert(std::is_standard_layout<DATA_TYPE>::value,
|
|
284
|
+
"Fixed-width field must be standard-layout for block deserialization.");
|
|
285
|
+
|
|
286
|
+
uint32_t size = 0;
|
|
287
|
+
Error return_value = WireFormatter::DeserializeVarint(buffer, size);
|
|
288
|
+
const uint32_t count = size / BYTES_PER_ELEMENT;
|
|
289
|
+
|
|
290
|
+
// Fast path: a whole, correctly sized block that fits in the array and is
|
|
291
|
+
// entirely present in the buffer is read in a single batched pop. Values
|
|
292
|
+
// are appended after any already-decoded elements (repeated packed fields
|
|
293
|
+
// may appear more than once and concatenate).
|
|
294
|
+
if((Error::NO_ERRORS == return_value)
|
|
295
|
+
&& (0U == (size % BYTES_PER_ELEMENT))
|
|
296
|
+
&& ((current_length_ + count) <= MAX_LENGTH)
|
|
297
|
+
&& (buffer.get_size() >= size))
|
|
298
|
+
{
|
|
299
|
+
VAR* const raw = reinterpret_cast<VAR*>(data_.data()) + current_length_;
|
|
300
|
+
return_value = WireFormatter::DeserializeFixedArrayNoTag(array_view<VAR>{raw, count}, buffer);
|
|
301
|
+
if(Error::NO_ERRORS == return_value)
|
|
302
|
+
{
|
|
303
|
+
current_length_ += count;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
{
|
|
308
|
+
// Misaligned / oversized / truncated block: defer to the base loop which
|
|
309
|
+
// preserves the previous lenient handling of such input.
|
|
310
|
+
ReadBufferSection section(buffer, size);
|
|
311
|
+
return_value = this->deserialize_packed_section(section);
|
|
312
|
+
}
|
|
313
|
+
return return_value;
|
|
314
|
+
#else
|
|
315
|
+
// Qualified base call (non-virtual) reads the size varint fresh and runs
|
|
316
|
+
// the element-by-element loop; no recursion back into this override.
|
|
317
|
+
return RepeatedField<DATA_TYPE>::deserialize(buffer);
|
|
318
|
+
#endif
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
//! Non-fixed-width / non-packed element types keep the base implementation.
|
|
322
|
+
Error deserialize_(::EmbeddedProto::ReadBufferInterface& buffer, std::false_type)
|
|
323
|
+
{
|
|
324
|
+
// Qualified base call (non-virtual): no recursion into this override.
|
|
325
|
+
return RepeatedField<DATA_TYPE>::deserialize(buffer);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
//! Whole-block batched serialize for packed fixed-width scalar elements.
|
|
329
|
+
Error serialize_packed_(WriteBufferInterface& buffer, std::true_type) const
|
|
330
|
+
{
|
|
331
|
+
using VAR = typename ::EmbeddedProto::internal::PackedFixedTraits<DATA_TYPE>::scalar_type;
|
|
332
|
+
static_assert(sizeof(DATA_TYPE) == sizeof(VAR),
|
|
333
|
+
"Fixed-width field must be layout-compatible with its scalar type.");
|
|
334
|
+
static_assert(std::is_standard_layout<DATA_TYPE>::value,
|
|
335
|
+
"Fixed-width field must be standard-layout for block serialization.");
|
|
336
|
+
Error return_value = Error::NO_ERRORS;
|
|
337
|
+
if(0U < current_length_)
|
|
338
|
+
{
|
|
339
|
+
const VAR* const raw = reinterpret_cast<const VAR*>(data_.data());
|
|
340
|
+
return_value = WireFormatter::SerializeFixedArrayNoTag(array_view<const VAR>{raw, current_length_},
|
|
341
|
+
buffer);
|
|
342
|
+
}
|
|
343
|
+
return return_value;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
//! Fallback to the element-by-element base implementation.
|
|
347
|
+
Error serialize_packed_(WriteBufferInterface& buffer, std::false_type) const
|
|
348
|
+
{
|
|
349
|
+
return RepeatedField<DATA_TYPE>::serialize(buffer);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//! Number of item in the data array.
|
|
353
|
+
uint32_t current_length_ = 0;
|
|
354
|
+
|
|
355
|
+
//! The actual data
|
|
356
|
+
Storage data_ = {};
|
|
357
|
+
|
|
358
|
+
//! Clamp an index to the last element, zero when there is no element at all.
|
|
359
|
+
static constexpr uint32_t clamp_index(const uint32_t index)
|
|
360
|
+
{
|
|
361
|
+
return (0U < MAX_LENGTH) ? std::min(index, MAX_LENGTH - 1U) : 0U;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
} // End of namespace EmbeddedProto
|
|
366
|
+
|
|
367
|
+
#endif // End of _REPEATED_FIELD_SIZE_H_
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
24
|
+
#ifndef _EMBEDDED_PROTO_VERSION_H_
|
|
25
|
+
#define _EMBEDDED_PROTO_VERSION_H_
|
|
26
|
+
|
|
27
|
+
//! The major version number of the Embedded Proto library.
|
|
28
|
+
#define EMBEDDEDPROTO_VERSION_MAJOR 4
|
|
29
|
+
|
|
30
|
+
//! The minor version number of the Embedded Proto library.
|
|
31
|
+
#define EMBEDDEDPROTO_VERSION_MINOR 0
|
|
32
|
+
|
|
33
|
+
//! The patch version number of the Embedded Proto library.
|
|
34
|
+
#define EMBEDDEDPROTO_VERSION_PATCH 0
|
|
35
|
+
|
|
36
|
+
//! The complete version string of the Embedded Proto library.
|
|
37
|
+
#define EMBEDDEDPROTO_VERSION_STRING "4.0.0b1"
|
|
38
|
+
|
|
39
|
+
#endif // _EMBEDDED_PROTO_VERSION_H_
|