deserialize_from

Macro deserialize_from 

Source
macro_rules! deserialize_from {
    ($buffer:expr, length=$length:ident, $($repr:ty),+) => { ... };
    ($buffer:expr, $($repr:ty),+) => { ... };
}
Expand description

Deserializes a series of variables from the given buffer.

An optional length parameter can be specified to deserialize the variables using deserialize_len.

§Performance Considerations

This macro is provided simply as a convenience for implementing the Deserialize trait.

It uses tuples to deserialize the variables from the buffer, which may not be the most performant solution for every use case, but is one that works well in most situations.

§Examples

use rsomeip_bytes::{Bytes, Deserialize, deserialize_from};

let mut buffer = Bytes::copy_from_slice(&[1u8, 2, 2, 3, 4][..]);

let (a, b) = deserialize_from!(&mut buffer, u8, u8).expect("should deserialize");
let (c, d) = deserialize_from!(&mut buffer, length = U8, u8, u8).expect("should deserialize");

assert_eq!([a, b, c, d], [1u8, 2, 3, 4]);