pub trait Deserialize {
type Output: Sized;
// Required methods
fn deserialize<Buffer>(
buffer: &mut Buffer,
) -> Result<Self::Output, DeserializeError>
where Buffer: Buf + ?Sized;
fn size_hint() -> Option<usize>;
}Expand description
Deserialize data from a SOME/IP byte stream.
Required Associated Types§
Required Methods§
Sourcefn deserialize<Buffer>(
buffer: &mut Buffer,
) -> Result<Self::Output, DeserializeError>
fn deserialize<Buffer>( buffer: &mut Buffer, ) -> Result<Self::Output, DeserializeError>
Deserializes an instance of Deserialize::Output from the buffer.
§Errors
Returns a DeserializeError if the deserialization fails.
§Examples
use rsomeip_bytes::{Deserialize as _};
// The buffer can be any type that implements `Buf`.
let buffer = [0x12_u8, 0x34];
// Deserialize a type from the buffer.
let value = u16::deserialize(&mut buffer.as_slice())?;
assert_eq!(value, 0x1234);§Implementation notes
Care should be taken so that the serialized data matches the interface definition and that it’s compatible with the SOME/IP on-wire format to prevent issues during deserialization.
Sourcefn size_hint() -> Option<usize>
fn size_hint() -> Option<usize>
Returns the minimum size of a correctly serialized Self::Output.
Deserialization is guaranteed to fail if the buffer doesn’t contain at least this amount of bytes.
Having more than this amount of bytes in the buffer doesn’t guarantee that deserialization does succeed however, as the correct size of some types can only be known at runtime, but it’s guaranteed to be at least this value.
Returns None if the size is larger than usize::MAX.
§Examples
use rsomeip_bytes::{Deserialize as _};
// Basic types match the in-memory size.
assert_eq!(u8::size_hint(), Some(1));
assert_eq!(u16::size_hint(), Some(2));
assert_eq!(u32::size_hint(), Some(4));§Implementation notes
The value returned by this method should include the size of all statically known elements
of Self::Output.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".