Serializer.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <swarmio/data/Variant.pb.h>
5 #include <swarmio/data/discovery/Schema.pb.h>
6 #include <ros/serialization.h>
7 #include <string>
8 #include <memory>
9 
10 namespace swarmros::introspection
11 {
17  class Serializer
18  {
19  private:
20 
25  static std::map<std::string, std::unique_ptr<Serializer>> _defaultSerializers;
26 
32  static std::map<std::string, std::unique_ptr<Serializer>> LoadDefaultSerializers();
33 
38  std::string _name;
39 
40  protected:
41 
46  Serializer(const std::string& name)
47  : _name(name) { }
48 
56  static const Serializer& SerializerForType(const std::string& type, const std::string& parentPackage);
57 
58  public:
59 
66  const std::string& GetName() const
67  {
68  return _name;
69  }
70 
77  virtual const std::string& GetFullName() const
78  {
79  return _name;
80  }
81 
88  virtual uint32_t GetDefaultLength(const FieldStack& fieldStack) const = 0;
89 
97  virtual uint32_t CalculateSerializedLength(const swarmio::data::Variant& value, const FieldStack& fieldStack) const = 0;
98 
106  virtual void Serialize(ros::serialization::OStream& stream, const swarmio::data::Variant& value, const FieldStack& fieldStack) const = 0;
107 
115  virtual swarmio::data::Variant Deserialize(ros::serialization::IStream& stream, const FieldStack& fieldStack) const = 0;
116 
125  virtual swarmio::data::Variant DeserializeArray(ros::serialization::IStream& stream, uint32_t count, const FieldStack& fieldStack) const = 0;
126 
133  virtual void EmitDefault(ros::serialization::OStream& stream, const FieldStack& fieldStack) const = 0;
134 
140  virtual swarmio::data::discovery::Field GetFieldDescriptor() const = 0;
141 
146  virtual ~Serializer() { }
147  };
148 }
virtual swarmio::data::Variant Deserialize(ros::serialization::IStream &stream, const FieldStack &fieldStack) const =0
Deserialize a stream into a variant.
virtual uint32_t CalculateSerializedLength(const swarmio::data::Variant &value, const FieldStack &fieldStack) const =0
Calculate the length of a serialized message in bytes.
virtual swarmio::data::Variant DeserializeArray(ros::serialization::IStream &stream, uint32_t count, const FieldStack &fieldStack) const =0
Deserialize a stream into a variant array.
virtual ~Serializer()
Destructor.
Definition: Serializer.h:146
Serializer(const std::string &name)
Construct a new Serializer object.
Definition: Serializer.h:46
virtual swarmio::data::discovery::Field GetFieldDescriptor() const =0
Build a field descriptor for the underlying type.
static std::map< std::string, std::unique_ptr< Serializer > > LoadDefaultSerializers()
Load the list of default serializers.
Definition: Serializer.cpp:13
virtual void EmitDefault(ros::serialization::OStream &stream, const FieldStack &fieldStack) const =0
Write the default value to the stream.
std::string _name
Non-qualified name for the type behind the serializer.
Definition: Serializer.h:38
virtual const std::string & GetFullName() const
Get the fully qualified name for the type behind the serializer.
Definition: Serializer.h:77
static std::map< std::string, std::unique_ptr< Serializer > > _defaultSerializers
List of built-in default serializers.
Definition: Serializer.h:25
Serializer is the base class for all binary message interpreters.
Definition: Serializer.h:17
const std::string & GetName() const
Get the non-qualified name for the type behind the serializer.
Definition: Serializer.h:66
static const Serializer & SerializerForType(const std::string &type, const std::string &parentPackage)
Look up or build a reader for a message type.
Definition: Serializer.cpp:40
virtual uint32_t GetDefaultLength(const FieldStack &fieldStack) const =0
Get the length of the default value.
virtual void Serialize(ros::serialization::OStream &stream, const swarmio::data::Variant &value, const FieldStack &fieldStack) const =0
Serialize a variant onto a stream.


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