Serializer.cpp
Go to the documentation of this file.
5 #include <regex>
6 #include <ros/package.h>
7 
8 using namespace swarmros;
9 using namespace swarmros::introspection;
10 
11 std::map<std::string, std::unique_ptr<Serializer>> Serializer::_defaultSerializers = Serializer::LoadDefaultSerializers();
12 
13 std::map<std::string, std::unique_ptr<Serializer>> Serializer::LoadDefaultSerializers()
14 {
15  std::map<std::string, std::unique_ptr<Serializer>> map;
16 
17  // Primitive types
18  map["bool"] = std::make_unique<PrimitiveSerializer>("bool", PrimitiveType::BOOL);
19  map["int8"] = std::make_unique<PrimitiveSerializer>("int8", PrimitiveType::INT8);
20  map["uint8"] = std::make_unique<PrimitiveSerializer>("uint8", PrimitiveType::UINT8);
21  map["int16"] = std::make_unique<PrimitiveSerializer>("int16", PrimitiveType::INT16);
22  map["uint16"] = std::make_unique<PrimitiveSerializer>("uint16", PrimitiveType::UINT16);
23  map["int32"] = std::make_unique<PrimitiveSerializer>("int32", PrimitiveType::INT32);
24  map["uint32"] = std::make_unique<PrimitiveSerializer>("uint32", PrimitiveType::UINT32);
25  map["int64"] = std::make_unique<PrimitiveSerializer>("int64", PrimitiveType::INT64);
26  map["uint64"] = std::make_unique<PrimitiveSerializer>("uint64", PrimitiveType::UINT64);
27  map["float32"] = std::make_unique<PrimitiveSerializer>("float32", PrimitiveType::FLOAT32);
28  map["float64"] = std::make_unique<PrimitiveSerializer>("float64", PrimitiveType::FLOAT64);
29  map["string"] = std::make_unique<PrimitiveSerializer>("string", PrimitiveType::STRING);
30  map["time"] = std::make_unique<PrimitiveSerializer>("time", PrimitiveType::TIME);
31  map["duration"] = std::make_unique<PrimitiveSerializer>("duration", PrimitiveType::DURATION);
32 
33  // Deprecated aliases
34  map["byte"] = std::make_unique<PrimitiveSerializer>("byte", PrimitiveType::INT8);
35  map["char"] = std::make_unique<PrimitiveSerializer>("char", PrimitiveType::UINT8);
36 
37  return map;
38 }
39 
40 const Serializer& Serializer::SerializerForType(const std::string& messageType, const std::string& parentPackage)
41 {
42  auto found = _defaultSerializers.find(messageType);
43  if (found != _defaultSerializers.end())
44  {
45  return *found->second;
46  }
47  else
48  {
49  return MessageSerializer::MessageSerializerForType(messageType, parentPackage);
50  }
51 }
static const MessageSerializer & MessageSerializerForType(const std::string &type, const std::string &parentPackage)
Look up or build a reader for a message type.
static std::map< std::string, std::unique_ptr< Serializer > > LoadDefaultSerializers()
Load the list of default serializers.
Definition: Serializer.cpp:13
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
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


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