Skip to content

Commit be54c04

Browse files
README.md completed for rustecal-types-string (#30)
1 parent ecee266 commit be54c04

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

rustecal-types-string/README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# rustecal-types-string
2+
3+
`rustecal-types-string` provides a simple wrapper for UTF-8 string messages (`Arc<str>`) to use with the typed eCAL Pub/Sub API.
4+
5+
## Features
6+
7+
- **StringMessage**: wrap and transport UTF-8 string payloads
8+
- Implements `PublisherMessage` and `SubscriberMessage` for seamless integration
9+
- Zero-copy where possible via `Arc<str>`
10+
- No extra dependencies beyond `rustecal-core` and `rustecal-pubsub`
11+
12+
## Installation
13+
14+
Add to your **workspace** `Cargo.toml`:
15+
16+
```toml
17+
[dependencies]
18+
rustecal-types-string = "0.1"
19+
```
20+
21+
## Usage
22+
23+
### Publisher Example
24+
25+
```rust
26+
use std::sync::Arc;
27+
use rustecal::{Ecal, EcalComponents, TypedPublisher};
28+
use rustecal_types_string::StringMessage;
29+
30+
fn main() -> Result<(), Box<dyn std::error::Error>> {
31+
Ecal::initialize(Some("string publisher"), EcalComponents::DEFAULT)?;
32+
33+
let publisher = TypedPublisher::<StringMessage>::new("hello")?;
34+
35+
while Ecal::ok() {
36+
let message = StringMessage { data: Arc::from("Hello from Rust") };
37+
publisher.send(&message);
38+
39+
std::thread::sleep(std::time::Duration::from_millis(500));
40+
}
41+
42+
Ecal::finalize();
43+
Ok(())
44+
}
45+
```
46+
47+
### Subscriber Example
48+
49+
```rust
50+
use rustecal::{Ecal, EcalComponents, TypedSubscriber};
51+
use rustecal_types_string::StringMessage;
52+
53+
fn main() -> Result<(), Box<dyn std::error::Error>> {
54+
Ecal::initialize(Some("string subscriber"), EcalComponents::DEFAULT)?;
55+
56+
let mut subscriber = TypedSubscriber::<StringMessage>::new("hello")?;
57+
subscriber.set_callback(|message| {
58+
println!("Received: {}", message.payload.data)
59+
});
60+
61+
while Ecal::ok() {
62+
std::thread::sleep(std::time::Duration::from_millis(500));
63+
}
64+
65+
Ecal::finalize();
66+
Ok(())
67+
}
68+
```
69+
70+
## Traits Reference
71+
72+
- **`PublisherMessage`**
73+
74+
- `fn datatype() -> DataTypeInfo`
75+
- `fn to_bytes(&self) -> Arc<[u8]>`
76+
77+
- **`SubscriberMessage`**
78+
79+
- `fn datatype() -> DataTypeInfo`
80+
- `fn from_bytes(bytes: Arc<[u8]>, _data_type_info: &DataTypeInfo) -> Option<Self>`
81+
82+
## See Also
83+
84+
- `rustecal-types-bytes` for raw binary data messages
85+
- `rustecal-types-protobuf` for Protobuf-based messages
86+
- `rustecal-types-serde` for JSON/CBOR/MessagePack via Serde
87+
- Examples in the `rustecal-samples/pubsub` directory

0 commit comments

Comments
 (0)