use alloc::string::{String, ToString};
#[derive(Clone, Debug, Default, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct TimeMsg {
pub sec: i32,
pub nanosec: u32,
}
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct HeaderMsg {
pub seq: u32,
pub stamp: TimeMsg,
pub frame_id: String,
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub struct PointFieldMsg {
#[cfg_attr(feature = "rkyv", rkyv(with = crate::ros::cowstr_with::AsString))]
pub name: CowStr,
pub offset: u32,
pub datatype: u8,
pub count: u32,
}
impl Default for PointFieldMsg {
fn default() -> Self {
Self {
name: make_field_name(""),
offset: 0,
datatype: 0,
count: 1,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CowStr(pub alloc::borrow::Cow<'static, str>);
impl From<&'static str> for CowStr {
fn from(s: &'static str) -> Self {
Self(alloc::borrow::Cow::Borrowed(s))
}
}
impl From<String> for CowStr {
fn from(s: String) -> Self {
Self(alloc::borrow::Cow::Owned(s))
}
}
impl CowStr {
#[must_use]
pub fn into_owned(self) -> alloc::string::String {
match self.0 {
alloc::borrow::Cow::Owned(s) => s,
alloc::borrow::Cow::Borrowed(b) => b.to_string(),
}
}
#[must_use]
pub fn as_str(&self) -> &str {
self.0.as_ref()
}
}
pub fn make_field_name(s: &'static str) -> CowStr {
CowStr::from(s)
}
impl core::ops::Deref for CowStr {
type Target = str;
fn deref(&self) -> &Self::Target {
self.0.as_ref()
}
}
impl PartialEq<str> for CowStr {
fn eq(&self, other: &str) -> bool {
self.0.as_ref() == other
}
}
impl PartialEq<&str> for CowStr {
fn eq(&self, other: &&str) -> bool {
self.0.as_ref() == *other
}
}
#[cfg(feature = "rkyv")]
pub mod cowstr_with {
use super::CowStr;
use alloc::borrow::Cow;
use alloc::string::String;
use rkyv::rancor::Fallible;
use rkyv::with::{ArchiveWith, DeserializeWith, SerializeWith};
use rkyv::{Archive, Deserialize, Serialize};
pub struct AsString;
impl ArchiveWith<CowStr> for AsString {
type Archived = <String as Archive>::Archived;
type Resolver = <String as Archive>::Resolver;
fn resolve_with(
field: &CowStr,
resolver: Self::Resolver,
out: rkyv::Place<Self::Archived>,
) {
let s: String = match &field.0 {
Cow::Owned(s) => s.clone(),
Cow::Borrowed(b) => b.to_string(),
};
<String as Archive>::resolve(&s, resolver, out);
}
}
impl<S> SerializeWith<CowStr, S> for AsString
where
S: Fallible + ?Sized,
<S as Fallible>::Error: rkyv::rancor::Source,
str: rkyv::SerializeUnsized<S>,
{
fn serialize_with(field: &CowStr, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
let s: String = match &field.0 {
Cow::Owned(s) => s.clone(),
Cow::Borrowed(b) => b.to_string(),
};
<String as Serialize<S>>::serialize(&s, serializer)
}
}
impl<D> DeserializeWith<<String as Archive>::Archived, CowStr, D> for AsString
where
D: Fallible + ?Sized,
String: Deserialize<<String as Archive>::Archived, D>,
{
fn deserialize_with(
field: &<String as Archive>::Archived,
deserializer: &mut D,
) -> Result<CowStr, D::Error> {
let s: String =
<<String as Archive>::Archived as rkyv::Deserialize<String, D>>::deserialize(
field,
deserializer,
)?;
Ok(CowStr(Cow::Owned(s)))
}
}
}
#[cfg(feature = "r2r")]
#[macro_export]
macro_rules! impl_pointcloud2_for_r2r {
() => {
pub mod impl_r2r {
pub fn to_pointcloud2_msg(
msg: ::r2r::sensor_msgs::msg::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> ::r2r::sensor_msgs::msg::PointCloud2 {
::r2r::sensor_msgs::msg::PointCloud2 {
header: ::r2r::std_msgs::msg::Header {
stamp: ::r2r::builtin_interfaces::msg::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| ::r2r::sensor_msgs::msg::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
pub fn time_to_internal(
time: ::r2r::builtin_interfaces::msg::Time,
) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec,
nanosec: time.nanosec,
}
}
pub fn time_from_internal(
time: ::ros_pointcloud2::ros::TimeMsg,
) -> ::r2r::builtin_interfaces::msg::Time {
::r2r::builtin_interfaces::msg::Time {
sec: time.sec,
nanosec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "hiroz")]
#[macro_export]
macro_rules! impl_pointcloud2_for_hiroz {
() => {
pub mod impl_hiroz {
use ::zenoh_buffers::buffer::SplitBuffer;
pub fn to_pointcloud2_msg(
msg: ::hiroz_msgs::sensor_msgs::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data.contiguous().as_ref().to_vec(),
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> ::hiroz_msgs::sensor_msgs::PointCloud2 {
::hiroz_msgs::sensor_msgs::PointCloud2 {
header: ::hiroz_msgs::std_msgs::Header {
stamp: ::hiroz_msgs::builtin_interfaces::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| ::hiroz_msgs::sensor_msgs::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data.into(),
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
pub fn time_to_internal(
time: ::hiroz_msgs::builtin_interfaces::Time,
) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec,
nanosec: time.nanosec,
}
}
pub fn time_from_internal(
time: ::ros_pointcloud2::ros::TimeMsg,
) -> ::hiroz_msgs::builtin_interfaces::Time {
::hiroz_msgs::builtin_interfaces::Time {
sec: time.sec,
nanosec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "ros2_interfaces_jazzy_serde")]
#[macro_export]
macro_rules! impl_pointcloud2_for_ros2_interfaces_jazzy_serde {
() => {
pub mod impl_ros2_interfaces_jazzy_serde {
pub fn to_pointcloud2_msg(
msg: ::ros2_interfaces_jazzy_serde::sensor_msgs::msg::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> ::ros2_interfaces_jazzy_serde::sensor_msgs::msg::PointCloud2 {
::ros2_interfaces_jazzy_serde::sensor_msgs::msg::PointCloud2 {
header: ::ros2_interfaces_jazzy_serde::std_msgs::msg::Header {
stamp: ::ros2_interfaces_jazzy_serde::builtin_interfaces::msg::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(
|field| ::ros2_interfaces_jazzy_serde::sensor_msgs::msg::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
},
)
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
pub fn time_to_internal(
time: ::ros2_interfaces_jazzy_serde::builtin_interfaces::msg::Time,
) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec,
nanosec: time.nanosec,
}
}
pub fn time_from_internal(
time: ::ros_pointcloud2::ros::TimeMsg,
) -> ::ros2_interfaces_jazzy_serde::builtin_interfaces::msg::Time {
::ros2_interfaces_jazzy_serde::builtin_interfaces::msg::Time {
sec: time.sec,
nanosec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "ros2_interfaces_jazzy_rkyv")]
#[macro_export]
macro_rules! impl_pointcloud2_for_ros2_interfaces_jazzy_rkyv {
() => {
pub mod impl_ros2_interfaces_jazzy_rkyv {
pub fn to_pointcloud2_msg(
msg: ::ros2_interfaces_jazzy_rkyv::sensor_msgs::msg::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> ::ros2_interfaces_jazzy_rkyv::sensor_msgs::msg::PointCloud2 {
::ros2_interfaces_jazzy_rkyv::sensor_msgs::msg::PointCloud2 {
header: ::ros2_interfaces_jazzy_rkyv::std_msgs::msg::Header {
stamp: ::ros2_interfaces_jazzy_rkyv::builtin_interfaces::msg::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(
|field| ::ros2_interfaces_jazzy_rkyv::sensor_msgs::msg::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
},
)
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
pub fn time_to_internal(
time: ::ros2_interfaces_jazzy_rkyv::builtin_interfaces::msg::Time,
) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec,
nanosec: time.nanosec,
}
}
pub fn time_from_internal(
time: ::ros_pointcloud2::ros::TimeMsg,
) -> ::ros2_interfaces_jazzy_rkyv::builtin_interfaces::msg::Time {
::ros2_interfaces_jazzy_rkyv::builtin_interfaces::msg::Time {
sec: time.sec,
nanosec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "rosrust")]
#[macro_export]
macro_rules! impl_pointcloud2_for_rosrust {
() => {
pub mod impl_rosrust {
pub fn to_pointcloud2_msg(
msg: rosrust_msg::sensor_msgs::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: msg.header.seq,
stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> rosrust_msg::sensor_msgs::PointCloud2 {
rosrust_msg::sensor_msgs::PointCloud2 {
header: rosrust_msg::std_msgs::Header {
seq: msg.header.seq,
stamp: rosrust::Time {
sec: msg.header.stamp.sec as u32,
nsec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| rosrust_msg::sensor_msgs::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: if msg.endian == ::ros_pointcloud2::Endian::Big {
true
} else {
false
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: if msg.dense == ::ros_pointcloud2::Denseness::Dense {
true
} else {
false
},
}
}
pub fn time_to_internal(time: rosrust::Time) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec as i32,
nanosec: time.nsec,
}
}
pub fn time_from_internal(time: ::ros_pointcloud2::ros::TimeMsg) -> rosrust::Time {
rosrust::Time {
sec: time.sec as u32,
nsec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "rclrs")]
#[macro_export]
macro_rules! impl_pointcloud2_for_rclrs {
() => {
pub mod impl_rclrs {
pub fn to_pointcloud2_msg(
msg: sensor_msgs::msg::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: time_to_internal(msg.header.stamp),
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> sensor_msgs::msg::PointCloud2 {
sensor_msgs::msg::PointCloud2 {
header: std_msgs::msg::Header {
stamp: builtin_interfaces::msg::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| sensor_msgs::msg::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
pub fn time_to_internal(
time: builtin_interfaces::msg::Time,
) -> ::ros_pointcloud2::ros::TimeMsg {
::ros_pointcloud2::ros::TimeMsg {
sec: time.sec,
nanosec: time.nanosec,
}
}
pub fn time_from_internal(
time: ::ros_pointcloud2::ros::TimeMsg,
) -> builtin_interfaces::msg::Time {
builtin_interfaces::msg::Time {
sec: time.sec,
nanosec: time.nanosec,
}
}
}
};
}
#[cfg(feature = "roslibrust_ros1")]
#[macro_export]
macro_rules! impl_pointcloud2_for_roslibrust_ros1 {
($root:path) => {
pub mod impl_roslibrust_ros1 {
use $root as msg_root;
pub fn to_pointcloud2_msg(
msg: msg_root::sensor_msgs::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: msg.header.seq,
stamp: ::ros_pointcloud2::ros::TimeMsg {
sec: msg.header.stamp.secs as i32,
nanosec: msg.header.stamp.nsecs as u32,
},
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> msg_root::sensor_msgs::PointCloud2 {
msg_root::sensor_msgs::PointCloud2 {
header: msg_root::std_msgs::Header {
seq: msg.header.seq,
stamp: roslibrust::codegen::integral_types::Time {
secs: msg.header.stamp.sec,
nsecs: msg.header.stamp.nanosec as i32,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| msg_root::sensor_msgs::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
}
};
}
#[cfg(feature = "roslibrust_ros2")]
#[macro_export]
macro_rules! impl_pointcloud2_for_roslibrust_ros2 {
($root:path) => {
pub mod impl_roslibrust_ros2 {
use $root as msg_root;
pub fn to_pointcloud2_msg(
msg: msg_root::sensor_msgs::PointCloud2,
) -> ::ros_pointcloud2::PointCloud2Msg {
::ros_pointcloud2::PointCloud2Msg {
header: ::ros_pointcloud2::ros::HeaderMsg {
seq: 0, stamp: ::ros_pointcloud2::ros::TimeMsg {
sec: msg.header.stamp.sec as i32,
nanosec: msg.header.stamp.nanosec as u32,
},
frame_id: msg.header.frame_id,
},
dimensions: ::ros_pointcloud2::CloudDimensions {
width: msg.width,
height: msg.height,
},
fields: msg
.fields
.into_iter()
.map(|field| ::ros_pointcloud2::ros::PointFieldMsg {
name: field.name.into(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
endian: if msg.is_bigendian {
::ros_pointcloud2::Endian::Big
} else {
::ros_pointcloud2::Endian::Little
},
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
dense: if msg.is_dense {
::ros_pointcloud2::Denseness::Dense
} else {
::ros_pointcloud2::Denseness::Sparse
},
}
}
pub fn from_pointcloud2_msg(
msg: ::ros_pointcloud2::PointCloud2Msg,
) -> msg_root::sensor_msgs::PointCloud2 {
msg_root::sensor_msgs::PointCloud2 {
header: msg_root::std_msgs::Header {
stamp: msg_root::builtin_interfaces::Time {
sec: msg.header.stamp.sec,
nanosec: msg.header.stamp.nanosec as u32,
},
frame_id: msg.header.frame_id,
},
height: msg.dimensions.height,
width: msg.dimensions.width,
fields: msg
.fields
.into_iter()
.map(|field| msg_root::sensor_msgs::PointField {
name: field.name.into_owned(),
offset: field.offset,
datatype: field.datatype,
count: field.count,
})
.collect(),
is_bigendian: matches!(msg.endian, ::ros_pointcloud2::Endian::Big),
point_step: msg.point_step,
row_step: msg.row_step,
data: msg.data,
is_dense: matches!(msg.dense, ::ros_pointcloud2::Denseness::Dense),
}
}
}
};
}