File tree Expand file tree Collapse file tree 7 files changed +78
-4
lines changed
Expand file tree Collapse file tree 7 files changed +78
-4
lines changed Original file line number Diff line number Diff line change 99 - [ Binary] ( examples/binary.md )
1010 - [ String] ( examples/string.md )
1111 - [ Protobuf] ( examples/protobuf.md )
12+ - [ Server] ( examples/service_server.md )
13+ - [ Client] ( examples/service_client.md )
1214- [ API Documentation] ( api/index.md )
1315 - [ Ecal Lifecycle] ( api/ecal.md )
1416 - [ Typed Publisher] ( api/publisher.md )
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ fn main() {
1010 Ecal :: initialize (Some (" blob publisher" ), EcalComponents :: DEFAULT ). unwrap ();
1111 let pub_ = TypedPublisher :: <BytesMessage >:: new (" blob" ). unwrap ();
1212 let mut counter = 0u8 ;
13- loop {
13+ while Ecal :: ok () {
1414 let buf = vec! [counter ; 1024 ];
1515 pub_ . send (& BytesMessage (buf ));
1616 counter = counter . wrapping_add (1 );
Original file line number Diff line number Diff line change 11# Examples
22
3- Code samples for using rustecal.
3+ Code samples for using rustecal.
4+
5+ ## Publish / Subscribe
6+
7+ - [ String Messages] ( string.md )
8+ - [ Binary Messages] ( binary.md )
9+ - [ Protobuf Messages] ( protobuf.md )
10+
11+ ## Service Client / Server
12+
13+ - [ Mirror Server] ( service_server.md )
14+ - [ Mirror Client] ( service_client.md )
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ impl IsProtobufType for Person {}
1313fn main () {
1414 Ecal :: initialize (Some (" protobuf publisher" ), EcalComponents :: DEFAULT ). unwrap ();
1515 let pub_ = TypedPublisher :: <ProtobufMessage <Person >>:: new (" person" ). unwrap ();
16- loop {
16+ while Ecal :: ok () {
1717 let person = Person { id : 1 , name : " Alice" . into (), .. Default :: default () };
1818 pub_ . send (& ProtobufMessage (person ));
1919 std :: thread :: sleep (std :: time :: Duration :: from_millis (500 ));
Original file line number Diff line number Diff line change 1+ # Service Client Example
2+
3+ This example demonstrates how to call a ** Mirror Service** using ` rustecal ` .
4+
5+ ## Example Code
6+
7+ ``` rust
8+ use rustecal :: {Ecal , EcalComponents };
9+ use rustecal_service :: ServiceClient ;
10+
11+ fn main () {
12+ Ecal :: initialize (Some (" mirror_client" ), EcalComponents :: DEFAULT ). unwrap ();
13+
14+ let client = ServiceClient :: new (" mirror_service" ). unwrap ();
15+
16+ let request_data = b " Hello, Service!" ;
17+ let timeout = std :: time :: Duration :: from_millis (500 );
18+
19+ while Ecal :: ok () {
20+ if let Some (response ) = client . call (request_data , timeout ) {
21+ println! (" Received response: {:?}" , String :: from_utf8_lossy (& response ));
22+ } else {
23+ println! (" Service call timed out." );
24+ }
25+ std :: thread :: sleep (std :: time :: Duration :: from_millis (500 ));
26+ }
27+
28+ Ecal :: finalize ();
29+ }
30+ ```
Original file line number Diff line number Diff line change 1+ # Service Server Example
2+
3+ This example shows how to implement a basic ** Mirror Service Server** using ` rustecal ` .
4+
5+ The server receives a request, logs it, and sends it back as a response.
6+
7+ ## Example Code
8+
9+ ``` rust
10+ use rustecal :: {Ecal , EcalComponents };
11+ use rustecal_service :: {ServiceServer , ReceivedRequest };
12+
13+ fn main () {
14+ Ecal :: initialize (Some (" mirror_server" ), EcalComponents :: DEFAULT ). unwrap ();
15+
16+ let _server = ServiceServer :: new (" mirror_service" , move | req : ReceivedRequest | {
17+ let request_str = String :: from_utf8_lossy (req . request ());
18+ println! (" Received request: {}" , request_str );
19+
20+ // Respond with the same data
21+ req . respond (req . request ());
22+ }). expect (" Failed to create service server" );
23+
24+ // Keep the server running
25+ while Ecal :: ok () {
26+ std :: thread :: sleep (std :: time :: Duration :: from_millis (500 ));
27+ }
28+
29+ Ecal :: finalize ();
30+ }
31+ ```
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use rustecal_types_string::StringMessage;
99fn main () {
1010 Ecal :: initialize (Some (" string publisher" ), EcalComponents :: DEFAULT ). unwrap ();
1111 let publisher = TypedPublisher :: <StringMessage >:: new (" hello" ). unwrap ();
12- loop {
12+ while Ecal :: ok () {
1313 let msg = StringMessage (format! (" Hello from Rust" ));
1414 publisher . send (& msg );
1515 std :: thread :: sleep (std :: time :: Duration :: from_millis (500 ));
You can’t perform that action at this time.
0 commit comments