Control Libraries 6.3.4
Loading...
Searching...
No Matches
clproto.h
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
31typedef std::chrono::nanoseconds timestamp_duration_t;
32
38class DecodingException : public std::runtime_error {
39public:
40 explicit DecodingException(const std::string& msg);
41};
42
48class JsonParsingException : public std::runtime_error {
49public:
50 explicit JsonParsingException(const std::string& msg);
51};
52
63 UNKNOWN_MESSAGE = 0,
64 STATE_MESSAGE = 1,
65 SPATIAL_STATE_MESSAGE = 2,
66 CARTESIAN_STATE_MESSAGE = 3,
67 CARTESIAN_POSE_MESSAGE = 4,
68 CARTESIAN_TWIST_MESSAGE = 5,
69 CARTESIAN_ACCELERATION_MESSAGE = 6,
70 CARTESIAN_WRENCH_MESSAGE = 7,
71 JACOBIAN_MESSAGE = 8,
72 JOINT_STATE_MESSAGE = 9,
73 JOINT_POSITIONS_MESSAGE = 10,
74 JOINT_VELOCITIES_MESSAGE = 11,
75 JOINT_ACCELERATIONS_MESSAGE = 12,
76 JOINT_TORQUES_MESSAGE = 13,
77 SHAPE_MESSAGE = 14,
78 ELLIPSOID_MESSAGE = 15,
79 PARAMETER_MESSAGE = 16
80};
81
92 UNKNOWN_PARAMETER = 0,
93 INT = 9,
94 INT_ARRAY = 10,
95 DOUBLE = 1,
96 DOUBLE_ARRAY = 2,
97 BOOL = 3,
98 BOOL_ARRAY = 4,
99 STRING = 5,
100 STRING_ARRAY = 6,
101 MATRIX = 7,
102 VECTOR = 8
103};
104
111bool is_valid(const std::string& msg);
112
119MessageType check_message_type(const std::string& msg);
120
128
136template<typename T>
137std::string encode(const T& obj);
138
148template<typename T>
149T decode(const std::string& msg);
150
161template<typename T>
162bool decode(const std::string& msg, T& obj);
163
177void pack_fields(const std::vector<std::string>& fields, char* data);
178
190std::vector<std::string> unpack_fields(const char* data);
191
198std::string to_json(const std::string& msg);
199
207template<typename T>
208std::string to_json(const T& obj) {
209 return to_json(encode<T>(obj));
210}
211
220std::string from_json(const std::string& json);
221
231template<typename T>
232T from_json(const std::string& json) {
233 return decode<T>(from_json(json));
234}
235}
A DecodingException is raised whenever a decoding operation fails due to invalid encoding.
Definition: clproto.h:38
A JsonParsingException is raised whenever a JSON conversion operation fails due to invalid encoding.
Definition: clproto.h:48
Bindings to encode and decode state objects into serialised binary message.
std::chrono::nanoseconds timestamp_duration_t
Duration type to use when representing chrono timestamps as integer count since epoch.
Definition: clproto.h:31
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:61
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.h: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:137
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:38
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.h:62
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:120
ParameterMessageType
The ParameterMessageType enumeration contains the possible value types contained in a parameter messa...
Definition: clproto.h:91
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:70
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:94
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:34