Skip to main content

MethodId

Struct MethodId 

Source
pub struct MethodId(pub u16);
Expand description

Method ID - identifies a method within a service. Bit 15 indicates if this is an event (1) or method (0).

Tuple Fields§

§0: u16

Implementations§

Source§

impl MethodId

Source

pub fn is_event(&self) -> bool

Check if this method ID represents an event (bit 15 set).

Examples found in repository?
examples/message_basics.rs (line 61)
13fn main() {
14    println!("=== SOME/IP Message Basics ===\n");
15
16    // Example 1: Create a request message using the builder
17    println!("--- Example 1: Building Messages ---");
18    let request = SomeIpMessage::request(ServiceId(0x1234), MethodId(0x0001))
19        .client_id(ClientId(0x0100))
20        .session_id(SessionId(0x0001))
21        .interface_version(2)
22        .payload(b"Hello, World!".as_slice())
23        .build();
24
25    println!("Request message:");
26    print_message(&request);
27
28    // Example 2: Create a response from the request
29    println!("\n--- Example 2: Creating Responses ---");
30    let response = request
31        .create_response()
32        .payload(b"Response data".as_slice())
33        .build();
34
35    println!("Response message:");
36    print_message(&response);
37
38    // Example 3: Create an error response
39    println!("\n--- Example 3: Error Response ---");
40    let error = request
41        .create_error_response(ReturnCode::UnknownMethod)
42        .build();
43
44    println!("Error response:");
45    print_message(&error);
46
47    // Example 4: Serialize and deserialize
48    println!("\n--- Example 4: Serialization ---");
49    let bytes = request.to_bytes();
50    println!("Serialized to {} bytes", bytes.len());
51    println!("Header bytes: {:02X?}", &bytes[..HEADER_SIZE]);
52    println!("Payload bytes: {:02X?}", &bytes[HEADER_SIZE..]);
53
54    let parsed = SomeIpMessage::from_bytes(&bytes).expect("Failed to parse");
55    println!("\nParsed message matches original: {}", parsed == request);
56
57    // Example 5: Working with headers directly
58    println!("\n--- Example 5: Header Details ---");
59    let header = SomeIpHeader::new(ServiceId(0xFFFF), MethodId(0x8001));
60    println!("Service ID: {}", header.service_id);
61    println!("Method ID: {} (is_event: {})", header.method_id, header.method_id.is_event());
62    println!("Message ID: 0x{:08X}", header.message_id());
63    println!("Request ID: 0x{:08X}", header.request_id());
64
65    // Example 6: Different message types
66    println!("\n--- Example 6: Message Types ---");
67
68    let notification = SomeIpMessage::notification(ServiceId(0x1234), MethodId::event(0x0001))
69        .payload(b"Event data".as_slice())
70        .build();
71    println!("Notification: type={:?}, method_id={} (is_event: {})",
72        notification.header.message_type,
73        notification.header.method_id,
74        notification.header.method_id.is_event()
75    );
76
77    let fire_and_forget = SomeIpMessage::request_no_return(ServiceId(0x1234), MethodId(0x0002))
78        .payload(b"Fire and forget".as_slice())
79        .build();
80    println!("Fire-and-forget: type={:?}, expects_response: {}",
81        fire_and_forget.header.message_type,
82        fire_and_forget.expects_response()
83    );
84
85    // Example 7: Return codes
86    println!("\n--- Example 7: Return Codes ---");
87    for code in [
88        ReturnCode::Ok,
89        ReturnCode::NotOk,
90        ReturnCode::UnknownService,
91        ReturnCode::UnknownMethod,
92        ReturnCode::Timeout,
93    ] {
94        println!("  {:?}: is_ok={}, value=0x{:02X}", code, code.is_ok(), code as u8);
95    }
96
97    println!("\n=== Done! ===");
98}
Source

pub fn event(id: u16) -> Self

Create a method ID for an event.

Examples found in repository?
examples/message_basics.rs (line 68)
13fn main() {
14    println!("=== SOME/IP Message Basics ===\n");
15
16    // Example 1: Create a request message using the builder
17    println!("--- Example 1: Building Messages ---");
18    let request = SomeIpMessage::request(ServiceId(0x1234), MethodId(0x0001))
19        .client_id(ClientId(0x0100))
20        .session_id(SessionId(0x0001))
21        .interface_version(2)
22        .payload(b"Hello, World!".as_slice())
23        .build();
24
25    println!("Request message:");
26    print_message(&request);
27
28    // Example 2: Create a response from the request
29    println!("\n--- Example 2: Creating Responses ---");
30    let response = request
31        .create_response()
32        .payload(b"Response data".as_slice())
33        .build();
34
35    println!("Response message:");
36    print_message(&response);
37
38    // Example 3: Create an error response
39    println!("\n--- Example 3: Error Response ---");
40    let error = request
41        .create_error_response(ReturnCode::UnknownMethod)
42        .build();
43
44    println!("Error response:");
45    print_message(&error);
46
47    // Example 4: Serialize and deserialize
48    println!("\n--- Example 4: Serialization ---");
49    let bytes = request.to_bytes();
50    println!("Serialized to {} bytes", bytes.len());
51    println!("Header bytes: {:02X?}", &bytes[..HEADER_SIZE]);
52    println!("Payload bytes: {:02X?}", &bytes[HEADER_SIZE..]);
53
54    let parsed = SomeIpMessage::from_bytes(&bytes).expect("Failed to parse");
55    println!("\nParsed message matches original: {}", parsed == request);
56
57    // Example 5: Working with headers directly
58    println!("\n--- Example 5: Header Details ---");
59    let header = SomeIpHeader::new(ServiceId(0xFFFF), MethodId(0x8001));
60    println!("Service ID: {}", header.service_id);
61    println!("Method ID: {} (is_event: {})", header.method_id, header.method_id.is_event());
62    println!("Message ID: 0x{:08X}", header.message_id());
63    println!("Request ID: 0x{:08X}", header.request_id());
64
65    // Example 6: Different message types
66    println!("\n--- Example 6: Message Types ---");
67
68    let notification = SomeIpMessage::notification(ServiceId(0x1234), MethodId::event(0x0001))
69        .payload(b"Event data".as_slice())
70        .build();
71    println!("Notification: type={:?}, method_id={} (is_event: {})",
72        notification.header.message_type,
73        notification.header.method_id,
74        notification.header.method_id.is_event()
75    );
76
77    let fire_and_forget = SomeIpMessage::request_no_return(ServiceId(0x1234), MethodId(0x0002))
78        .payload(b"Fire and forget".as_slice())
79        .build();
80    println!("Fire-and-forget: type={:?}, expects_response: {}",
81        fire_and_forget.header.message_type,
82        fire_and_forget.expects_response()
83    );
84
85    // Example 7: Return codes
86    println!("\n--- Example 7: Return Codes ---");
87    for code in [
88        ReturnCode::Ok,
89        ReturnCode::NotOk,
90        ReturnCode::UnknownService,
91        ReturnCode::UnknownMethod,
92        ReturnCode::Timeout,
93    ] {
94        println!("  {:?}: is_ok={}, value=0x{:02X}", code, code.is_ok(), code as u8);
95    }
96
97    println!("\n=== Done! ===");
98}
Source

pub fn method(id: u16) -> Self

Create a method ID for a regular method.

Trait Implementations§

Source§

impl Clone for MethodId

Source§

fn clone(&self) -> MethodId

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for MethodId

Source§

impl Debug for MethodId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MethodId

Source§

fn default() -> MethodId

Returns the “default value” for a type. Read more
Source§

impl Display for MethodId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for MethodId

Source§

impl Hash for MethodId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MethodId

Source§

fn eq(&self, other: &MethodId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for MethodId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.