json_conversions.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Roboception GmbH
3  *
4  * Author: Elena Gambaro
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of the copyright holder nor the names of its contributors
17  * may be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef RC_TAGDETECT_JSON_CONVERSIONS_H
34 #define RC_TAGDETECT_JSON_CONVERSIONS_H
35 
37 
38 #include <rc_common_msgs/ReturnCode.h>
39 
40 #include <rc_tagdetect_client/Tag.h>
41 #include <rc_tagdetect_client/DetectedTag.h>
42 
43 #include <rc_tagdetect_client/DetectTags.h>
44 
45 namespace rc_common_msgs
46 {
47 inline void from_json(const nlohmann::json& j, ReturnCode& r)
48 {
49  j.at("value").get_to(r.value);
50  j.at("message").get_to(r.message);
51 }
52 
53 } // namespace rc_common_msgs
54 
56 {
57 inline void to_json(nlohmann::json& j, const Tag& r)
58 {
59  j["id"] = r.id;
60  j["size"] = r.size;
61 }
62 
63 inline void from_json(const nlohmann::json& j, Tag& r)
64 {
65  j.at("id").get_to(r.id);
66  j.at("size").get_to(r.size);
67 }
68 
69 inline void from_json(const nlohmann::json& j, DetectedTag& r)
70 {
71  j.at("timestamp").get_to(r.header.stamp);
72  j.at("pose_frame").get_to(r.header.frame_id);
73  j.at("id").get_to(r.tag.id);
74  j.at("size").get_to(r.tag.size);
75  j.at("instance_id").get_to(r.instance_id);
76  j.at("pose").get_to(r.pose.pose);
77  r.pose.header.stamp = r.header.stamp;
78  r.pose.header.frame_id = r.header.frame_id;
79 }
80 
81 inline void to_json(nlohmann::json& j, const DetectTagsRequest& r)
82 {
83  j["tags"] = r.tags;
84  if (!r.pose_frame.empty())
85  {
86  j["pose_frame"] = r.pose_frame;
87  if (r.pose_frame == "external")
88  {
89  j["robot_pose"] = r.robot_pose;
90  }
91  }
92 }
93 
94 inline void from_json(const nlohmann::json& j, DetectTagsResponse& r)
95 {
96  j.at("tags").get_to(r.tags);
97  j.at("timestamp").get_to(r.timestamp);
98  j.at("return_code").get_to(r.return_code);
99 }
100 
101 } // namespace rc_tagdetect_client
102 
103 #endif // RC_TAGDETECT_JSON_CONVERSIONS_H
int j
void to_json(nlohmann::json &j, const DetectTagsRequest &r)
nlohmann::json json
Definition: rest_helper.h:41
void from_json(const nlohmann::json &j, ReturnCode &r)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15