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,412 @@
|
|
|
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 _FUNCTIONAL_H_
|
|
25
|
+
#define _FUNCTIONAL_H_
|
|
26
|
+
|
|
27
|
+
#include <type_traits>
|
|
28
|
+
|
|
29
|
+
namespace EmbeddedProto
|
|
30
|
+
{
|
|
31
|
+
|
|
32
|
+
//! Lightweight zero-allocation callback wrapper.
|
|
33
|
+
/*!
|
|
34
|
+
This class stores callbacks without dynamic allocation and is intended for
|
|
35
|
+
small embedded systems.
|
|
36
|
+
|
|
37
|
+
\tparam Signature Callback signature.
|
|
38
|
+
*/
|
|
39
|
+
template<typename Signature>
|
|
40
|
+
class Functional;
|
|
41
|
+
|
|
42
|
+
//! Specialization for callbacks with return value.
|
|
43
|
+
template<typename R, typename... Args>
|
|
44
|
+
class Functional<R(Args...)>
|
|
45
|
+
{
|
|
46
|
+
public:
|
|
47
|
+
using FunctionCallback = R (*)(Args...);
|
|
48
|
+
using ContextCallback = R (*)(void* context, Args...);
|
|
49
|
+
|
|
50
|
+
Functional() = default;
|
|
51
|
+
~Functional() = default;
|
|
52
|
+
|
|
53
|
+
//! Remove any bound callback.
|
|
54
|
+
void clear()
|
|
55
|
+
{
|
|
56
|
+
context_ = nullptr;
|
|
57
|
+
callback_.context_callback_ = nullptr;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//! Check if a callback is bound.
|
|
61
|
+
bool is_set() const
|
|
62
|
+
{
|
|
63
|
+
bool result = false;
|
|
64
|
+
if(nullptr != context_)
|
|
65
|
+
{
|
|
66
|
+
result = (nullptr != callback_.context_callback_);
|
|
67
|
+
}
|
|
68
|
+
else
|
|
69
|
+
{
|
|
70
|
+
result = (nullptr != callback_.function_callback_);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//! Bind a plain C/C++ function pointer.
|
|
76
|
+
void set(FunctionCallback function)
|
|
77
|
+
{
|
|
78
|
+
context_ = nullptr;
|
|
79
|
+
callback_.function_callback_ = function;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//! Bind a C style callback with context pointer.
|
|
83
|
+
void set(ContextCallback function, void* context)
|
|
84
|
+
{
|
|
85
|
+
if(nullptr != function)
|
|
86
|
+
{
|
|
87
|
+
callback_.context_callback_ = function;
|
|
88
|
+
context_ = (nullptr == context) ? null_context_sentinel() : context;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
{
|
|
92
|
+
context_ = nullptr;
|
|
93
|
+
callback_.context_callback_ = nullptr;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//! Bind a member function (non-const) at compile time.
|
|
98
|
+
template<class T, R (T::*METHOD)(Args...)>
|
|
99
|
+
void set(T* instance)
|
|
100
|
+
{
|
|
101
|
+
context_ = instance;
|
|
102
|
+
callback_.context_callback_ = &member_thunk<T, METHOD>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//! Bind a member function (const) at compile time.
|
|
106
|
+
template<class T, R (T::*METHOD)(Args...) const>
|
|
107
|
+
void set(const T* instance)
|
|
108
|
+
{
|
|
109
|
+
context_ = const_cast<T*>(instance);
|
|
110
|
+
callback_.context_callback_ = &const_member_thunk<T, METHOD>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//! Bind a callable object by reference (non-owning).
|
|
114
|
+
template<class Callable>
|
|
115
|
+
void set(Callable& callable,
|
|
116
|
+
typename std::enable_if<!std::is_same<Callable, Functional<R(Args...)>>::value>::type* = nullptr)
|
|
117
|
+
{
|
|
118
|
+
context_ = &callable;
|
|
119
|
+
callback_.context_callback_ = &callable_thunk<Callable>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//! Bind a const callable object by reference (non-owning).
|
|
123
|
+
template<class Callable>
|
|
124
|
+
void set(const Callable& callable,
|
|
125
|
+
typename std::enable_if<!std::is_same<Callable, Functional<R(Args...)>>::value>::type* = nullptr)
|
|
126
|
+
{
|
|
127
|
+
context_ = const_cast<Callable*>(&callable);
|
|
128
|
+
callback_.context_callback_ = &const_callable_thunk<Callable>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//! Invoke the bound callback if set.
|
|
132
|
+
/*!
|
|
133
|
+
\return true when callback was set and out was updated.
|
|
134
|
+
\return false when callback was not set and out was unchanged.
|
|
135
|
+
*/
|
|
136
|
+
bool invoke(R& out, Args... args) const
|
|
137
|
+
{
|
|
138
|
+
bool result = false;
|
|
139
|
+
|
|
140
|
+
if(nullptr != context_)
|
|
141
|
+
{
|
|
142
|
+
if(nullptr != callback_.context_callback_)
|
|
143
|
+
{
|
|
144
|
+
out = callback_.context_callback_(decode_context(context_), args...);
|
|
145
|
+
result = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else
|
|
149
|
+
{
|
|
150
|
+
if(nullptr != callback_.function_callback_)
|
|
151
|
+
{
|
|
152
|
+
out = callback_.function_callback_(args...);
|
|
153
|
+
result = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//! \brief Convenience operator for invoke().
|
|
161
|
+
bool operator()(R& out, Args... args) const
|
|
162
|
+
{
|
|
163
|
+
return invoke(out, args...);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private:
|
|
167
|
+
union CallbackStorage
|
|
168
|
+
{
|
|
169
|
+
FunctionCallback function_callback_;
|
|
170
|
+
ContextCallback context_callback_;
|
|
171
|
+
|
|
172
|
+
CallbackStorage() : context_callback_(nullptr)
|
|
173
|
+
{
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
static void* null_context_sentinel()
|
|
178
|
+
{
|
|
179
|
+
static int sentinel = 0;
|
|
180
|
+
return &sentinel;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static void* decode_context(void* context)
|
|
184
|
+
{
|
|
185
|
+
void* result = context;
|
|
186
|
+
if(null_context_sentinel() == context)
|
|
187
|
+
{
|
|
188
|
+
result = nullptr;
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
template<class T, R (T::*METHOD)(Args...)>
|
|
194
|
+
static R member_thunk(void* context, Args... args)
|
|
195
|
+
{
|
|
196
|
+
T* instance = static_cast<T*>(context);
|
|
197
|
+
return (instance->*METHOD)(args...);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
template<class T, R (T::*METHOD)(Args...) const>
|
|
201
|
+
static R const_member_thunk(void* context, Args... args)
|
|
202
|
+
{
|
|
203
|
+
const T* instance = static_cast<const T*>(context);
|
|
204
|
+
return (instance->*METHOD)(args...);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
template<class Callable>
|
|
208
|
+
static R callable_thunk(void* context, Args... args)
|
|
209
|
+
{
|
|
210
|
+
Callable* callable = static_cast<Callable*>(context);
|
|
211
|
+
return (*callable)(args...);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
template<class Callable>
|
|
215
|
+
static R const_callable_thunk(void* context, Args... args)
|
|
216
|
+
{
|
|
217
|
+
const Callable* callable = static_cast<const Callable*>(context);
|
|
218
|
+
return (*callable)(args...);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
void* context_ = nullptr;
|
|
222
|
+
CallbackStorage callback_{};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
//! Specialization for callbacks without return value.
|
|
226
|
+
template<typename... Args>
|
|
227
|
+
class Functional<void(Args...)>
|
|
228
|
+
{
|
|
229
|
+
public:
|
|
230
|
+
using FunctionCallback = void (*)(Args...);
|
|
231
|
+
using ContextCallback = void (*)(void* context, Args...);
|
|
232
|
+
|
|
233
|
+
Functional() = default;
|
|
234
|
+
~Functional() = default;
|
|
235
|
+
|
|
236
|
+
//! Remove any bound callback.
|
|
237
|
+
void clear()
|
|
238
|
+
{
|
|
239
|
+
context_ = nullptr;
|
|
240
|
+
callback_.context_callback_ = nullptr;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
//! Check if a callback is bound.
|
|
244
|
+
bool is_set() const
|
|
245
|
+
{
|
|
246
|
+
bool result = false;
|
|
247
|
+
if(nullptr != context_)
|
|
248
|
+
{
|
|
249
|
+
result = (nullptr != callback_.context_callback_);
|
|
250
|
+
}
|
|
251
|
+
else
|
|
252
|
+
{
|
|
253
|
+
result = (nullptr != callback_.function_callback_);
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//! Bind a plain C/C++ function pointer.
|
|
259
|
+
void set(FunctionCallback function)
|
|
260
|
+
{
|
|
261
|
+
context_ = nullptr;
|
|
262
|
+
callback_.function_callback_ = function;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
//! Bind a C style callback with context pointer.
|
|
266
|
+
void set(ContextCallback function, void* context)
|
|
267
|
+
{
|
|
268
|
+
if(nullptr != function)
|
|
269
|
+
{
|
|
270
|
+
callback_.context_callback_ = function;
|
|
271
|
+
context_ = (nullptr == context) ? null_context_sentinel() : context;
|
|
272
|
+
}
|
|
273
|
+
else
|
|
274
|
+
{
|
|
275
|
+
context_ = nullptr;
|
|
276
|
+
callback_.context_callback_ = nullptr;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
//! Bind a member function (non-const) at compile time.
|
|
281
|
+
template<class T, void (T::*METHOD)(Args...)>
|
|
282
|
+
void set(T* instance)
|
|
283
|
+
{
|
|
284
|
+
context_ = instance;
|
|
285
|
+
callback_.context_callback_ = &member_thunk<T, METHOD>;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//! Bind a member function (const) at compile time.
|
|
289
|
+
template<class T, void (T::*METHOD)(Args...) const>
|
|
290
|
+
void set(const T* instance)
|
|
291
|
+
{
|
|
292
|
+
context_ = const_cast<T*>(instance);
|
|
293
|
+
callback_.context_callback_ = &const_member_thunk<T, METHOD>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
//! Bind a callable object by reference (non-owning).
|
|
297
|
+
template<class Callable>
|
|
298
|
+
void set(Callable& callable,
|
|
299
|
+
typename std::enable_if<!std::is_same<Callable, Functional<void(Args...)>>::value>::type* = nullptr)
|
|
300
|
+
{
|
|
301
|
+
context_ = &callable;
|
|
302
|
+
callback_.context_callback_ = &callable_thunk<Callable>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
//! Bind a const callable object by reference (non-owning).
|
|
306
|
+
template<class Callable>
|
|
307
|
+
void set(const Callable& callable,
|
|
308
|
+
typename std::enable_if<!std::is_same<Callable, Functional<void(Args...)>>::value>::type* = nullptr)
|
|
309
|
+
{
|
|
310
|
+
context_ = const_cast<Callable*>(&callable);
|
|
311
|
+
callback_.context_callback_ = &const_callable_thunk<Callable>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
//! Invoke the bound callback if set.
|
|
315
|
+
void invoke(Args... args) const
|
|
316
|
+
{
|
|
317
|
+
if(nullptr != context_)
|
|
318
|
+
{
|
|
319
|
+
if(nullptr != callback_.context_callback_)
|
|
320
|
+
{
|
|
321
|
+
callback_.context_callback_(decode_context(context_), args...);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else
|
|
325
|
+
{
|
|
326
|
+
if(nullptr != callback_.function_callback_)
|
|
327
|
+
{
|
|
328
|
+
callback_.function_callback_(args...);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
//! \brief Convenience operator for invoke().
|
|
334
|
+
void operator()(Args... args) const
|
|
335
|
+
{
|
|
336
|
+
invoke(args...);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
private:
|
|
340
|
+
union CallbackStorage
|
|
341
|
+
{
|
|
342
|
+
FunctionCallback function_callback_;
|
|
343
|
+
ContextCallback context_callback_;
|
|
344
|
+
|
|
345
|
+
CallbackStorage() : context_callback_(nullptr)
|
|
346
|
+
{
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
static void* null_context_sentinel()
|
|
351
|
+
{
|
|
352
|
+
static int sentinel = 0;
|
|
353
|
+
return &sentinel;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
static void* decode_context(void* context)
|
|
357
|
+
{
|
|
358
|
+
void* result = context;
|
|
359
|
+
if(null_context_sentinel() == context)
|
|
360
|
+
{
|
|
361
|
+
result = nullptr;
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
template<class T, void (T::*METHOD)(Args...)>
|
|
367
|
+
static void member_thunk(void* context, Args... args)
|
|
368
|
+
{
|
|
369
|
+
T* instance = static_cast<T*>(context);
|
|
370
|
+
if(nullptr != instance)
|
|
371
|
+
{
|
|
372
|
+
(instance->*METHOD)(args...);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
template<class T, void (T::*METHOD)(Args...) const>
|
|
377
|
+
static void const_member_thunk(void* context, Args... args)
|
|
378
|
+
{
|
|
379
|
+
const T* instance = static_cast<const T*>(context);
|
|
380
|
+
if(nullptr != instance)
|
|
381
|
+
{
|
|
382
|
+
(instance->*METHOD)(args...);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
template<class Callable>
|
|
387
|
+
static void callable_thunk(void* context, Args... args)
|
|
388
|
+
{
|
|
389
|
+
Callable* callable = static_cast<Callable*>(context);
|
|
390
|
+
if(nullptr != callable)
|
|
391
|
+
{
|
|
392
|
+
(*callable)(args...);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
template<class Callable>
|
|
397
|
+
static void const_callable_thunk(void* context, Args... args)
|
|
398
|
+
{
|
|
399
|
+
const Callable* callable = static_cast<const Callable*>(context);
|
|
400
|
+
if(nullptr != callable)
|
|
401
|
+
{
|
|
402
|
+
(*callable)(args...);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
void* context_ = nullptr;
|
|
407
|
+
CallbackStorage callback_{};
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
} // namespace EmbeddedProto
|
|
411
|
+
|
|
412
|
+
#endif // _FUNCTIONAL_H_
|