Function Cloudini::SerializeCompressedPointCloud2

Function Documentation

void Cloudini::SerializeCompressedPointCloud2(const sensor_msgs::msg::PointCloud2 &msg, float resolution, std::vector<uint8_t> &serialized_dds_msg)

Compress a PointCloud2 and serialize as a CDR-encoded CompressedPointCloud2 DDS message.

This is a convenience function that combines field conversion, resolution profiling, encoding, and CDR serialization into a single call. The output can be published directly via a generic publisher.

Example (simple):

std::vector<uint8_t> buffer;
Cloudini::SerializeCompressedPointCloud2(pcd_msg, 0.001, buffer);

Example (zero-copy publish):

std::vector<uint8_t> buffer;  // keep as member to reuse allocation
Cloudini::SerializeCompressedPointCloud2(pcd_msg, 0.001, buffer);
rclcpp::SerializedMessage ser_msg;
ser_msg.get_rcl_serialized_message().buffer = buffer.data();
ser_msg.get_rcl_serialized_message().buffer_length = buffer.size();
generic_publisher->publish(ser_msg);
// null out buffer pointer before ser_msg destruction to prevent double-free
ser_msg.get_rcl_serialized_message().buffer = nullptr;
ser_msg.get_rcl_serialized_message().buffer_length = 0;

Parameters:
  • msg – The PointCloud2 message to compress

  • resolution – The quantization resolution for FLOAT32 fields (e.g. 0.001 for 1mm)

  • serialized_dds_msg – Output buffer for the CDR-serialized CompressedPointCloud2