veecle_os_data_support_someip/
lib.rs

1//! Support for working with SOME/IP within a runtime instance.
2
3#![no_std]
4#![forbid(unsafe_code)]
5#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
6
7#[cfg(test)]
8macro_rules! test_round_trip {
9    ($type:ty, $value:expr, $expected:expr) => {
10        let value = $value;
11
12        // Serialize valid.
13        let mut buffer = [0u8; 2048];
14        let buffer_length = crate::serialize::Serialize::required_length(&value);
15        let serialized_length =
16            crate::serialize::SerializeExt::serialize(&value, &mut buffer).unwrap();
17
18        let serialized_data = &buffer[..serialized_length];
19
20        // Required length.
21
22        assert_eq!(serialized_data.len(), buffer_length);
23
24        assert_eq!(serialized_data, $expected);
25
26        // Parse valid.
27
28        let parsed = <$type as crate::parse::ParseExt>::parse(serialized_data);
29
30        assert!(matches!(parsed, Ok(..)));
31        assert_eq!(parsed.unwrap(), value);
32
33        // Serialize too short
34        for cut_off in 0..serialized_data.len().saturating_sub(1) {
35            let mut buffer = [0u8; 2048];
36
37            assert!(matches!(
38                crate::serialize::SerializeExt::serialize(&value, &mut buffer[..cut_off]),
39                Err(crate::serialize::SerializeError::BufferTooSmall)
40            ));
41        }
42
43        // Parse too short
44        for cut_off in 0..serialized_data.len().saturating_sub(1) {
45            assert!(matches!(
46                <$type as crate::parse::ParseExt>::parse(&serialized_data[..cut_off]),
47                Err(crate::parse::ParseError::PayloadTooShort)
48                    | Err(crate::parse::ParseError::MalformedMessage { .. })
49            ));
50        }
51
52        // Parse empty
53        assert!(matches!(
54            <$type as crate::parse::ParseExt>::parse(&[]),
55            Err(crate::parse::ParseError::PayloadTooShort)
56                | Err(crate::parse::ParseError::MalformedMessage { .. })
57        ));
58    };
59}
60
61pub mod array;
62pub mod header;
63pub mod length;
64pub mod parse;
65pub mod parse_impl;
66pub mod serialize;
67pub mod serialize_impl;
68pub mod service_discovery;
69pub mod string;
70
71// Make `Parse` derive macro work inside this crate.
72// This is required because the macro expects the `veecle_os_data_support_someip` crate to be imported.
73extern crate self as veecle_os_data_support_someip;