Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/swri-robotics/message_serialization

A utility for serializing C++ structures (specifically ROS messages) into YAML and binary formatted files
https://github.com/swri-robotics/message_serialization

ros ros-industrial serialization

Last synced: about 22 hours ago
JSON representation

A utility for serializing C++ structures (specifically ROS messages) into YAML and binary formatted files

Lists

README

        

# message_serialization
![](https://github.com/swri-robotics/message_serialization/workflows/CI/badge.svg)
[![license - Apache 2.0](https://img.shields.io/:license-Apache%202.0-yellowgreen.svg)](https://opensource.org/licenses/Apache-2.0)

A header-only utility for serializing C++ structures (specifically ROS messages) into YAML-formatted and binary-formatted files that can be loaded to/from disk

## Usage

```c++
// Serialization headers
#include
#include

// Datatype-specific serialization header
#include

int main(int argc, char** argv)
{
// Create a structure to serialize
geometry_msgs::PoseStamped ps;
ps.header.frame = "world";
ps.header.stamp = ros::Time::now();
...

const std::string filename = "/path/to/save/dir/file.yaml";

// YAML Serialization
// Serialize the message
if(!message_serialization::serialize(filename, ps))
return -1;

// De-serialize the message
geometry_msgs::Pose new_ps;
if(!message_serialization::deserialize(filename, new_ps))
return -1;

// Binary serialization (ROS messages only)
// Serialize the message
if(!message_serialization::serializeToBinary(filename, ps))
return -1;

// De-serialize the message
if(!message_serialization::deserializeFromBinary(filename, new_ps))
return -1;

return 0;
}
```

## Customization

Any custom C++ structure can be serialized to YAML with this library, provided that a specific template structure for the custom datatype be specialized in the YAML namespace:

```c++
struct CustomStruct;

namespace YAML
{
template<>
struct convert
{
static Node encode(const CustomStruct& rhs);
static bool decode(const Node& node, CustomStruct& rhs);
};
}
```

See the implementations in the `include` directory for examples on how to implement this structure for a custom data type.