25 #ifndef SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MESSAGE_PARSER_H_ 26 #define SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MESSAGE_PARSER_H_ 28 #ifdef MESSAGE_SUPPORT 30 #include <corbo-communication/messages/descriptor_extensions.pb.h> 31 #include <google/protobuf/message.h> 60 struct FieldInformation
63 std::string field_name;
64 std::vector<std::string> enum_list;
65 std::list<std::string> nested_names;
69 const google::protobuf::FieldDescriptor* field_raw =
nullptr;
70 google::protobuf::Message* message_raw =
nullptr;
71 const google::protobuf::OneofDescriptor* oneof_descriptor =
nullptr;
72 const google::protobuf::FieldDescriptor* oneof_selected_field =
nullptr;
74 bool new_message =
true;
78 std::pair<bool, std::string> label;
79 std::pair<bool, std::string> description;
80 std::pair<bool, std::string> msg_description;
81 std::pair<bool, std::string> default_value;
82 std::pair<bool, double> min_value;
83 std::pair<bool, double> max_value;
84 bool dynamic_size =
false;
85 std::pair<bool, int> min_size;
86 std::pair<bool, int> max_size;
87 std::pair<bool, bool> info_text;
89 std::pair<bool, messages::GuiType> gui_type;
90 bool collapsed =
false;
91 bool update_signals =
false;
92 bool print_description =
false;
96 enum class MessageEvent { MessageStart, MessageEnd, OneOf };
99 using CbValue = std::function<void(const T&, const FieldInformation&)>;
101 using CbMessageEvent = std::function<void(const MessageEvent&, const FieldInformation&)>;
104 void setCallbackValueInt32(CbValue<std::int32_t> fun_value_int32) { _fun_value_int32 = fun_value_int32; }
106 void setCallbackValueInt32Array(CbValue<std::vector<std::int32_t>> fun_value_int32_array) { _fun_value_int32_array = fun_value_int32_array; }
109 void setCallbackValueUInt32(CbValue<std::uint32_t> fun_value_uint32) { _fun_value_uint32 = fun_value_uint32; }
111 void setCallbackValueUInt32Array(CbValue<std::vector<std::uint32_t>> fun_value_uint32_array) { _fun_value_uint32_array = fun_value_uint32_array; }
114 void setCallbackValueInt64(CbValue<std::int64_t> fun_value_int64) { _fun_value_int64 = fun_value_int64; }
116 void setCallbackValueInt64Array(CbValue<std::vector<std::int64_t>> fun_value_int64_array) { _fun_value_int64_array = fun_value_int64_array; }
119 void setCallbackValueUInt64(CbValue<std::uint64_t> fun_value_uint64) { _fun_value_uint64 = fun_value_uint64; }
121 void setCallbackValueUInt64Array(CbValue<std::vector<std::uint64_t>> fun_value_uint64_array) { _fun_value_uint64_array = fun_value_uint64_array; }
124 void setCallbackValueFloat(CbValue<float> fun_value_float) { _fun_value_float = fun_value_float; }
126 void setCallbackValueFloatArray(CbValue<std::vector<float>> fun_value_float_array) { _fun_value_float_array = fun_value_float_array; }
129 void setCallbackValueDouble(CbValue<double> fun_value_double) { _fun_value_double = fun_value_double; }
131 void setCallbackValueDoubleArray(CbValue<std::vector<double>> fun_value_double_array) { _fun_value_double_array = fun_value_double_array; }
134 void setCallbackValueString(CbValue<std::string> fun_value_string) { _fun_value_string = fun_value_string; }
136 void setCallbackValueStringArray(CbValue<std::vector<std::string>> fun_value_string_array) { _fun_value_string_array = fun_value_string_array; }
139 void setCallbackValueStringInfo(CbValue<std::string> fun_value_string_info) { _fun_value_string_info = fun_value_string_info; }
142 void setCallbackValueBool(CbValue<bool> fun_value_bool) { _fun_value_bool = fun_value_bool; }
144 void setCallbackValueBoolArray(CbValue<std::vector<bool>> fun_value_bool_array) { _fun_value_bool_array = fun_value_bool_array; }
147 void setCallbackValueEnum(CbValue<std::string> fun_value_enum) { _fun_value_enum = fun_value_enum; }
149 void setCallbackValueEnumArray(CbValue<std::vector<std::string>> fun_value_enum_array) { _fun_value_enum_array = fun_value_enum_array; }
152 void setCallbackMessageEvent(CbMessageEvent fun_msg_event) { _fun_msg_event = fun_msg_event; }
162 void parse(google::protobuf::Message* message,
bool expand_oneof =
true,
bool skip_inactive_oneof =
true,
163 std::list<std::string>* nested_names =
nullptr);
176 void parseField(google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field,
bool expand_oneof =
true,
177 bool expand_first_oneof =
true,
bool skip_inactive_oneof =
true, std::list<std::string>* nested_names =
nullptr);
180 void setVerbose(
bool active) { _verbose = active; }
183 static std::string nestedNamesToString(
const std::list<std::string>& namespaces);
187 void consumeFieldMessage(google::protobuf::Message* message,
const google::protobuf::Reflection* reflection,
188 const google::protobuf::FieldDescriptor* field,
bool expand_oneof =
true,
bool skip_inactive_oneof =
true,
189 std::list<std::string>* nested_names =
nullptr);
191 void consumeFieldValue(google::protobuf::Message* message,
const google::protobuf::Reflection* reflection,
192 const google::protobuf::FieldDescriptor* field, std::list<std::string>* nested_names =
nullptr);
195 void getFieldInformation(google::protobuf::Message* message,
const google::protobuf::FieldDescriptor* field, FieldInformation&
info,
196 std::list<std::string>* nested_names =
nullptr,
bool is_message =
false);
198 CbValue<std::int32_t> _fun_value_int32;
199 CbValue<std::vector<std::int32_t>> _fun_value_int32_array;
200 CbValue<std::uint32_t> _fun_value_uint32;
201 CbValue<std::vector<std::uint32_t>> _fun_value_uint32_array;
202 CbValue<std::int64_t> _fun_value_int64;
203 CbValue<std::vector<std::int64_t>> _fun_value_int64_array;
204 CbValue<std::uint64_t> _fun_value_uint64;
205 CbValue<std::vector<std::uint64_t>> _fun_value_uint64_array;
206 CbValue<float> _fun_value_float;
207 CbValue<std::vector<float>> _fun_value_float_array;
208 CbValue<double> _fun_value_double;
209 CbValue<std::vector<double>> _fun_value_double_array;
210 CbValue<std::string> _fun_value_string;
211 CbValue<std::vector<std::string>> _fun_value_string_array;
212 CbValue<std::string> _fun_value_string_info;
213 CbValue<bool> _fun_value_bool;
214 CbValue<std::vector<bool>> _fun_value_bool_array;
215 CbValue<std::string> _fun_value_enum;
216 CbValue<std::vector<std::string>> _fun_value_enum_array;
218 CbMessageEvent _fun_msg_event;
220 bool _verbose =
true;
225 #endif // MESSAGE_SUPPORT 227 #endif // SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MESSAGE_PARSER_H_