EmbeddedProto  2.0.0
EmbeddedProto is a C++ Protocol Buffer implementation specifically suitable for microcontrollers.
Public Types | Static Public Member Functions | List of all members
EmbeddedProto::WireFormatter Class Reference

This class combines functions to serialize and deserialize messages. More...

#include <WireFormatter.h>

Public Types

enum  WireType {
  WireType::VARINT = 0, WireType::FIXED64 = 1, WireType::LENGTH_DELIMITED = 2, WireType::START_GROUP = 3,
  WireType::END_GROUP = 4, WireType::FIXED32 = 5
}
 Definitions of the different encoding types used in protobuf. More...
 

Static Public Member Functions

template<class INT_TYPE >
static constexpr auto ZigZagEncode (const INT_TYPE n)
 Encode a signed integer using the zig zag method. More...
 
template<class UINT_TYPE >
static constexpr auto ZigZagDecode (const UINT_TYPE n)
 Decode a signed integer using the zig zag method. More...
 
static constexpr uint32_t MakeTag (const uint32_t field_number, const WireType type)
 Create the tag of a field. More...
 
template<class UINT_TYPE >
static Error SerializeVarint (UINT_TYPE value, WriteBufferInterface &buffer)
 This function converts a given value unsigned integer to a varint formatted data buffer. More...
 
template<class UINT_TYPE >
static Error DeserializeVarint (ReadBufferInterface &buffer, UINT_TYPE &value)
 This function deserializes the following N bytes into a varint. More...
 
template<class UINT_TYPE >
static Error SerialzieFixedNoTag (UINT_TYPE value, WriteBufferInterface &buffer)
 Serialize fields, without tags the given buffer. More...
 
template<class INT_TYPE >
static Error SerialzieSFixedNoTag (INT_TYPE value, WriteBufferInterface &buffer)
 Serialize a signed fixed length field without the tag. More...
 
static Error SerialzieFloatNoTag (float value, WriteBufferInterface &buffer)
 Serialize a 32bit real value without tag. More...
 
static Error SerialzieDoubleNoTag (double value, WriteBufferInterface &buffer)
 Serialize a 64bit real value without tag. More...
 
template<class INT_TYPE >
static Error SerializeInt (uint32_t field_number, INT_TYPE value, WriteBufferInterface &buffer)
 Serialize fields, including tags to the given buffer. More...
 
template<class UINT_TYPE >
static Error SerializeUInt (uint32_t field_number, UINT_TYPE value, WriteBufferInterface &buffer)
 
template<class INT_TYPE >
static Error SerializeSInt (uint32_t field_number, INT_TYPE value, WriteBufferInterface &buffer)
 
static Error SerializeFixed (uint32_t field_number, uint32_t value, WriteBufferInterface &buffer)
 
static Error SerializeFixed (uint32_t field_number, uint64_t value, WriteBufferInterface &buffer)
 
static Error SerializeSFixed (uint32_t field_number, int32_t value, WriteBufferInterface &buffer)
 
static Error SerializeSFixed (uint32_t field_number, int64_t value, WriteBufferInterface &buffer)
 
static Error SerializeFloat (uint32_t field_number, float value, WriteBufferInterface &buffer)
 
static Error SerializeDouble (uint32_t field_number, double value, WriteBufferInterface &buffer)
 
static Error SerializeBool (uint32_t field_number, bool value, WriteBufferInterface &buffer)
 
static Error SerializeEnum (uint32_t field_number, uint32_t value, WriteBufferInterface &buffer)
 
static Error DeserializeTag (ReadBufferInterface &buffer, WireType &type, uint32_t &id)
 Deserialize fields from the given buffer. More...
 
template<class UINT_TYPE >
static Error DeserializeUInt (ReadBufferInterface &buffer, UINT_TYPE &value)
 
template<class INT_TYPE >
static Error DeserializeInt (ReadBufferInterface &buffer, INT_TYPE &value)
 
template<class INT_TYPE >
static Error DeserializeSInt (ReadBufferInterface &buffer, INT_TYPE &value)
 
template<class TYPE >
static Error DeserializeFixed (ReadBufferInterface &buffer, TYPE &value)
 
template<class STYPE >
static Error DeserializeSFixed (ReadBufferInterface &buffer, STYPE &value)
 
static Error DeserializeFloat (ReadBufferInterface &buffer, float &value)
 
static Error DeserializeDouble (ReadBufferInterface &buffer, double &value)
 
static Error DeserializeBool (ReadBufferInterface &buffer, bool &value)
 
template<class ENUM_TYPE >
static Error DeserializeEnum (ReadBufferInterface &buffer, ENUM_TYPE &value)
 

Detailed Description

This class combines functions to serialize and deserialize messages.

Member Enumeration Documentation

◆ WireType

Definitions of the different encoding types used in protobuf.

Enumerator
VARINT 

int32, int64, uint32, uint64, sint32, sint64, bool, enum.

FIXED64 

fixed64, sfixed64, double

LENGTH_DELIMITED 

string, bytes, embedded messages, packed repeated fields

START_GROUP 

Deprecated.

END_GROUP 

Deprecated.

FIXED32 

fixed32, sfixed32, float

Member Function Documentation

◆ DeserializeBool()

static Error EmbeddedProto::WireFormatter::DeserializeBool ( ReadBufferInterface buffer,
bool &  value 
)
inlinestatic

◆ DeserializeDouble()

static Error EmbeddedProto::WireFormatter::DeserializeDouble ( ReadBufferInterface buffer,
double &  value 
)
inlinestatic

◆ DeserializeEnum()

template<class ENUM_TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeEnum ( ReadBufferInterface buffer,
ENUM_TYPE &  value 
)
inlinestatic

◆ DeserializeFixed()

template<class TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeFixed ( ReadBufferInterface buffer,
TYPE &  value 
)
inlinestatic

◆ DeserializeFloat()

static Error EmbeddedProto::WireFormatter::DeserializeFloat ( ReadBufferInterface buffer,
float &  value 
)
inlinestatic

◆ DeserializeInt()

template<class INT_TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeInt ( ReadBufferInterface buffer,
INT_TYPE &  value 
)
inlinestatic

◆ DeserializeSFixed()

template<class STYPE >
static Error EmbeddedProto::WireFormatter::DeserializeSFixed ( ReadBufferInterface buffer,
STYPE &  value 
)
inlinestatic

◆ DeserializeSInt()

template<class INT_TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeSInt ( ReadBufferInterface buffer,
INT_TYPE &  value 
)
inlinestatic

◆ DeserializeTag()

static Error EmbeddedProto::WireFormatter::DeserializeTag ( ReadBufferInterface buffer,
WireType type,
uint32_t &  id 
)
inlinestatic

Deserialize fields from the given buffer.

Read from the buffer the next wiretype and field id.

Parameters
[in]bufferThe data source from which to read the type and id.
[out]typeThis parameter returns the wiretype of the next field in the data buffer.
[out]idThis parameter returns the next field id.
Returns
A value from the EmbeddedProto::Error enum indicating if the process succeeded.

◆ DeserializeUInt()

template<class UINT_TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeUInt ( ReadBufferInterface buffer,
UINT_TYPE &  value 
)
inlinestatic

◆ DeserializeVarint()

template<class UINT_TYPE >
static Error EmbeddedProto::WireFormatter::DeserializeVarint ( ReadBufferInterface buffer,
UINT_TYPE &  value 
)
inlinestatic

This function deserializes the following N bytes into a varint.

Parameters
[in]bufferThe data buffer from which bytes are popped.
[out]valueThe variable in which the varint is returned.
Returns
A value from the Error enum, NO_ERROR in case everything is fine.

◆ MakeTag()

static constexpr uint32_t EmbeddedProto::WireFormatter::MakeTag ( const uint32_t  field_number,
const WireType  type 
)
inlinestaticconstexpr

Create the tag of a field.

This is the combination of the field number and wire type of the field. The field number is shifted to the left by three bits. This creates space to or the wire type of the designated field.

◆ SerializeBool()

static Error EmbeddedProto::WireFormatter::SerializeBool ( uint32_t  field_number,
bool  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeDouble()

static Error EmbeddedProto::WireFormatter::SerializeDouble ( uint32_t  field_number,
double  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeEnum()

static Error EmbeddedProto::WireFormatter::SerializeEnum ( uint32_t  field_number,
uint32_t  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeFixed() [1/2]

static Error EmbeddedProto::WireFormatter::SerializeFixed ( uint32_t  field_number,
uint32_t  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeFixed() [2/2]

static Error EmbeddedProto::WireFormatter::SerializeFixed ( uint32_t  field_number,
uint64_t  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeFloat()

static Error EmbeddedProto::WireFormatter::SerializeFloat ( uint32_t  field_number,
float  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeInt()

template<class INT_TYPE >
static Error EmbeddedProto::WireFormatter::SerializeInt ( uint32_t  field_number,
INT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

Serialize fields, including tags to the given buffer.

◆ SerializeSFixed() [1/2]

static Error EmbeddedProto::WireFormatter::SerializeSFixed ( uint32_t  field_number,
int32_t  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeSFixed() [2/2]

static Error EmbeddedProto::WireFormatter::SerializeSFixed ( uint32_t  field_number,
int64_t  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeSInt()

template<class INT_TYPE >
static Error EmbeddedProto::WireFormatter::SerializeSInt ( uint32_t  field_number,
INT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeUInt()

template<class UINT_TYPE >
static Error EmbeddedProto::WireFormatter::SerializeUInt ( uint32_t  field_number,
UINT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

◆ SerializeVarint()

template<class UINT_TYPE >
static Error EmbeddedProto::WireFormatter::SerializeVarint ( UINT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

This function converts a given value unsigned integer to a varint formatted data buffer.

Parameters
[in]valueThe data to be serialized, uint32_t or uint64_t.
[in]bufferA reference to a message buffer object in which to store the variable.
Returns
A value from the Error enum, NO_ERROR in case everything is fine.

◆ SerialzieDoubleNoTag()

static Error EmbeddedProto::WireFormatter::SerialzieDoubleNoTag ( double  value,
WriteBufferInterface buffer 
)
inlinestatic

Serialize a 64bit real value without tag.

◆ SerialzieFixedNoTag()

template<class UINT_TYPE >
static Error EmbeddedProto::WireFormatter::SerialzieFixedNoTag ( UINT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

Serialize fields, without tags the given buffer.

Serialize an unsigned fixed length field without the tag.

◆ SerialzieFloatNoTag()

static Error EmbeddedProto::WireFormatter::SerialzieFloatNoTag ( float  value,
WriteBufferInterface buffer 
)
inlinestatic

Serialize a 32bit real value without tag.

◆ SerialzieSFixedNoTag()

template<class INT_TYPE >
static Error EmbeddedProto::WireFormatter::SerialzieSFixedNoTag ( INT_TYPE  value,
WriteBufferInterface buffer 
)
inlinestatic

Serialize a signed fixed length field without the tag.

◆ ZigZagDecode()

template<class UINT_TYPE >
static constexpr auto EmbeddedProto::WireFormatter::ZigZagDecode ( const UINT_TYPE  n)
inlinestaticconstexpr

Decode a signed integer using the zig zag method.

Parameters
[in]nThe value encoded in zig zag to be decoded.
Returns
The decoded signed value.

This function is suitable for 32 and 64 bit.

◆ ZigZagEncode()

template<class INT_TYPE >
static constexpr auto EmbeddedProto::WireFormatter::ZigZagEncode ( const INT_TYPE  n)
inlinestaticconstexpr

Encode a signed integer using the zig zag method.

As specified the right-shift must be arithmetic, hence the cast is after the shift. The left shift must be unsigned because of overflow.

This function is suitable for 32 and 64 bit.

Parameters
[in]nThe signed value to be encoded.
Returns
The zig zag transformed value ready for serialization into the array.

The documentation for this class was generated from the following file: