Basic variables

There are a number of basic numeric variables possible in Protobuf: floating point values and integers both signed and unsigned. Also a simple boolean is available. There are various methods in which these types can be serialized, such as base 127, ZigZag and fixed length. To accommodate these various methods Embedded Proto warps the base types in a class , a Field class.

The Field class is used to wrap the basic variable type together with functions to serialize and deserialize the value. Various operators are overloaded in these classes to easily perform operations on the base type, such as assignment and comparison. Take for instance the examples below:

// A field object.
EmbeddedProto::int32 int_field;

// A normal scalar variable.
int32_t normal_variable = 1;

// Assigning the scaler to the field object.
int_field = normal_variable;

// A field and scaler comparison.
if(int_field == normal_variable) 
  // etc.

When a field is integrated into a message class a number of functions are provided by that class to access the field. Assume we have the following message named Foo:

message Foo
  int32 Bar = 1;

The message holds one variable named Bar. When generating code for the message Foo various functions are created to access the member Bar. The interface for getting, setting and clearing Bar is depicted below:

class Foo
    EmbeddedProto::int32::FIELD_TYPE Bar() const;
    EmbeddedProto::int32::FIELD_TYPE get_Bar() const;
    void set_Bar(const EmbeddedProto::int32::FIELD_TYPE& value);
    void set_Bar(const EmbeddedProto::int32::FIELD_TYPE&& value);
    void clear_Bar();

As you can see there are two functions to obtain a constant copy of the value using the Bar() and get_Bar() functions. The set_Bar() function is executed in two versions, one with the normal reference and one with an rvalue reference. The last function is used to clear the value back to the protobuf default. At the moment of writing Embedded Proto is implemented for Proto3 meaning that all variable types are set by default to zero.