EmbeddedProto  2.0.0
EmbeddedProto is a C++ Protocol Buffer implementation specifically suitable for microcontrollers.
WireFormatter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
3  *
4  * This file is part of Embedded Proto.
5  *
6  * Embedded Proto is open source software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation, version 3 of the license.
9  *
10  * Embedded Proto is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
17  *
18  * For commercial and closed source application please visit:
19  * <https://EmbeddedProto.com/license/>.
20  *
21  * Embedded AMS B.V.
22  * Info:
23  * info at EmbeddedProto dot com
24  *
25  * Postal address:
26  * Johan Huizingalaan 763a
27  * 1066 VH, Amsterdam
28  * the Netherlands
29  */
30 
31 #ifndef _WIRE_FORMATTER_H_
32 #define _WIRE_FORMATTER_H_
33 
34 #include "WriteBufferInterface.h"
35 #include "ReadBufferInterface.h"
36 #include "Errors.h"
37 
38 #include <cstdint>
39 #include <math.h>
40 #include <type_traits>
41 #include <limits>
42 
43 
44 namespace EmbeddedProto
45 {
46 
49  {
50 
52  static constexpr uint8_t VARINT_SHIFT_N_BITS = 7;
53 
55  static constexpr uint8_t VARINT_MSB_BYTE = 0x80;
56 
58 
64  static constexpr int32_t constexpr_ceil(float num)
65  {
66  return (static_cast<float>(static_cast<int32_t>(num)) == num)
67  ? static_cast<int32_t>(num)
68  : static_cast<int32_t>(num) + ((num > 0) ? 1 : 0);
69  }
70 
71  public:
73  enum class WireType
74  {
75  VARINT = 0,
76  FIXED64 = 1,
77  LENGTH_DELIMITED = 2,
78  START_GROUP = 3,
79  END_GROUP = 4,
80  FIXED32 = 5,
81  };
82 
84 
93  template<class INT_TYPE>
94  static constexpr auto ZigZagEncode(const INT_TYPE n)
95  {
96  static_assert(std::is_same<INT_TYPE, int32_t>::value ||
97  std::is_same<INT_TYPE, int64_t>::value, "Wrong type passed to ZigZagEncode.");
98 
99  typedef typename std::make_unsigned<INT_TYPE>::type UINT_TYPE;
100  constexpr uint8_t N_BITS_TO_ZIGZAG = std::numeric_limits<UINT_TYPE>::digits - 1;
101 
102  return (static_cast<UINT_TYPE>(n) << 1) ^ static_cast<UINT_TYPE>(n >> N_BITS_TO_ZIGZAG);
103  }
104 
106 
112  template<class UINT_TYPE>
113  static constexpr auto ZigZagDecode(const UINT_TYPE n)
114  {
115  static_assert(std::is_same<UINT_TYPE, uint32_t>::value ||
116  std::is_same<UINT_TYPE, uint64_t>::value, "Wrong type passed to ZigZagDecode.");
117 
118  typedef typename std::make_signed<UINT_TYPE>::type INT_TYPE;
119 
120  return static_cast<INT_TYPE>((n >> 1) ^ (~(n & 1) + 1));
121  }
122 
124 
129  static constexpr uint32_t MakeTag(const uint32_t field_number, const WireType type)
130  {
131  return ((field_number << 3) | static_cast<uint32_t>(type));
132  }
133 
139  template<class UINT_TYPE>
141  static Error SerialzieFixedNoTag(UINT_TYPE value, WriteBufferInterface& buffer)
142  {
143  static_assert(std::is_same<UINT_TYPE, uint32_t>::value ||
144  std::is_same<UINT_TYPE, uint64_t>::value, "Wrong type passed to SerialzieFixedNoTag.");
145 
146  // Push the data little endian to the buffer.
147  // TODO Define a little endian flag to support memcpy the data to the buffer.
148 
149  bool result = true;
150 
151  // Loop over all bytes in the integer.
152  for(uint8_t i = 0; (i < std::numeric_limits<UINT_TYPE>::digits) && result; i += 8) {
153  // Shift the value using the current value of i.
154  result = buffer.push(static_cast<uint8_t>((value >> i) & 0x00FF));
155  }
156  return result ? Error::NO_ERRORS : Error::BUFFER_FULL;
157  }
158 
160  template<class INT_TYPE>
161  static Error SerialzieSFixedNoTag(INT_TYPE value, WriteBufferInterface& buffer)
162  {
163  static_assert(std::is_same<INT_TYPE, int32_t>::value ||
164  std::is_same<INT_TYPE, int64_t>::value, "Wrong type passed to SerialzieSFixedNoTag.");
165 
166  typedef typename std::make_unsigned<INT_TYPE>::type UINT_TYPE;
167 
168  return SerialzieFixedNoTag(static_cast<UINT_TYPE>(value), buffer);
169  }
170 
172  static Error SerialzieFloatNoTag(float value, WriteBufferInterface& buffer)
173  {
174  // Cast the type to void and to a 32 fixed number
175  void* pVoid = static_cast<void*>(&value);
176  uint32_t* fixed = static_cast<uint32_t*>(pVoid);
177  return SerialzieFixedNoTag(*fixed, buffer);
178  }
179 
181  static Error SerialzieDoubleNoTag(double value, WriteBufferInterface& buffer)
182  {
183  // Cast the type to void and to a 64 fixed number
184  void* pVoid = static_cast<void*>(&value);
185  uint64_t* fixed = static_cast<uint64_t*>(pVoid);
186  return SerialzieFixedNoTag(*fixed, buffer);
187  }
195  template<class INT_TYPE>
196  static Error SerializeInt(uint32_t field_number, INT_TYPE value, WriteBufferInterface& buffer)
197  {
198  typedef typename std::make_unsigned<INT_TYPE>::type UINT_TYPE;
199  Error return_value = SerializeVarint(MakeTag(field_number, WireType::VARINT), buffer);
200  if(Error::NO_ERRORS == return_value)
201  {
202  return_value = SerializeVarint(static_cast<UINT_TYPE>(value), buffer);
203  }
204  return return_value;
205  }
206 
207  template<class UINT_TYPE>
208  static Error SerializeUInt(uint32_t field_number, UINT_TYPE value, WriteBufferInterface& buffer)
209  {
210  Error return_value = SerializeVarint(MakeTag(field_number, WireType::VARINT), buffer);
211  if(Error::NO_ERRORS == return_value)
212  {
213  return_value = SerializeVarint(value, buffer);
214  }
215  return return_value;
216  }
217 
218  template<class INT_TYPE>
219  static Error SerializeSInt(uint32_t field_number, INT_TYPE value, WriteBufferInterface& buffer)
220  {
221  Error return_value = SerializeVarint(MakeTag(field_number, WireType::VARINT), buffer);
222  if(Error::NO_ERRORS == return_value)
223  {
224  return_value = SerializeVarint(ZigZagEncode(value), buffer);
225  }
226  return return_value;
227  }
228 
229  static Error SerializeFixed(uint32_t field_number, uint32_t value, WriteBufferInterface& buffer)
230  {
231  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED32), buffer);
232  if(Error::NO_ERRORS == return_value)
233  {
234  return_value = SerialzieFixedNoTag(value, buffer);
235  }
236  return return_value;
237  }
238 
239  static Error SerializeFixed(uint32_t field_number, uint64_t value, WriteBufferInterface& buffer)
240  {
241  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED64), buffer);
242  if(Error::NO_ERRORS == return_value)
243  {
244  return_value = SerialzieFixedNoTag(value, buffer);
245  }
246  return return_value;
247  }
248 
249  static Error SerializeSFixed(uint32_t field_number, int32_t value, WriteBufferInterface& buffer)
250  {
251  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED32), buffer);
252  if(Error::NO_ERRORS == return_value)
253  {
254  return_value = SerialzieSFixedNoTag(value, buffer);
255  }
256  return return_value;
257  }
258 
259  static Error SerializeSFixed(uint32_t field_number, int64_t value, WriteBufferInterface& buffer)
260  {
261  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED64), buffer);
262  if(Error::NO_ERRORS == return_value)
263  {
264  return_value = SerialzieSFixedNoTag(value, buffer);
265  }
266  return return_value;
267  }
268 
269  static Error SerializeFloat(uint32_t field_number, float value, WriteBufferInterface& buffer)
270  {
271  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED32), buffer);
272  if(Error::NO_ERRORS == return_value)
273  {
274  return_value = SerialzieFloatNoTag(value, buffer);
275  }
276  return return_value;
277  }
278 
279  static Error SerializeDouble(uint32_t field_number, double value, WriteBufferInterface& buffer)
280  {
281  Error return_value = SerializeVarint(MakeTag(field_number, WireType::FIXED64), buffer);
282  if(Error::NO_ERRORS == return_value)
283  {
284  return_value = SerialzieDoubleNoTag(value, buffer);
285  }
286  return return_value;
287  }
288 
289  static Error SerializeBool(uint32_t field_number, bool value, WriteBufferInterface& buffer)
290  {
291  Error return_value = SerializeVarint(MakeTag(field_number, WireType::VARINT), buffer);
292  if(Error::NO_ERRORS == return_value)
293  {
294  const uint8_t byte = value ? 0x01 : 0x00;
295  return_value = buffer.push(byte) ? Error::NO_ERRORS : Error::BUFFER_FULL;
296  }
297  return return_value;
298  }
299 
300  static Error SerializeEnum(uint32_t field_number, uint32_t value, WriteBufferInterface& buffer)
301  {
302  Error return_value = SerializeVarint(MakeTag(field_number, WireType::VARINT), buffer);
303  if(Error::NO_ERRORS == return_value)
304  {
305  return_value = SerializeVarint(value, buffer);
306  }
307  return return_value;
308  }
309 
317 
324  static Error DeserializeTag(ReadBufferInterface& buffer, WireType& type, uint32_t& id)
325  {
326  uint32_t temp_value;
327  // Read the next varint considered to be a tag.
328  Error return_value = DeserializeVarint(buffer, temp_value);
329 
330  if(Error::NO_ERRORS == return_value)
331  {
332  // Next check the validity of the wire type.
333  if((temp_value & 0x07) <= static_cast<uint32_t>(WireType::FIXED32))
334  {
335  // If reading the tag succeeded and the wire type is a valid one.
336  type = static_cast<WireType>(temp_value & 0x07);
337  id = (temp_value >> 3);
338  }
339  else
340  {
341  return_value = Error::INVALID_WIRETYPE;
342  }
343  }
344  return return_value;
345  }
346 
347  template<class UINT_TYPE>
348  static Error DeserializeUInt(ReadBufferInterface& buffer, UINT_TYPE& value)
349  {
350  static_assert(std::is_same<UINT_TYPE, uint32_t>::value ||
351  std::is_same<UINT_TYPE, uint64_t>::value, "Wrong type passed to DeserializeUInt.");
352 
353  return DeserializeVarint(buffer, value);
354  }
355 
356  template<class INT_TYPE>
357  static Error DeserializeInt(ReadBufferInterface& buffer, INT_TYPE& value)
358  {
359  static_assert(std::is_same<INT_TYPE, int32_t>::value ||
360  std::is_same<INT_TYPE, int64_t>::value, "Wrong type passed to DeserializeInt.");
361 
362  uint64_t uint_value;
363  Error result = DeserializeVarint(buffer, uint_value);
364  if(Error::NO_ERRORS == result)
365  {
366  value = static_cast<INT_TYPE>(uint_value);
367  }
368  return result;
369  }
370 
371  template<class INT_TYPE>
372  static Error DeserializeSInt(ReadBufferInterface& buffer, INT_TYPE& value)
373  {
374  static_assert(std::is_same<INT_TYPE, int32_t>::value ||
375  std::is_same<INT_TYPE, int64_t>::value, "Wrong type passed to DeserializeSInt.");
376 
377  uint64_t uint_value;
378  Error result = DeserializeVarint(buffer, uint_value);
379  if(Error::NO_ERRORS == result)
380  {
381  value = ZigZagDecode(uint_value);
382  }
383  return result;
384  }
385 
386  template<class TYPE>
387  static Error DeserializeFixed(ReadBufferInterface& buffer, TYPE& value)
388  {
389  static_assert(std::is_same<TYPE, uint32_t>::value ||
390  std::is_same<TYPE, uint64_t>::value, "Wrong type passed to DeserializeFixed.");
391 
392  // Deserialize the data little endian to the buffer.
393  // TODO Define a little endian flag to support memcpy the data from the buffer.
394 
395  TYPE temp_value = 0;
396  bool result(true);
397  uint8_t byte = 0;
398  for(uint8_t i = 0; (i < std::numeric_limits<TYPE>::digits) && result;
399  i += std::numeric_limits<uint8_t>::digits)
400  {
401  result = buffer.pop(byte);
402  if(result)
403  {
404  temp_value |= (static_cast<TYPE>(byte) << i);
405  }
406  }
407 
408  Error return_value = Error::NO_ERRORS;
409  if(result)
410  {
411  value = temp_value;
412  }
413  else
414  {
415  return_value = Error::END_OF_BUFFER;
416  }
417 
418  return return_value;
419  }
420 
421  template<class STYPE>
422  static Error DeserializeSFixed(ReadBufferInterface& buffer, STYPE& value)
423  {
424  static_assert(std::is_same<STYPE, int32_t>::value ||
425  std::is_same<STYPE, int64_t>::value, "Wrong type passed to DeserializeSFixed.");
426 
427  typedef typename std::make_unsigned<STYPE>::type USTYPE;
428  USTYPE temp_unsigned_value = 0;
429  Error result = DeserializeFixed(buffer, temp_unsigned_value);
430  if(Error::NO_ERRORS == result)
431  {
432  value = static_cast<STYPE>(temp_unsigned_value);
433  }
434 
435  return result;
436  }
437 
438  static Error DeserializeFloat(ReadBufferInterface& buffer, float& value)
439  {
440  uint32_t temp_value = 0;
441  Error result = DeserializeFixed(buffer, temp_value);
442  if(Error::NO_ERRORS == result)
443  {
444  // Cast from unsigned int to a float.
445  const void* pVoid = static_cast<const void*>(&temp_value);
446  const float* pFloat = static_cast<const float*>(pVoid);
447  value = *pFloat;
448  }
449  return result;
450  }
451 
452  static Error DeserializeDouble(ReadBufferInterface& buffer, double& value)
453  {
454  uint64_t temp_value = 0;
455  Error result = DeserializeFixed(buffer, temp_value);
456  if(Error::NO_ERRORS == result)
457  {
458  // Cast from unsigned int to a double.
459  const void* pVoid = static_cast<const void*>(&temp_value);
460  const double* pDouble = static_cast<const double*>(pVoid);
461  value = *pDouble;
462  }
463  return result;
464  }
465 
466  static Error DeserializeBool(ReadBufferInterface& buffer, bool& value)
467  {
468  uint8_t byte;
469  Error result = Error::NO_ERRORS;
470  if(buffer.pop(byte))
471  {
472  value = static_cast<bool>(byte);
473  }
474  else
475  {
476  result = Error::END_OF_BUFFER;
477  }
478  return result;
479  }
480 
481  template<class ENUM_TYPE>
482  static Error DeserializeEnum(ReadBufferInterface& buffer, ENUM_TYPE& value)
483  {
484  static_assert(std::is_enum<ENUM_TYPE>::value, "No enum given to DeserializeEnum parameter value.");
485  uint64_t temp_value;
486  Error result = DeserializeVarint(buffer, temp_value);
487  if(Error::NO_ERRORS == result)
488  {
489  value = static_cast<ENUM_TYPE>(temp_value);
490  }
491  return result;
492  }
493 
494 
498 
504  template<class UINT_TYPE>
505  static Error SerializeVarint(UINT_TYPE value, WriteBufferInterface& buffer)
506  {
507  static_assert(std::is_same<UINT_TYPE, uint32_t>::value ||
508  std::is_same<UINT_TYPE, uint64_t>::value,
509  "Wrong type passed to SerializeVarint.");
510 
511  bool memory_free = true;
512  while((value >= VARINT_MSB_BYTE) && memory_free)
513  {
514  memory_free = buffer.push(static_cast<uint8_t>(value | VARINT_MSB_BYTE));
515  value >>= VARINT_SHIFT_N_BITS;
516  }
517  memory_free = buffer.push(static_cast<uint8_t>(value));
518 
519  const Error return_value = memory_free ? Error::NO_ERRORS : Error::BUFFER_FULL;
520  return return_value;
521  }
522 
524 
529  template<class UINT_TYPE>
530  static Error DeserializeVarint(ReadBufferInterface& buffer, UINT_TYPE& value)
531  {
532  static_assert(std::is_same<UINT_TYPE, uint32_t>::value ||
533  std::is_same<UINT_TYPE, uint64_t>::value,
534  "Wrong type passed to DeserializeVarint.");
535 
536  // Calculate how many bytes there are in a varint 128 base encoded number. This should
537  // yield 5 for a 32bit number and 10 for a 64bit number.
538  static constexpr uint8_t N_BYTES_IN_VARINT = static_cast<uint8_t>(constexpr_ceil(
539  std::numeric_limits<UINT_TYPE>::digits
540  / static_cast<float>(VARINT_SHIFT_N_BITS)));
541 
542  UINT_TYPE temp_value = 0;
543  uint8_t byte = 0;
544  bool result = buffer.pop(byte);
545  // Loop until the end of the encoded varint or until there is no more data in the buffer.
546  for(uint8_t i = 0; (i < N_BYTES_IN_VARINT) && result; ++i)
547  {
548  temp_value |= static_cast<UINT_TYPE>(byte & (~VARINT_MSB_BYTE)) << (i * VARINT_SHIFT_N_BITS);
549  if(byte & VARINT_MSB_BYTE)
550  {
551  // Continue
552  result = buffer.pop(byte);
553  }
554  else
555  {
556  // The varint is complete
557  break;
558  }
559  }
560 
561  Error return_value = Error::NO_ERRORS;
562  if(result)
563  {
564  value = temp_value;
565  }
566  else
567  {
568  return_value = Error::END_OF_BUFFER;
569  }
570 
571  return return_value;
572  }
573 
574 
575  };
576 
577 } // End of namespace EmbeddedProto.
578 #endif
EmbeddedProto::WireFormatter::DeserializeInt
static Error DeserializeInt(ReadBufferInterface &buffer, INT_TYPE &value)
Definition: WireFormatter.h:357
EmbeddedProto::WireFormatter::DeserializeFloat
static Error DeserializeFloat(ReadBufferInterface &buffer, float &value)
Definition: WireFormatter.h:438
Errors.h
EmbeddedProto::WireFormatter::DeserializeEnum
static Error DeserializeEnum(ReadBufferInterface &buffer, ENUM_TYPE &value)
Definition: WireFormatter.h:482
EmbeddedProto::WireFormatter::SerialzieFloatNoTag
static Error SerialzieFloatNoTag(float value, WriteBufferInterface &buffer)
Serialize a 32bit real value without tag.
Definition: WireFormatter.h:172
EmbeddedProto::WireFormatter::DeserializeFixed
static Error DeserializeFixed(ReadBufferInterface &buffer, TYPE &value)
Definition: WireFormatter.h:387
EmbeddedProto::WireFormatter::SerialzieDoubleNoTag
static Error SerialzieDoubleNoTag(double value, WriteBufferInterface &buffer)
Serialize a 64bit real value without tag.
Definition: WireFormatter.h:181
EmbeddedProto::WireFormatter::SerializeBool
static Error SerializeBool(uint32_t field_number, bool value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:289
EmbeddedProto::WireFormatter::DeserializeUInt
static Error DeserializeUInt(ReadBufferInterface &buffer, UINT_TYPE &value)
Definition: WireFormatter.h:348
EmbeddedProto::WireFormatter::SerializeSFixed
static Error SerializeSFixed(uint32_t field_number, int32_t value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:249
EmbeddedProto::WireFormatter::SerializeFixed
static Error SerializeFixed(uint32_t field_number, uint32_t value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:229
EmbeddedProto::WireFormatter::SerialzieFixedNoTag
static Error SerialzieFixedNoTag(UINT_TYPE value, WriteBufferInterface &buffer)
Serialize fields, without tags the given buffer.
Definition: WireFormatter.h:141
EmbeddedProto::WireFormatter::SerializeDouble
static Error SerializeDouble(uint32_t field_number, double value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:279
EmbeddedProto::WireFormatter::DeserializeDouble
static Error DeserializeDouble(ReadBufferInterface &buffer, double &value)
Definition: WireFormatter.h:452
EmbeddedProto::WireFormatter::SerializeUInt
static Error SerializeUInt(uint32_t field_number, UINT_TYPE value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:208
EmbeddedProto::ReadBufferInterface
The pure virtual definition of a message buffer to read from.
Definition: ReadBufferInterface.h:43
EmbeddedProto::WireFormatter::SerializeSFixed
static Error SerializeSFixed(uint32_t field_number, int64_t value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:259
EmbeddedProto::Error::INVALID_WIRETYPE
@ INVALID_WIRETYPE
When reading a Wiretype from the tag we got an invalid value.
EmbeddedProto::WireFormatter::WireType::LENGTH_DELIMITED
@ LENGTH_DELIMITED
string, bytes, embedded messages, packed repeated fields
EmbeddedProto::WireFormatter::SerializeVarint
static Error SerializeVarint(UINT_TYPE value, WriteBufferInterface &buffer)
This function converts a given value unsigned integer to a varint formatted data buffer.
Definition: WireFormatter.h:505
EmbeddedProto::WireFormatter::ZigZagEncode
static constexpr auto ZigZagEncode(const INT_TYPE n)
Encode a signed integer using the zig zag method.
Definition: WireFormatter.h:94
EmbeddedProto
Definition: Errors.h:34
EmbeddedProto::Error::NO_ERRORS
@ NO_ERRORS
No errors have occurred.
EmbeddedProto::WireFormatter::SerialzieSFixedNoTag
static Error SerialzieSFixedNoTag(INT_TYPE value, WriteBufferInterface &buffer)
Serialize a signed fixed length field without the tag.
Definition: WireFormatter.h:161
EmbeddedProto::WireFormatter::WireType::VARINT
@ VARINT
int32, int64, uint32, uint64, sint32, sint64, bool, enum.
EmbeddedProto::WriteBufferInterface::push
virtual bool push(const uint8_t byte)=0
Push a single byte into the buffer.
EmbeddedProto::WireFormatter::WireType::END_GROUP
@ END_GROUP
Deprecated.
EmbeddedProto::WireFormatter::SerializeFixed
static Error SerializeFixed(uint32_t field_number, uint64_t value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:239
EmbeddedProto::WireFormatter::WireType::FIXED64
@ FIXED64
fixed64, sfixed64, double
EmbeddedProto::WriteBufferInterface
The pure virtual definition of a message buffer used for writing .
Definition: WriteBufferInterface.h:46
EmbeddedProto::Error
Error
This enumeration defines errors which can occur during serialization and deserialization.
Definition: Errors.h:38
EmbeddedProto::WireFormatter::DeserializeVarint
static Error DeserializeVarint(ReadBufferInterface &buffer, UINT_TYPE &value)
This function deserializes the following N bytes into a varint.
Definition: WireFormatter.h:530
EmbeddedProto::WireFormatter::DeserializeTag
static Error DeserializeTag(ReadBufferInterface &buffer, WireType &type, uint32_t &id)
Deserialize fields from the given buffer.
Definition: WireFormatter.h:324
EmbeddedProto::WireFormatter::WireType
WireType
Definitions of the different encoding types used in protobuf.
Definition: WireFormatter.h:73
EmbeddedProto::WireFormatter::SerializeFloat
static Error SerializeFloat(uint32_t field_number, float value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:269
EmbeddedProto::Error::END_OF_BUFFER
@ END_OF_BUFFER
While trying to read from the buffer we ran out of bytes tor read.
EmbeddedProto::WireFormatter::WireType::START_GROUP
@ START_GROUP
Deprecated.
EmbeddedProto::ReadBufferInterface::pop
virtual bool pop(uint8_t &byte)=0
Obtain the value of the oldest byte in the buffer and remove it from the buffer.
EmbeddedProto::WireFormatter::WireType::FIXED32
@ FIXED32
fixed32, sfixed32, float
EmbeddedProto::WireFormatter::SerializeEnum
static Error SerializeEnum(uint32_t field_number, uint32_t value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:300
EmbeddedProto::WireFormatter::SerializeSInt
static Error SerializeSInt(uint32_t field_number, INT_TYPE value, WriteBufferInterface &buffer)
Definition: WireFormatter.h:219
ReadBufferInterface.h
EmbeddedProto::WireFormatter::DeserializeBool
static Error DeserializeBool(ReadBufferInterface &buffer, bool &value)
Definition: WireFormatter.h:466
EmbeddedProto::WireFormatter::SerializeInt
static Error SerializeInt(uint32_t field_number, INT_TYPE value, WriteBufferInterface &buffer)
Serialize fields, including tags to the given buffer.
Definition: WireFormatter.h:196
EmbeddedProto::WireFormatter::MakeTag
static constexpr uint32_t MakeTag(const uint32_t field_number, const WireType type)
Create the tag of a field.
Definition: WireFormatter.h:129
WriteBufferInterface.h
EmbeddedProto::WireFormatter::DeserializeSInt
static Error DeserializeSInt(ReadBufferInterface &buffer, INT_TYPE &value)
Definition: WireFormatter.h:372
EmbeddedProto::WireFormatter
This class combines functions to serialize and deserialize messages.
Definition: WireFormatter.h:48
EmbeddedProto::WireFormatter::DeserializeSFixed
static Error DeserializeSFixed(ReadBufferInterface &buffer, STYPE &value)
Definition: WireFormatter.h:422
EmbeddedProto::Error::BUFFER_FULL
@ BUFFER_FULL
The write buffer is full, unable to push more bytes in to it.
EmbeddedProto::WireFormatter::ZigZagDecode
static constexpr auto ZigZagDecode(const UINT_TYPE n)
Decode a signed integer using the zig zag method.
Definition: WireFormatter.h:113