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.
Files changed (63) hide show
  1. EmbeddedProto/EmbeddedProto.py +122 -0
  2. EmbeddedProto/Features.py +255 -0
  3. EmbeddedProto/Field.py +1295 -0
  4. EmbeddedProto/Oneof.py +74 -0
  5. EmbeddedProto/ProtoFile.py +210 -0
  6. EmbeddedProto/TypeDefinitions.py +367 -0
  7. EmbeddedProto/__init__.py +0 -0
  8. EmbeddedProto/__main__.py +28 -0
  9. EmbeddedProto/config.py +173 -0
  10. EmbeddedProto/custom_header.py +513 -0
  11. EmbeddedProto/embedded_proto_options.proto +62 -0
  12. EmbeddedProto/embedded_proto_options_pb2.py +37 -0
  13. EmbeddedProto/field_options.py +344 -0
  14. EmbeddedProto/main.py +316 -0
  15. EmbeddedProto/src/EmbeddedProto/BytesStringCallback.h +476 -0
  16. EmbeddedProto/src/EmbeddedProto/Defines.h +118 -0
  17. EmbeddedProto/src/EmbeddedProto/EmptyArray.h +81 -0
  18. EmbeddedProto/src/EmbeddedProto/Errors.h +53 -0
  19. EmbeddedProto/src/EmbeddedProto/FieldStringBytes.h +793 -0
  20. EmbeddedProto/src/EmbeddedProto/Fields.h +832 -0
  21. EmbeddedProto/src/EmbeddedProto/Functional.h +412 -0
  22. EmbeddedProto/src/EmbeddedProto/MessageCallback.h +688 -0
  23. EmbeddedProto/src/EmbeddedProto/MessageInterface.h +792 -0
  24. EmbeddedProto/src/EmbeddedProto/MessageSizeCalculator.h +109 -0
  25. EmbeddedProto/src/EmbeddedProto/MessageState.h +207 -0
  26. EmbeddedProto/src/EmbeddedProto/ReadBufferFixedSize.h +204 -0
  27. EmbeddedProto/src/EmbeddedProto/ReadBufferInterface.h +181 -0
  28. EmbeddedProto/src/EmbeddedProto/ReadBufferSection.h +232 -0
  29. EmbeddedProto/src/EmbeddedProto/RepeatedField.h +1053 -0
  30. EmbeddedProto/src/EmbeddedProto/RepeatedFieldCallback.h +432 -0
  31. EmbeddedProto/src/EmbeddedProto/RepeatedFieldFixedSize.h +367 -0
  32. EmbeddedProto/src/EmbeddedProto/Version.h +39 -0
  33. EmbeddedProto/src/EmbeddedProto/WireFormatter.h +852 -0
  34. EmbeddedProto/src/EmbeddedProto/WriteBufferFixedSize.h +114 -0
  35. EmbeddedProto/src/EmbeddedProto/WriteBufferInterface.h +134 -0
  36. EmbeddedProto/src/EmbeddedProto.h +55 -0
  37. EmbeddedProto/templates/FieldBasic_Deserialize.h.jinja2 +26 -0
  38. EmbeddedProto/templates/FieldBasic_GetSet.h.jinja2 +89 -0
  39. EmbeddedProto/templates/FieldBytes_GetSet.h.jinja2 +86 -0
  40. EmbeddedProto/templates/FieldEnum_Deserialize.h.jinja2 +50 -0
  41. EmbeddedProto/templates/FieldEnum_GetSet.h.jinja2 +93 -0
  42. EmbeddedProto/templates/FieldErrorRecursive_GetSet.h.jinja2 +29 -0
  43. EmbeddedProto/templates/FieldMap_GetSet.h.jinja2 +203 -0
  44. EmbeddedProto/templates/FieldMsg_Deserialize.h.jinja2 +44 -0
  45. EmbeddedProto/templates/FieldMsg_GetSet.h.jinja2 +93 -0
  46. EmbeddedProto/templates/FieldRepeated_GetSet.h.jinja2 +94 -0
  47. EmbeddedProto/templates/FieldString_GetSet.h.jinja2 +86 -0
  48. EmbeddedProto/templates/Field_DeserializePartial.h.jinja2 +33 -0
  49. EmbeddedProto/templates/Field_Serialize.h.jinja2 +112 -0
  50. EmbeddedProto/templates/Field_SerializePartial.h.jinja2 +119 -0
  51. EmbeddedProto/templates/Header.h.jinja2 +108 -0
  52. EmbeddedProto/templates/TypeDefEnum.h.jinja2 +45 -0
  53. EmbeddedProto/templates/TypeDefMsg.h.jinja2 +791 -0
  54. EmbeddedProto/templates/TypeOneof.h.jinja2 +178 -0
  55. EmbeddedProto/version.json +3 -0
  56. embeddedproto-4.0.0b1.dist-info/METADATA +141 -0
  57. embeddedproto-4.0.0b1.dist-info/RECORD +63 -0
  58. embeddedproto-4.0.0b1.dist-info/WHEEL +5 -0
  59. embeddedproto-4.0.0b1.dist-info/entry_points.txt +3 -0
  60. embeddedproto-4.0.0b1.dist-info/licenses/LICENSE +30 -0
  61. embeddedproto-4.0.0b1.dist-info/licenses/LICENSES/GPL-3.0-only.txt +674 -0
  62. embeddedproto-4.0.0b1.dist-info/licenses/LICENSES/LicenseRef-EmbeddedProto-Commercial.txt +12 -0
  63. embeddedproto-4.0.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,232 @@
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 _READ_BUFFER_SECTION_H_
25
+ #define _READ_BUFFER_SECTION_H_
26
+
27
+ #include "ReadBufferInterface.h"
28
+
29
+ #include <cstdint>
30
+ #include <algorithm>
31
+
32
+
33
+ namespace EmbeddedProto
34
+ {
35
+ //! This is a wrapper around a ReadBufferInterface only exposing a given number of bytes.
36
+ /*!
37
+ This class is used when decoding a length delimited fields. It is constructed given a message
38
+ buffer and a size. This class will return bytes from the buffer for the given number of bytes
39
+ stated in the size parameter.
40
+
41
+ \see ReadBufferInterface
42
+ */
43
+ class ReadBufferSection : public ReadBufferInterface
44
+ {
45
+ public:
46
+
47
+ //! Explicitly delete the default constructor in favor of the one with parameters.
48
+ ReadBufferSection() = delete;
49
+
50
+ //! The constructor of the class with the required parameters
51
+ /*!
52
+ \param buffer The actual data buffer from which the bytes are obtained.
53
+ \param size The maximum number of bytes to return from buffer.
54
+ */
55
+ ReadBufferSection(ReadBufferInterface& buffer, const uint32_t size);
56
+
57
+ ~ReadBufferSection() = default;
58
+
59
+
60
+ //! Return the number of bytes remaining.
61
+ uint32_t get_size() const override;
62
+
63
+ //! Obtain the total number of bytes which can at most be stored in the buffer.
64
+ /*!
65
+ In the case of this buffer section this will return the size of the section.
66
+ */
67
+ uint32_t get_max_size() const override;
68
+
69
+ //! Expose the function of the parent buffer.
70
+ /*!
71
+ This will not do anything if size zero is reached.
72
+ \return True when the buffer was not empty.
73
+ */
74
+ bool peek(uint8_t& byte) const override;
75
+
76
+ //! Expose the function of the parent buffer.
77
+ /*!
78
+ This will not do anything if size zero is reached.
79
+ \return True when the buffer was not empty.
80
+ */
81
+ bool peek(const uint32_t n_bytes, uint8_t& byte) const override;
82
+
83
+ //! Decrement the size and call advance on the parent buffer.
84
+ /*!
85
+ This will not do anything if size zero is reached.
86
+ \return True when the buffer was not empty.
87
+ */
88
+ bool advance() override;
89
+
90
+ //! Decrement the size by N bytes and call advance on the parent buffer.
91
+ /*!
92
+ This will not do anything if size zero is reached.
93
+ \return True when the buffer held the n_bytes or more.
94
+ */
95
+ bool advance(const uint32_t n_bytes) override;
96
+
97
+ //! Decrement the size and pop the next byte from the parent buffer.
98
+ /*!
99
+ This will not do anything if size zero is reached.
100
+ \return True while the end of the buffer is not reached.
101
+ */
102
+ bool pop(uint8_t& byte) override;
103
+
104
+ //! Keep the pointer and length form of pop() reachable next to the override below.
105
+ using ReadBufferInterface::pop;
106
+
107
+ //! Copy a block of bytes from the parent buffer, respecting the section size.
108
+ /*!
109
+ All-or-nothing: nothing is copied and the section size is left unchanged
110
+ when dest.size exceeds the number of bytes remaining in this section. This
111
+ keeps a fixed-width element that straddles the section boundary from being
112
+ half-consumed.
113
+ \return True when dest.size bytes were available within the section and copied.
114
+ */
115
+ bool pop(const bytes_view& dest) override;
116
+
117
+ //! Keep the single byte forms of peek() reachable next to the override below.
118
+ using ReadBufferInterface::peek;
119
+
120
+ //! Copy a block of bytes from the parent buffer without consuming them, respecting the section size.
121
+ bool peek(const bytes_view& dest) const override;
122
+
123
+ private:
124
+
125
+ //! A reference to the buffer containing the actual data.
126
+ ReadBufferInterface& buffer_;
127
+
128
+ //! The number of bytes left in this section.
129
+ uint32_t size_;
130
+
131
+ //! The total number of bytes masked of by this section.
132
+ const uint32_t max_size_;
133
+ };
134
+
135
+
136
+ // Definitions of the member functions declared above. The library is header only, so they are
137
+ // inline.
138
+
139
+ inline ReadBufferSection::ReadBufferSection(ReadBufferInterface& buffer, const uint32_t size)
140
+ : buffer_(buffer),
141
+ size_(std::min(size, buffer.get_size())),
142
+ max_size_(std::min(size, buffer.get_size()))
143
+ {
144
+
145
+ }
146
+
147
+ inline uint32_t ReadBufferSection::get_size() const
148
+ {
149
+ return size_;
150
+ }
151
+
152
+ inline uint32_t ReadBufferSection::get_max_size() const
153
+ {
154
+ return max_size_;
155
+ }
156
+
157
+ inline bool ReadBufferSection::peek(uint8_t& byte) const
158
+ {
159
+ bool result = 0 < size_;
160
+ if(result)
161
+ {
162
+ result = buffer_.peek(byte);
163
+ }
164
+ return result;
165
+ }
166
+
167
+ inline bool ReadBufferSection::peek(const uint32_t n_bytes, uint8_t& byte) const
168
+ {
169
+ bool result = n_bytes < size_;
170
+ if(result)
171
+ {
172
+ result = buffer_.peek(n_bytes, byte);
173
+ }
174
+ return result;
175
+ }
176
+
177
+ inline bool ReadBufferSection::advance()
178
+ {
179
+ bool result = 0 < size_;
180
+ if(result)
181
+ {
182
+ result = buffer_.advance();
183
+ --size_;
184
+ }
185
+ return result;
186
+ }
187
+
188
+ inline bool ReadBufferSection::advance(const uint32_t n_bytes)
189
+ {
190
+ bool result = 0 < size_;
191
+ if(result)
192
+ {
193
+ uint32_t n = (n_bytes <= size_) ? n_bytes : size_;
194
+ result = buffer_.advance(n);
195
+ size_ -= n;
196
+ }
197
+ return result;
198
+ }
199
+
200
+ inline bool ReadBufferSection::pop(uint8_t& byte)
201
+ {
202
+ bool result = 0 < size_;
203
+ if(result)
204
+ {
205
+ result = buffer_.pop(byte);
206
+ --size_;
207
+ }
208
+ return result;
209
+ }
210
+
211
+ inline bool ReadBufferSection::pop(const bytes_view& dest)
212
+ {
213
+ bool result = dest.size <= size_;
214
+ if(result)
215
+ {
216
+ result = buffer_.pop(dest);
217
+ if(result)
218
+ {
219
+ size_ -= dest.size;
220
+ }
221
+ }
222
+ return result;
223
+ }
224
+
225
+ inline bool ReadBufferSection::peek(const bytes_view& dest) const
226
+ {
227
+ return (dest.size <= size_) && buffer_.peek(dest);
228
+ }
229
+
230
+ } // End of namespace EmbeddedProto
231
+
232
+ #endif // _READ_BUFFER_SECTION_H_