10 static const std::regex
TruePattern(
"^\\s*(true|[0-9]*[1-9][0-9]*)\\s*(?:#.*)?$");
13 static const std::regex
FalsePattern(
"^\\s*(false|0+)\\s*(?:#.*)?$");
19 static const std::regex
SignedPattern(
"^\\s*(-?[0-9]+)\\s*(?:#.*)?$");
22 static const std::regex
FloatPattern(
"^\\s*(-?[0-9]+(?:\\.[0-9]+)?)\\s*(?:#.*)?$");
29 _value.set_bool_value(
true);
34 _value.set_bool_value(
false);
48 _value.set_uint_value(std::stoull(value));
62 _value.set_int_value(std::stoll(value));
76 _value.set_double_value(std::stod(value));
88 _value.set_string_value(value);
92 :
Field(name, serializer)
95 if (primitiveSerializer !=
nullptr)
97 switch (primitiveSerializer->
GetType())
131 throw Exception(
"Unknown primitive type");
Serializer for primitive builtin types.
static const std::regex FalsePattern("^\\s*(false|0+)\\s*(?:#.*)?$")
virtual uint32_t GetDefaultLength(const FieldStack &fieldStack) const override
Get the length of the default value.
static const std::regex TruePattern("^\\s*(true|[0-9]*[1-9][0-9]*)\\s*(?:#.*)?$")
virtual void Serialize(ros::serialization::OStream &stream, const swarmio::data::Variant &value, const FieldStack &fieldStack) const override
Serialize a variant onto a stream.
Exception base class for swarmros exceptions.
virtual void EmitDefault(ros::serialization::OStream &stream, const FieldStack &fieldStack) const override
Write the default value to the stream.
void ParseSigned(const std::string &value)
Parse a signed integer value.
A Field represents an entry in a message reader that can read one of its fields.
void ParseFloat(const std::string &value)
Parse a floating point value.
void ParseString(const std::string &value)
Parse a string value.
void ParseBool(const std::string &value)
Parse a boolean value.
static const std::regex FloatPattern("^\\s*(-?[0-9]+(?:\\.[0-9]+)?)\\s*(?:#.*)?$")
PrimitiveType GetType() const
Get underlying data type.
void WriteTypeName(std::stringstream &stream, bool forHash) const
Get the type name for the serializer.
swarmio::data::Variant _value
Value.
Serializer is the base class for all binary message interpreters.
const std::string & GetName() const
Get the non-qualified name for the type behind the serializer.
static const std::regex SignedPattern("^\\s*(-?[0-9]+)\\s*(?:#.*)?$")
virtual uint32_t CalculateSerializedLength(const swarmio::data::Variant &value, const FieldStack &fieldStack) const override
Calculate the length of a serialized message in bytes.
virtual swarmio::data::Variant Deserialize(ros::serialization::IStream &stream, const FieldStack &fieldStack) const override
Deserialize a stream into a variant.
An exception that is expected to be caught and translated into another exception. ...
virtual void WriteDefinition(std::stringstream &stream, bool forHash) const override
Write the definition of this field to a string stream.
ConstantField(const std::string &name, const Serializer &serializer, const std::string &value)
Construct a new ConstantField object.
static const std::regex UnsignedPattern("^\\s*([0-9]+)\\s*(?:#.*)?$")
void ParseUnsigned(const std::string &value)
Parse an unsigned integer value.
std::string _rawValue
Raw string value.