Can I use cpp programmer as a publisher and rust program as a subscriber? #480
-
I try to run the example of cpp publisher, and wanna to subscriber it on another rust project, with the same service name, but If I open the cpp service, I can open the rust service, the wrong message is under Error: PublishSubscribeOpenError(IncompatibleTypes) and I just run
but all the type in the example is same #[derive(Debug)]
#[repr(C)]
pub struct TransmissionData {
pub x: i32,
pub y: i32,
pub funky: f64,
} so how can I resolve this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Apart from the memory layout, iceoryx2 also requires the type name to be the same. The Rust side uses iceoryx2/iceoryx2/src/service/static_config/message_type_details.rs Lines 44 to 56 in a657228 However, the C++ side uses iceoryx2/iceoryx2-ffi/cxx/include/iox2/message_type_details.hpp Lines 21 to 42 in a657228 Unfortunately, looks like there is currently no way in iceoryx2 to customize the type name. |
Beta Was this translation helpful? Give feedback.
-
With the introduction of the C++ and C language binding, we wanted to make it work first reliable in the language itself and then focus on cross language use-cases. So at the moment you can use iceoryx2 only for Rust 2 Rust or C/C++ to C/C++ communication. But by utilizing the internal Rust API you can establish a communication between C++ and Rust - it is internal and only a temporary solution! // Rust part
struct TransmissionData {
//...
}
let mut type_details = TypeDetail::__internal_new<TransmissionData>(TypeVariant::FixedSize);
type_details.type_name = "TransmissionData"; // set here the type name to the C++ compiler output of `typeid(TransmissionData).name()`
let service = node
.service_builder(&"My/Funk/ServiceName".try_into()?)
.publish_subscribe::<TransmissionData>()
.__internal_set_payload_type_details(type_details)
.open_or_create()?; // C++ part
struct TransmissionData {
// ...
};
// this prints the value you have to use in the rust part type_details.type_name
std::cout << typeid(TransmissionData).name() << std::endl;
// The C++ code can stay as it is since the Rust side has adjusted the type name to the C++ variant The So it will be looking somehow like this: #[derive(ShmSend)]
#[type_details(TypeName = "MyFunkyType")]
struct MyFunkyType {
a: u64,
b: u64
} struct MyFunkyType {
constexpr char * TYPE_NAME = "MyFunkyType";
uint64_t a;
uint64_t b;
}; Currently, we are preparing some conference talks for next week ROScon and OCX where we present iceoryx2 and right after that we will focus on this feature. So in the beginning of November you should be able to have Rust 2 C++/C communication with the official iceoryx2 API, without using the internal API. |
Beta Was this translation helpful? Give feedback.
@XiaoPengYouCode @Chaoses-Ib
With the introduction of the C++ and C language binding, we wanted to make it work first reliable in the language itself and then focus on cross language use-cases. So at the moment you can use iceoryx2 only for Rust 2 Rust or C/C++ to C/C++ communication.
But by utilizing the internal Rust API you can establish a communication between C++ and Rust - it is internal and only a temporary solution!