diff --git a/docs/src/api/message_types.md b/docs/src/api/message_types.md index 5543f15..61c48d7 100644 --- a/docs/src/api/message_types.md +++ b/docs/src/api/message_types.md @@ -15,8 +15,8 @@ Used for binary `Vec` payloads. Supports publishing/receiving of Protobuf types that implement `Message` and `Default`. ```rust -use rustecal::types::ProtobufMessage; +use rustecal_types_protobuf::ProtobufMessage; use my_proto::MyProto; -let pub = Publisher::>::builder("proto_topic").create()?; +let publisher = Publisher::>::builder("proto_topic").create()?; ``` diff --git a/docs/src/api/publisher.md b/docs/src/api/publisher.md index 5c0539f..09d6026 100644 --- a/docs/src/api/publisher.md +++ b/docs/src/api/publisher.md @@ -6,8 +6,8 @@ The `Publisher` allows you to publish messages of type `T` on a topic. ```rust use rustecal::pubsub::Publisher; -use rustecal::types::StringMessage; +use rustecal_types::StringMessage; -let pub = Publisher::::builder("my_topic").create()?; -pub.send("Rust rocks!")?; +let publisher = Publisher::::builder("my_topic").create()?; +publisher.send("Rust rocks!")?; ``` diff --git a/docs/src/api/service_client.md b/docs/src/api/service_client.md index bce8de5..6319fc3 100644 --- a/docs/src/api/service_client.md +++ b/docs/src/api/service_client.md @@ -48,4 +48,4 @@ match response { ## Runtime Compatibility -This API matches the usage and behavior of `mirror_client.cpp` in the eCAL C++ samples. \ No newline at end of file +This API is fully compatible with the C++ `mirror_client.cpp` and C `mirror_client_c.c` examples. \ No newline at end of file diff --git a/docs/src/api/service_server.md b/docs/src/api/service_server.md index a15c6b5..5733e40 100644 --- a/docs/src/api/service_server.md +++ b/docs/src/api/service_server.md @@ -47,4 +47,4 @@ Response : desserts ## Runtime Compatibility -This API is fully compatible with the C++ `mirror_server.cpp` and C `mirror_server.c` examples. \ No newline at end of file +This API is fully compatible with the C++ `mirror_server.cpp` and C `mirror_server_c.c` examples. \ No newline at end of file diff --git a/docs/src/api/subscriber.md b/docs/src/api/subscriber.md index 0a2bc2f..02d08c7 100644 --- a/docs/src/api/subscriber.md +++ b/docs/src/api/subscriber.md @@ -6,10 +6,10 @@ The `Subscriber` enables you to subscribe to messages of type `T` on a topic. ```rust use rustecal::pubsub::Subscriber; -use rustecal::types::StringMessage; +use rustecal_types::StringMessage; -let sub = Subscriber::::builder("my_topic").create()?; -sub.set_callback(|msg| { +let subscriber = Subscriber::::builder("my_topic").create()?; +subscriber.set_callback(|msg| { println!("Received: {}", msg.data()); }); ``` diff --git a/docs/src/examples/binary.md b/docs/src/examples/binary.md index d173c79..93fbba9 100644 --- a/docs/src/examples/binary.md +++ b/docs/src/examples/binary.md @@ -3,6 +3,7 @@ ## Publisher ```rust +use std::sync::Arc; use rustecal::{Ecal, EcalComponents, TypedPublisher}; use rustecal_types_bytes::BytesMessage; @@ -14,9 +15,9 @@ fn main() -> Result<(), Box> { let mut counter = 0u8; while Ecal::ok() { let buf = vec![counter; 1024]; + counter = counter.wrapping_add(1); publisher.send(&BytesMessage(Arc::from(buf))); - counter = counter.wrapping_add(1); std::thread::sleep(std::time::Duration::from_millis(500)); } @@ -36,7 +37,7 @@ fn main() -> Result<(), Box> { let mut subscriber = TypedSubscriber::::new("blob")?; subscriber.set_callback(|msg| { - println!("Received blob of {} bytes", msg.msg.0.len()); + println!("Received blob of {} bytes", msg.payload.data.len()); }); while Ecal::ok() { diff --git a/docs/src/examples/protobuf.md b/docs/src/examples/protobuf.md index 8962f0e..040b15b 100644 --- a/docs/src/examples/protobuf.md +++ b/docs/src/examples/protobuf.md @@ -48,7 +48,9 @@ fn main() -> Result<(), Box> { Ecal::initialize(Some("protobuf subscriber"), EcalComponents::DEFAULT)?; let mut subscriber = TypedSubscriber::>::new("person")?; - subscriber.set_callback(|msg| println!("Received person: {}", msg.msg.0.name)); + subscriber.set_callback(|msg| { + println!("Received person: {}", msg.payload.data.name) + }); while Ecal::ok() { std::thread::sleep(std::time::Duration::from_millis(500)); diff --git a/docs/src/examples/service_client.md b/docs/src/examples/service_client.md index b24a5eb..7ff11c0 100644 --- a/docs/src/examples/service_client.md +++ b/docs/src/examples/service_client.md @@ -9,7 +9,6 @@ use rustecal::{Ecal, EcalComponents, ServiceClient, ServiceRequest}; fn main() -> Result<(), Box> { Ecal::initialize(Some("mirror_client"), EcalComponents::DEFAULT)?; - println!("mirror_client initialized. Sending requests…"); let client = ServiceClient::new("mirror_service")?; diff --git a/docs/src/examples/string.md b/docs/src/examples/string.md index 843b178..f6496e0 100644 --- a/docs/src/examples/string.md +++ b/docs/src/examples/string.md @@ -33,7 +33,9 @@ fn main() -> Result<(), Box> { Ecal::initialize(Some("string subscriber"), EcalComponents::DEFAULT)?; let mut subscriber = TypedSubscriber::::new("hello")?; - subscriber.set_callback(|msg| println!("Received: {}", msg.msg.0)); + subscriber.set_callback(|msg| { + println!("Received: {}", msg.payload.data) + }); while Ecal::ok() { std::thread::sleep(std::time::Duration::from_millis(500)); diff --git a/docs/src/types/message_types.md b/docs/src/types/message_types.md index 13c2290..9417512 100644 --- a/docs/src/types/message_types.md +++ b/docs/src/types/message_types.md @@ -2,6 +2,6 @@ - `BytesMessage` – Arbitrary binary data - `StringMessage` – UTF-8 encoded strings -- `ProtobufMessage` – Protobuf messages (via `prost`) +- `ProtobufMessage` – Protobuf messages Each type is provided via a dedicated crate to avoid pulling unnecessary dependencies. diff --git a/rustecal-pubsub/src/typed_subscriber.rs b/rustecal-pubsub/src/typed_subscriber.rs index ff475f7..83f7dd2 100644 --- a/rustecal-pubsub/src/typed_subscriber.rs +++ b/rustecal-pubsub/src/typed_subscriber.rs @@ -23,7 +23,7 @@ pub trait SubscriberMessage: Sized { /// This includes the deserialized message and eCAL metadata such as timestamp and topic information. pub struct Received { /// The decoded message of type `T`. - pub msg: T, + pub payload: T, /// The name of the topic this message was received on. pub topic_name: String, @@ -201,7 +201,7 @@ extern "C" fn trampoline( let type_name = CStr::from_ptr((*data_type_info).name).to_string_lossy().into_owned(); let metadata = Received { - msg: decoded, + payload: decoded, topic_name, encoding, type_name, diff --git a/rustecal-samples/pubsub/blob_receive/src/main.rs b/rustecal-samples/pubsub/blob_receive/src/main.rs index 7c48c7b..36a2319 100644 --- a/rustecal-samples/pubsub/blob_receive/src/main.rs +++ b/rustecal-samples/pubsub/blob_receive/src/main.rs @@ -10,7 +10,7 @@ fn main() { .expect("Failed to create subscriber"); subscriber.set_callback(|msg: Received| { - let buffer = &msg.msg.0; + let buffer = &msg.payload.data; if buffer.is_empty() { return; } diff --git a/rustecal-samples/pubsub/blob_send/src/main.rs b/rustecal-samples/pubsub/blob_send/src/main.rs index 9976592..a6b8630 100644 --- a/rustecal-samples/pubsub/blob_send/src/main.rs +++ b/rustecal-samples/pubsub/blob_send/src/main.rs @@ -16,7 +16,7 @@ fn main() { let buffer = vec![counter; 1024]; counter = counter.wrapping_add(1); - let wrapped = BytesMessage(Arc::from(buffer)); + let wrapped = BytesMessage { data: Arc::from(buffer) }; publisher.send(&wrapped); println!("Sent buffer filled with {}", counter); diff --git a/rustecal-samples/pubsub/hello_receive/src/main.rs b/rustecal-samples/pubsub/hello_receive/src/main.rs index 3d8195c..fb8ac84 100644 --- a/rustecal-samples/pubsub/hello_receive/src/main.rs +++ b/rustecal-samples/pubsub/hello_receive/src/main.rs @@ -21,7 +21,7 @@ fn main() { println!("------------------------------------------"); println!(" CONTENT "); println!("------------------------------------------"); - println!("message : {}", msg.msg.0); + println!("message : {}", msg.payload.data); println!("------------------------------------------\n"); }); diff --git a/rustecal-samples/pubsub/hello_send/src/main.rs b/rustecal-samples/pubsub/hello_send/src/main.rs index 520ce3d..1bff29a 100644 --- a/rustecal-samples/pubsub/hello_send/src/main.rs +++ b/rustecal-samples/pubsub/hello_send/src/main.rs @@ -14,10 +14,10 @@ fn main() { cnt += 1; let msg = format!("HELLO WORLD FROM RUST ({})", cnt); - let wrapped = StringMessage(Arc::from(msg)); + let wrapped = StringMessage{ data: Arc::::from(msg) }; publisher.send(&wrapped); - println!("Sent: {}", wrapped.0); + println!("Sent: {}", wrapped.data); std::thread::sleep(std::time::Duration::from_millis(500)); } diff --git a/rustecal-samples/pubsub/person_receive/src/main.rs b/rustecal-samples/pubsub/person_receive/src/main.rs index 105b625..84b46d0 100644 --- a/rustecal-samples/pubsub/person_receive/src/main.rs +++ b/rustecal-samples/pubsub/person_receive/src/main.rs @@ -17,7 +17,7 @@ fn main() { .expect("Failed to create subscriber"); subscriber.set_callback(|msg: Received>| { - let person = msg.msg.0; + let person = msg.payload.data; println!("------------------------------------------"); println!(" HEAD "); diff --git a/rustecal-samples/pubsub/person_send/src/main.rs b/rustecal-samples/pubsub/person_send/src/main.rs index 715880e..9ce11b8 100644 --- a/rustecal-samples/pubsub/person_send/src/main.rs +++ b/rustecal-samples/pubsub/person_send/src/main.rs @@ -43,7 +43,7 @@ fn main() { println!(); // Wrap the person struct in ProtobufMessage - let wrapped = ProtobufMessage(Arc::from(person)); + let wrapped = ProtobufMessage { data: Arc::from(person) }; publisher.send(&wrapped); std::thread::sleep(std::time::Duration::from_millis(500)); diff --git a/rustecal-types-bytes/src/lib.rs b/rustecal-types-bytes/src/lib.rs index b8b8c53..1f8e61f 100644 --- a/rustecal-types-bytes/src/lib.rs +++ b/rustecal-types-bytes/src/lib.rs @@ -18,7 +18,9 @@ use rustecal_pubsub::typed_subscriber::SubscriberMessage; /// /// This type allows sending and receiving raw binary payloads through the /// `TypedPublisher` and `TypedSubscriber` APIs. -pub struct BytesMessage(pub Arc<[u8]>); +pub struct BytesMessage { + pub data: Arc<[u8]>, +} impl SubscriberMessage for BytesMessage { /// Returns metadata describing the message encoding and type. @@ -34,7 +36,7 @@ impl SubscriberMessage for BytesMessage { /// Creates a `BytesMessage` from a raw byte slice. fn from_bytes(bytes: Arc<[u8]>) -> Option { - Some(BytesMessage(Arc::from(bytes))) + Some(BytesMessage { data: Arc::from(bytes) }) } } @@ -46,6 +48,6 @@ impl PublisherMessage for BytesMessage { /// Returns the internal binary data as an Arc<[u8]> for zero-copy transmission. fn to_bytes(&self) -> Arc<[u8]> { - self.0.clone() + self.data.clone() } } diff --git a/rustecal-types-protobuf/src/lib.rs b/rustecal-types-protobuf/src/lib.rs index a4bcf09..0bdcc92 100644 --- a/rustecal-types-protobuf/src/lib.rs +++ b/rustecal-types-protobuf/src/lib.rs @@ -30,7 +30,9 @@ pub trait IsProtobufType {} /// This type allows sending and receiving protobuf messages through the /// `TypedPublisher` and `TypedSubscriber` APIs. #[derive(Debug, Clone)] -pub struct ProtobufMessage(pub Arc); +pub struct ProtobufMessage { + pub data: Arc, +} impl SubscriberMessage for ProtobufMessage where @@ -56,7 +58,9 @@ where /// - `Some(ProtobufMessage)` on success /// - `None` if decoding fails fn from_bytes(bytes: Arc<[u8]>) -> Option { - T::decode(bytes.as_ref()).ok().map(|msg| ProtobufMessage(Arc::new(msg))) + T::decode(bytes.as_ref()).ok().map(|msg| ProtobufMessage { + data: Arc::new(msg), + }) } } @@ -74,8 +78,8 @@ where /// # Panics /// Will panic if `prost::Message::encode` fails (should never panic for valid messages). fn to_bytes(&self) -> Arc<[u8]> { - let mut buf = Vec::with_capacity(self.0.encoded_len()); - self.0 + let mut buf = Vec::with_capacity(self.data.encoded_len()); + self.data .encode(&mut buf) .expect("Failed to encode protobuf message"); Arc::from(buf) diff --git a/rustecal-types-string/src/lib.rs b/rustecal-types-string/src/lib.rs index 6038f74..87330bf 100644 --- a/rustecal-types-string/src/lib.rs +++ b/rustecal-types-string/src/lib.rs @@ -19,7 +19,9 @@ use rustecal_pubsub::typed_subscriber::SubscriberMessage; /// /// This type allows sending and receiving strings through the /// `TypedPublisher` and `TypedSubscriber` APIs. -pub struct StringMessage(pub Arc); +pub struct StringMessage { + pub data: Arc, +} impl SubscriberMessage for StringMessage { /// Returns metadata describing this message type (`utf-8` encoded string). @@ -35,7 +37,7 @@ impl SubscriberMessage for StringMessage { fn from_bytes(bytes: Arc<[u8]>) -> Option { str::from_utf8(bytes.as_ref()) .ok() - .map(|s| StringMessage(Arc::::from(s))) + .map(|s| StringMessage{ data: Arc::::from(s) }) } } @@ -47,6 +49,6 @@ impl PublisherMessage for StringMessage { /// Serializes the string into a byte buffer. fn to_bytes(&self) -> Arc<[u8]> { - Arc::from(self.0.as_bytes()) + Arc::from(self.data.as_bytes()) } }