Skip to main content

cu_ros_payloads/
sensor_msgs.rs

1use compact_str::CompactString;
2use cu_sensor_payloads::PointCloudSoa;
3use serde::{Deserialize, Serialize};
4
5use crate::{RosMsgAdapter, builtin::Header};
6
7// sensor_msgs/PointField
8#[derive(Clone, Debug, Serialize, Deserialize)]
9pub struct PointField {
10    pub name: CompactString,
11    pub offset: u32,
12    pub datatype: u8,
13    pub count: u32,
14}
15
16// sensor_msgs/PointCloud2 like struct
17#[derive(Clone, Debug, Serialize, Deserialize)]
18pub struct PointCloud2 {
19    pub header: Header,
20    pub height: u32, //
21    pub width: u32,  // Length of the point cloud
22    pub pointfields: Vec<PointField>,
23    pub is_bigendian: bool,
24    pub point_step: u32, // Length of a point in bytes
25    pub row_step: u32,   // Length of a row in bytes
26    pub data: Vec<u8>,   // size is (row_step*height)
27    pub is_dense: bool,  // True if there are no invalid points
28}
29
30impl<const N: usize> RosMsgAdapter<'static> for PointCloudSoa<N> {
31    type Output = PointCloud2;
32
33    fn namespace() -> &'static str {
34        "sensor_msgs"
35    }
36
37    fn type_name() -> &'static str {
38        "PointCloud2"
39    }
40
41    fn type_hash() -> &'static str {
42        "RIHS01_9198cabf7da3796ae6fe19c4cb3bdd3525492988c70522628af5daa124bae2b5"
43    }
44}
45
46impl<const N: usize> From<&PointCloudSoa<N>> for PointCloud2 {
47    #[allow(unreachable_code)]
48    fn from(_: &PointCloudSoa<N>) -> Self {
49        PointCloud2 {
50            header: todo!(),
51            height: 1,
52            width: todo!(),
53            pointfields: todo!(),
54            is_bigendian: true,
55            point_step: todo!(),
56            row_step: todo!(),
57            data: todo!(),
58            is_dense: todo!(),
59        }
60    }
61}