From a5bd5ad76e27a11a9fc259d137fb663ee28ce683 Mon Sep 17 00:00:00 2001
From: Tommy Persson <tommy.persson@liu.se>
Date: Wed, 31 Aug 2022 20:40:51 +0200
Subject: [PATCH] Adding json coding of PointCloud2.

---
 package.xml                       |  1 +
 src/codegen_json_bson/__init__.py | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/package.xml b/package.xml
index af9c9f0..9c174ca 100644
--- a/package.xml
+++ b/package.xml
@@ -44,6 +44,7 @@
   <!--   <test_depend>gtest</test_depend> -->
   <buildtool_depend>catkin</buildtool_depend>
   <depend>gazebo_msgs</depend>
+  <depend>sensor_msgs</depend>
   <depend>lrs_msgs_common</depend>
   <depend>lrs_srvs_wdb</depend>
   <depend>tf</depend>
diff --git a/src/codegen_json_bson/__init__.py b/src/codegen_json_bson/__init__.py
index 0ede9fb..05f2741 100644
--- a/src/codegen_json_bson/__init__.py
+++ b/src/codegen_json_bson/__init__.py
@@ -427,7 +427,7 @@ def type_is_complex(ty):
                      "FIPAAclMessage", "PathElementTree", "TSTExecStatus", "TSTExecInfo",
                      "BoundingBoxCVL", "ImageSize", "CVLImage", "DiagnosticStatus", "MultiArrayDimension",
                      "Point32", "KeyValue", "TransformStamped", "ChannelFloat32", "PointField", "Marker",
-                     "LandingDetection", "CompressedImage",
+                     "LandingDetection", "CompressedImage", "PointCloud2",
                      "TargetPrediction", "DepotBookingInfo", "SalientPoint", "LrsVisionDetection",
                      "DelLogItem", "StringList", "Team", "VisionDetection", "SearchUnit", "SearchCell",
                      "PathElement", "ResourceInfo", "Interval", "NavigationData", "GeopointHeadingSpeed",
@@ -450,6 +450,8 @@ def field_assignment_get_json_value(field, ty, fieldtype, name):
     if ty == "bytes":
         res = ""
         res += f'// {ty} {field} {fieldtype} {name}\n'
+        if name == "PointCloud2":
+            res += f'  res["{field}"] = macaron::Base64::Encode(msg.{field});\n'
         if name == "CompressedImage":
             res += f'  res["{field}"] = macaron::Base64::Encode(msg.{field});\n'
         if name == "CVLImage":
@@ -507,6 +509,16 @@ def field_assignment_parse_json_value(field, ty, fieldtype, name):
             res += "  for (unsigned int i=0; i<out.size(); i++) {\n"
             res += f'    msg.{field}.push_back(out[i]);\n'
             res += "  }"
+        if name == "PointCloud2":
+            res += "  std::string out;\n"
+            res += f'  std::string res = macaron::Base64::Decode(m["{field}"].asString(), out);\n'
+            res += "  if (res != \"\") {\n"
+            res += "    ROS_ERROR(\"FAILED TO DECODE CVL IMAGE Base64 Data: %s\", res.c_str());\n"
+            res += "    return false;\n"
+            res += "  }\n"
+            res += "  for (unsigned int i=0; i<out.size(); i++) {\n"
+            res += f'    msg.{field}.push_back(out[i]);\n'
+            res += "  }"
         return res
     listprefix = ""
     gen_for_list = True
-- 
GitLab