You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-8Lines changed: 5 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -51,7 +51,7 @@ Methods on services are defined using callbacks. While this is fine for simple s
51
51
It offers a higher-level abstraction over the underlying protocol, making it easier to use and understand by providing a cleaner more structured way to define services by leveraging Rust's powerful macro system, something similar to [rocket.rs](https://rocket.rs/) but for SOME/IP.
52
52
53
53
# Example
54
-
Here's a simple example of defining a service and method using smip:
54
+
Let's look at a simple "Hello World" example using smip.
55
55
56
56
```rust
57
57
usesmip::{Runtime, RuntimeConfig, Service};
@@ -63,18 +63,13 @@ struct MyService {
63
63
64
64
#[smip::methods_impl]
65
65
implMyService {
66
-
// Method that adds whatever value it receives to x
67
-
// Expects u32 in request
68
-
// Returns u32 in response
66
+
69
67
#[smip_method(id = 1)]
70
68
fnadd(&mutself, value:u32) ->u32 {
71
69
self.x +=value;
72
70
self.x
73
71
}
74
-
75
-
// Method that sends a string
76
-
// Expects nothing in request
77
-
// Returns String in response
72
+
78
73
#[smip_method(id = 2)]
79
74
fnhello(&self) ->String {
80
75
"Hello World!".to_string()
@@ -98,6 +93,8 @@ A service is represented by a struct, `MyService` in this case, with a `service`
98
93
SOME/IP methods are just rust methods with a special `smip_method` attribute to indicate its id. Whatever you pass as an argument to your method is parsed automatically from the payload, and whatever you return from it serialized into a response and sent back.
99
94
All of these need to be in a special impl block marked with a `methods_impl` attribute for the framework to recognize them.
100
95
96
+
There are two methods
97
+
101
98
A `Runtime` needs to be created using a `RuntimeConfig` which which take care of creating and running all of your services.
102
99
103
100
After adding all your services to the `Runtime`, call `runtime.run()` to start all the services.
0 commit comments