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: 2 months ago
JSON representation
A utility for serializing C++ structures (specifically ROS messages) into YAML and binary formatted files
- Host: GitHub
- URL: https://github.com/swri-robotics/message_serialization
- Owner: swri-robotics
- License: apache-2.0
- Created: 2020-06-29T18:38:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-24T02:41:02.000Z (about 4 years ago)
- Last Synced: 2024-08-03T02:02:45.531Z (5 months ago)
- Topics: ros, ros-industrial, serialization
- Language: C++
- Homepage:
- Size: 36.1 KB
- Stars: 11
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ros-tools - message_serialization - 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. ![message_serialization](https://img.shields.io/github/stars/swri-robotics/message_serialization.svg?style=flat&label=Star&maxAge=86400) (Other / Sensors)
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
#includeint 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.