Basic variables

Several basic numeric variables are available 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 are serialized, such as base 127, ZigZag and fixed length. To accommodate multiple methods, Embedded Proto warps the base types in a class, a Field class.

The Field class wraps the basic variable type together with functions to serialize and deserialize the value. Various operators are overloaded in these classes to efficiently 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 part of a message class, several functions provide to access the field. Assume we have the following message named Foo:

message Foo
{
  int32 Bar = 1;
}

The message holds one variable named Bar. Various functions are available to access the member Bar when generating code for the message Foo. The interface for getting, setting, and clearing Bar are depicted below:

class Foo
{
  public:
    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 has two versions, one with the standard reference and one with an rvalue reference. The last function; clear_Bar(), is used to reset the value of Bar 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.