MessageSerializer.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <list>
7 #include <functional>
8 
10 {
16  {
17  private:
18 
23  static std::map<std::string, std::unique_ptr<MessageSerializer>> _messageSerializers;
24 
29  std::list<std::unique_ptr<Field>> _fields;
30 
35  std::list<ConstantField> _constants;
36 
42  bool _hasHeader;
43 
50  const Field* _shortcut;
51 
56  std::string _package;
57 
62  std::string _fullName;
63 
68  std::string _canonicalDefinition;
69 
74  std::string _hash;
75 
81  std::string BuildCanonicalDefinition();
82 
88  std::string CalculateHash();
89 
90  public:
91 
99  static const MessageSerializer& MessageSerializerForType(const std::string& type, const std::string& parentPackage);
100 
108  MessageSerializer(const std::string& package, const std::string& name, const std::string& path);
109 
115  const std::string& GetPackage() const
116  {
117  return _package;
118  }
119 
126  virtual const std::string& GetFullName() const override
127  {
128  return _fullName;
129  }
130 
136  const std::string& GetHash() const
137  {
138  return _hash;
139  }
140 
146  const std::string& GetCanonicalDefinition() const
147  {
148  return _canonicalDefinition;
149  }
150 
157  bool HasHeader() const
158  {
159  return _hasHeader;
160  }
161 
168  virtual uint32_t GetDefaultLength(const FieldStack& fieldStack) const override;
169 
177  virtual uint32_t CalculateSerializedLength(const swarmio::data::Variant& value, const FieldStack& fieldStack) const override;
178 
186  virtual swarmio::data::Variant Deserialize(ros::serialization::IStream& stream, const FieldStack& fieldStack) const override;
187 
196  virtual swarmio::data::Variant DeserializeArray(ros::serialization::IStream& stream, uint32_t count, const FieldStack& fieldStack) const override;
197 
205  virtual void Serialize(ros::serialization::OStream& stream, const swarmio::data::Variant& value, const FieldStack& fieldStack) const override;
206 
213  virtual void EmitDefault(ros::serialization::OStream& stream, const FieldStack& fieldStack) const override;
214 
220  virtual swarmio::data::discovery::Field GetFieldDescriptor() const override;
221 
231  uint32_t CalculateSerializedLength(const swarmio::data::Variant& value, unsigned skipCount, const FieldStack& fieldStack) const;
232 
242  uint32_t CalculateSerializedLength(const swarmio::data::Map& value, unsigned skipCount, const FieldStack& fieldStack) const;
243 
253  void Serialize(ros::serialization::OStream& stream, const swarmio::data::Variant& value, unsigned skipCount, const FieldStack& fieldStack) const;
254 
264  void Serialize(ros::serialization::OStream& stream, const swarmio::data::Map& value, unsigned skipCount, const FieldStack& fieldStack) const;
265 
275  swarmio::data::Variant Deserialize(ros::serialization::IStream& stream, unsigned skipCount, const FieldStack& fieldStack) const;
276 
286  void Deserialize(ros::serialization::IStream& stream, swarmio::data::Map& map, unsigned skipCount, const FieldStack& fieldStack) const;
287 
295  swarmio::data::discovery::Schema GetSchemaDescriptor(unsigned skipCount) const;
296 
303  void EnumerateFields(std::function<bool(unsigned, const Field&)> enumerator) const;
304  };
305 }
MessageSerializer(const std::string &package, const std::string &name, const std::string &path)
Construct a new MessageSerializer object.
virtual swarmio::data::Variant DeserializeArray(ros::serialization::IStream &stream, uint32_t count, const FieldStack &fieldStack) const override
Deserialize a stream into a variant array.
bool HasHeader() const
Checks whether the message fits the requirements of a message with a header.
std::string _hash
MD5 hash of the message.
const std::string & GetCanonicalDefinition() const
Get the canonical definition of the message.
void EnumerateFields(std::function< bool(unsigned, const Field &)> enumerator) const
Enumerate the fields of the message with a function.
const std::string & GetHash() const
Get the MD5 hash of the message definition file.
static const MessageSerializer & MessageSerializerForType(const std::string &type, const std::string &parentPackage)
Look up or build a reader for a message type.
const Field * _shortcut
For certain messages, the normal field processing is skipped and a single field is used to deserializ...
static std::map< std::string, std::unique_ptr< MessageSerializer > > _messageSerializers
Map of message serializers.
const std::string & GetPackage() const
Get package name.
Serializer for full-fledged message types.
A Field represents an entry in a message reader that can read one of its fields.
Definition: Field.h:15
bool _hasHeader
Whether the message begins with the standard header.
std::list< ConstantField > _constants
Constant fields.
virtual swarmio::data::Variant Deserialize(ros::serialization::IStream &stream, const FieldStack &fieldStack) const override
Deserialize a stream into a variant.
std::list< std::unique_ptr< Field > > _fields
Variable fields.
virtual void Serialize(ros::serialization::OStream &stream, const swarmio::data::Variant &value, const FieldStack &fieldStack) const override
Serialize a variant onto a stream.
virtual uint32_t GetDefaultLength(const FieldStack &fieldStack) const override
Get the length of the default value.
virtual void EmitDefault(ros::serialization::OStream &stream, const FieldStack &fieldStack) const override
Write the default value to the stream.
Serializer is the base class for all binary message interpreters.
Definition: Serializer.h:17
std::string CalculateHash()
Calculate the MD5 hash used to identify the message type.
std::string BuildCanonicalDefinition()
Build a canonical definition for the message.
virtual swarmio::data::discovery::Field GetFieldDescriptor() const override
Build a field descriptor for the underlying type.
virtual const std::string & GetFullName() const override
Get the fully qualified name for the type behind the serializer.
virtual uint32_t CalculateSerializedLength(const swarmio::data::Variant &value, const FieldStack &fieldStack) const override
Calculate the length of a serialized message in bytes.
std::string _canonicalDefinition
Canonical definition of the message.
swarmio::data::discovery::Schema GetSchemaDescriptor(unsigned skipCount) const
Build a field descriptor for the underlying type, with or without its header.


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48