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_data = crate::serialize::SerializeExt::serialize(&value, &mut buffer);
16
17        assert!(matches!(serialized_data, Ok(..)));
18
19        let serialized_data = serialized_data.unwrap();
20
21        // Required length.
22
23        assert_eq!(serialized_data.len(), buffer_length);
24
25        assert_eq!(serialized_data, $expected);
26
27        // Parse valid.
28
29        let parsed = <$type as crate::parse::ParseExt>::parse(serialized_data);
30
31        assert!(matches!(parsed, Ok(..)));
32        assert_eq!(parsed.unwrap(), value);
33
34        // Serialize too short
35        for cut_off in 0..serialized_data.len().saturating_sub(1) {
36            let mut buffer = [0u8; 2048];
37
38            assert!(matches!(
39                crate::serialize::SerializeExt::serialize(&value, &mut buffer[..cut_off]),
40                Err(crate::serialize::SerializeError::BufferTooSmall)
41            ));
42        }
43
44        // Parse too short
45        for cut_off in 0..serialized_data.len().saturating_sub(1) {
46            assert!(matches!(
47                <$type as crate::parse::ParseExt>::parse(&serialized_data[..cut_off]),
48                Err(crate::parse::ParseError::PayloadTooShort)
49                    | Err(crate::parse::ParseError::MalformedMessage { .. })
50            ));
51        }
52
53        // Parse empty
54        assert!(matches!(
55            <$type as crate::parse::ParseExt>::parse(&[]),
56            Err(crate::parse::ParseError::PayloadTooShort)
57                | Err(crate::parse::ParseError::MalformedMessage { .. })
58        ));
59    };
60}
61
62pub mod array;
63pub mod header;
64pub mod length;
65pub mod parse;
66pub mod parse_impl;
67pub mod serialize;
68pub mod serialize_impl;
69pub mod service_discovery;
70pub mod string;
71
72// Make `Parse` derive macro work inside this crate.
73// This is required because the macro expects the `veecle_os_data_support_someip` crate to be imported.
74extern crate self as veecle_os_data_support_someip;