Control Libraries 7.4.0
Loading...
Searching...
No Matches
clproto.hpp
1#pragma once
2
3#include <cstdint>
4#include <chrono>
5#include <stdexcept>
6#include <string>
7#include <vector>
8
9#define CLPROTO_PACKING_MAX_FIELD_LENGTH (4096)
10#define CLPROTO_PACKING_MAX_FIELDS (64)
11
16namespace clproto {
17
24typedef uint32_t field_length_t;
25
31class DecodingException : public std::runtime_error {
32public:
33 explicit DecodingException(const std::string& msg);
34};
35
41class JsonParsingException : public std::runtime_error {
42public:
43 explicit JsonParsingException(const std::string& msg);
44};
45
56 UNKNOWN_MESSAGE = 0,
57 STATE_MESSAGE = 1,
58 SPATIAL_STATE_MESSAGE = 2,
59 CARTESIAN_STATE_MESSAGE = 3,
60 CARTESIAN_POSE_MESSAGE = 4,
61 CARTESIAN_TWIST_MESSAGE = 5,
62 CARTESIAN_ACCELERATION_MESSAGE = 6,
63 CARTESIAN_WRENCH_MESSAGE = 7,
64 JACOBIAN_MESSAGE = 8,
65 JOINT_STATE_MESSAGE = 9,
66 JOINT_POSITIONS_MESSAGE = 10,
67 JOINT_VELOCITIES_MESSAGE = 11,
68 JOINT_ACCELERATIONS_MESSAGE = 12,
69 JOINT_TORQUES_MESSAGE = 13,
70 SHAPE_MESSAGE = 14,
71 ELLIPSOID_MESSAGE = 15,
72 PARAMETER_MESSAGE = 16,
73 DIGITAL_IO_STATE_MESSAGE = 17,
74 ANALOG_IO_STATE_MESSAGE = 18
75};
76
87 UNKNOWN_PARAMETER = 0,
88 INT = 9,
89 INT_ARRAY = 10,
90 DOUBLE = 1,
91 DOUBLE_ARRAY = 2,
92 BOOL = 3,
93 BOOL_ARRAY = 4,
94 STRING = 5,
95 STRING_ARRAY = 6,
96 MATRIX = 7,
97 VECTOR = 8
98};
99
106bool is_valid(const std::string& msg);
107
114MessageType check_message_type(const std::string& msg);
115
123
131template<typename T>
132std::string encode(const T& obj);
133
143template<typename T>
144T decode(const std::string& msg);
145
156template<typename T>
157bool decode(const std::string& msg, T& obj);
158
172void pack_fields(const std::vector<std::string>& fields, char* data);
173
185std::vector<std::string> unpack_fields(const char* data);
186
193std::string to_json(const std::string& msg);
194
202template<typename T>
203std::string to_json(const T& obj) {
204 return to_json(encode<T>(obj));
205}
206
215std::string from_json(const std::string& json);
216
226template<typename T>
227T from_json(const std::string& json) {
228 return decode<T>(from_json(json));
229}
230}
A DecodingException is raised whenever a decoding operation fails due to invalid encoding.
Definition clproto.hpp:31
A JsonParsingException is raised whenever a JSON conversion operation fails due to invalid encoding.
Definition clproto.hpp:41
Bindings to encode and decode state objects into serialised binary message.
ParameterMessageType check_parameter_message_type(const std::string &msg)
Check which control libraries parameter type a serialized binary string can be decoded as,...
Definition clproto.cpp:63
uint32_t field_length_t
Size type used to indicate number of fields and field data length in pack_fields() and unpack_fields(...
Definition clproto.hpp:24
std::string from_json(const std::string &json)
Convert a JSON formatted state message description into a serialized binary string representation (wi...
Definition clproto.cpp:139
MessageType check_message_type(const std::string &msg)
Check which control libraries message type a serialized binary string can be decoded as,...
Definition clproto.cpp:40
T decode(const std::string &msg)
Decode a serialized binary string from wire format into a control libraries object instance.
MessageType
The MessageType enumeration contains the possible message types in the clproto.
Definition clproto.hpp:55
std::string to_json(const std::string &msg)
Convert a serialized binary string from wire format into a JSON formatted state message description.
Definition clproto.cpp:122
ParameterMessageType
The ParameterMessageType enumeration contains the possible value types contained in a parameter messa...
Definition clproto.hpp:86
void pack_fields(const std::vector< std::string > &fields, char *data)
Pack an ordered vector of encoded field messages into a single data array.
Definition clproto.cpp:72
std::string encode(const T &obj)
Encode a control libraries object into a serialized binary string representation (wire format).
std::vector< std::string > unpack_fields(const char *data)
Unpack a data array into an ordered vector of encoded field messages.
Definition clproto.cpp:96
bool is_valid(const std::string &msg)
Check if a serialized binary string can be decoded into a support control libraries message type.
Definition clproto.cpp:36