Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/api/message_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Used for binary `Vec<u8>` 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::<ProtobufMessage<MyProto>>::builder("proto_topic").create()?;
let publisher = Publisher::<ProtobufMessage<MyProto>>::builder("proto_topic").create()?;
```
6 changes: 3 additions & 3 deletions docs/src/api/publisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The `Publisher<T>` 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::<StringMessage>::builder("my_topic").create()?;
pub.send("Rust rocks!")?;
let publisher = Publisher::<StringMessage>::builder("my_topic").create()?;
publisher.send("Rust rocks!")?;
```
2 changes: 1 addition & 1 deletion docs/src/api/service_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ match response {

## Runtime Compatibility

This API matches the usage and behavior of `mirror_client.cpp` in the eCAL C++ samples.
This API is fully compatible with the C++ `mirror_client.cpp` and C `mirror_client_c.c` examples.
2 changes: 1 addition & 1 deletion docs/src/api/service_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
This API is fully compatible with the C++ `mirror_server.cpp` and C `mirror_server_c.c` examples.
6 changes: 3 additions & 3 deletions docs/src/api/subscriber.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ The `Subscriber<T>` 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::<StringMessage>::builder("my_topic").create()?;
sub.set_callback(|msg| {
let subscriber = Subscriber::<StringMessage>::builder("my_topic").create()?;
subscriber.set_callback(|msg| {
println!("Received: {}", msg.data());
});
```
5 changes: 3 additions & 2 deletions docs/src/examples/binary.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Publisher

```rust
use std::sync::Arc;
use rustecal::{Ecal, EcalComponents, TypedPublisher};
use rustecal_types_bytes::BytesMessage;

Expand All @@ -14,9 +15,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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));
}

Expand All @@ -36,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let mut subscriber = TypedSubscriber::<BytesMessage>::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() {
Expand Down
4 changes: 3 additions & 1 deletion docs/src/examples/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("protobuf subscriber"), EcalComponents::DEFAULT)?;

let mut subscriber = TypedSubscriber::<ProtobufMessage<Person>>::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));
Expand Down
1 change: 0 additions & 1 deletion docs/src/examples/service_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustecal::{Ecal, EcalComponents, ServiceClient, ServiceRequest};

fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("mirror_client"), EcalComponents::DEFAULT)?;
println!("mirror_client initialized. Sending requests…");

let client = ServiceClient::new("mirror_service")?;

Expand Down
4 changes: 3 additions & 1 deletion docs/src/examples/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
Ecal::initialize(Some("string subscriber"), EcalComponents::DEFAULT)?;

let mut subscriber = TypedSubscriber::<StringMessage>::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));
Expand Down
2 changes: 1 addition & 1 deletion docs/src/types/message_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

- `BytesMessage` – Arbitrary binary data
- `StringMessage` – UTF-8 encoded strings
- `ProtobufMessage<T>` – Protobuf messages (via `prost`)
- `ProtobufMessage<T>` – Protobuf messages

Each type is provided via a dedicated crate to avoid pulling unnecessary dependencies.
4 changes: 2 additions & 2 deletions rustecal-pubsub/src/typed_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
/// 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,
Expand Down Expand Up @@ -201,7 +201,7 @@ extern "C" fn trampoline<T: SubscriberMessage>(
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,
Expand Down
2 changes: 1 addition & 1 deletion rustecal-samples/pubsub/blob_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
.expect("Failed to create subscriber");

subscriber.set_callback(|msg: Received<BytesMessage>| {
let buffer = &msg.msg.0;
let buffer = &msg.payload.data;
if buffer.is_empty() {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion rustecal-samples/pubsub/blob_send/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion rustecal-samples/pubsub/hello_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
println!("------------------------------------------");
println!(" CONTENT ");
println!("------------------------------------------");
println!("message : {}", msg.msg.0);
println!("message : {}", msg.payload.data);
println!("------------------------------------------\n");
});

Expand Down
4 changes: 2 additions & 2 deletions rustecal-samples/pubsub/hello_send/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<str>::from(msg) };
publisher.send(&wrapped);

println!("Sent: {}", wrapped.0);
println!("Sent: {}", wrapped.data);

std::thread::sleep(std::time::Duration::from_millis(500));
}
Expand Down
2 changes: 1 addition & 1 deletion rustecal-samples/pubsub/person_receive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
.expect("Failed to create subscriber");

subscriber.set_callback(|msg: Received<ProtobufMessage<Person>>| {
let person = msg.msg.0;
let person = msg.payload.data;

println!("------------------------------------------");
println!(" HEAD ");
Expand Down
2 changes: 1 addition & 1 deletion rustecal-samples/pubsub/person_send/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 5 additions & 3 deletions rustecal-types-bytes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -34,7 +36,7 @@ impl SubscriberMessage for BytesMessage {

/// Creates a `BytesMessage` from a raw byte slice.
fn from_bytes(bytes: Arc<[u8]>) -> Option<Self> {
Some(BytesMessage(Arc::from(bytes)))
Some(BytesMessage { data: Arc::from(bytes) })
}
}

Expand All @@ -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()
}
}
12 changes: 8 additions & 4 deletions rustecal-types-protobuf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(pub Arc<T>);
pub struct ProtobufMessage<T> {
pub data: Arc<T>,
}

impl<T> SubscriberMessage for ProtobufMessage<T>
where
Expand All @@ -56,7 +58,9 @@ where
/// - `Some(ProtobufMessage<T>)` on success
/// - `None` if decoding fails
fn from_bytes(bytes: Arc<[u8]>) -> Option<Self> {
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),
})
}
}

Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions rustecal-types-string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>);
pub struct StringMessage {
pub data: Arc<str>,
}

impl SubscriberMessage for StringMessage {
/// Returns metadata describing this message type (`utf-8` encoded string).
Expand All @@ -35,7 +37,7 @@ impl SubscriberMessage for StringMessage {
fn from_bytes(bytes: Arc<[u8]>) -> Option<Self> {
str::from_utf8(bytes.as_ref())
.ok()
.map(|s| StringMessage(Arc::<str>::from(s)))
.map(|s| StringMessage{ data: Arc::<str>::from(s) })
}
}

Expand All @@ -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())
}
}