COMMS
Template library intended to help with implementation of communication protocols.
|
#include "comms/options.h"
Option to specify numeric value serialisation offset.
Applicable only to numeric fields such as comms::field::IntValue or comms::field::EnumValue. The provided value will be added to the field's value and the result will be written to the buffer when serialising. Good example for such option would be serialising a "current year" value. Most protocols now specify it as an offset from year 2000 or later and written as a single byte, i.e. to specify year 2015 is to write value 15. However it may be inconvenient to manually adjust serialised/deserialised value by predefined offset 2000. To help with such case option comms::option::def::NumValueSerOffset can be used. For example:
Note that in the example above the field value (accessible by value() member function of the field) will have type std::uint16_t and will be equal to say 2015, while when serialised it consumes only 1 byte (thanks to comms::option::def::FixedLength option) and reduced value of 15 is written.
TOffset | Offset value to be added when serialising field. |