COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
comms::option::def::NumValueSerOffset< TOffset > Struct Template Reference

#include "comms/options.h"

Detailed Description

template<std::intmax_t TOffset>
struct comms::option::def::NumValueSerOffset< TOffset >

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:

using MyField =
MyFieldBase,
std::uint16_t,
>;
Base class to all the field classes.
Definition Field.h:33
Field that represent integral value.
Definition IntValue.h:72
Option used to specify number of bytes that is used for field serialisation.
Definition options.h:280
Option to specify numeric value serialisation offset.
Definition options.h:378

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.

Template Parameters
TOffsetOffset value to be added when serialising field.

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