TpBuf

Struct TpBuf 

Source
pub struct TpBuf { /* private fields */ }
Expand description

Buffer to reconstruct one SOMEIP TP packet stream without checks that the message id & request id are the same for all packets (this has to be done by the caller).

This buffer only reconstructs one TP stream and assumes that the user only sends data with matching “SOMEIP message id” and matching “SOMEIP request id” as well as matching sender to the buffer.

In case you want something that also automatically reconstructs multiple TP streams and can handles multiple TP stream with differing request ids and message id’s gracefully use crate::TpPool instead.

§Example

use someip_parse::TpBuf;
use someip_parse::SomeipMsgSlice;

// setup the buffer
// (replace default if you have knowledge about the upper package sizes)
let mut buf = TpBuf::new(Default::default());

// feed the packets to the buffer
let pkt1_slice = SomeipMsgSlice::from_slice(&pkt1_bytes)?;
assert!(pkt1_slice.is_tp()); // only tp packets are allowed
buf.consume_tp(pkt1_slice.clone())?;

// incomplete packets will fail to finalize
assert_eq!(None, buf.try_finalize());

let pkt2_slice = SomeipMsgSlice::from_slice(&pkt2_bytes)?;
assert!(pkt2_slice.is_tp());

// user of the TpBuf have to ensure the "message id"
// and "request id" are the same for all packets
assert_eq!(pkt1_slice.message_id(), pkt2_slice.message_id());
assert_eq!(pkt1_slice.request_id(), pkt2_slice.request_id());

buf.consume_tp(pkt2_slice.clone())?;

// once the packet is completed you can access the resulting packet
// via "try_finalize"
let reassembled = buf.try_finalize().unwrap();

// the re-assembled packet will be provided as a non TP SOMEIP slice
assert_eq!(false, reassembled.is_tp());
assert_eq!(reassembled.message_id(), pkt1_slice.message_id());
println!("Reconstructed payload: {:?}", reassembled.payload());

// finally you can clear the buffer to re-use the
// memory for a new stream
buf.clear();

Implementations§

Source§

impl TpBuf

Source

pub fn new(config: TpBufConfig) -> TpBuf

Source

pub fn clear(&mut self)

Reset buffer to starting state.

Source

pub fn consume_tp( &mut self, someip_slice: SomeipMsgSlice<'_>, ) -> Result<(), TpReassembleError>

Consume a TP SOMEIP slice (caller must ensure that someip_slice.is_tp() is true).

Source

pub fn is_complete(&self) -> bool

Source

pub fn try_finalize(&mut self) -> Option<SomeipMsgSlice<'_>>

Try finalizing the reconstructed TP packet and return a reference to it if the stream reconstruction was completed.

Trait Implementations§

Source§

impl Clone for TpBuf

Source§

fn clone(&self) -> TpBuf

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TpBuf

Source§

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

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

impl Hash for TpBuf

Source§

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

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

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 Ord for TpBuf

Source§

fn cmp(&self, other: &TpBuf) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for TpBuf

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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 PartialOrd for TpBuf

Source§

fn partial_cmp(&self, other: &TpBuf) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for TpBuf

Source§

impl StructuralPartialEq for TpBuf

Auto Trait Implementations§

§

impl Freeze for TpBuf

§

impl RefUnwindSafe for TpBuf

§

impl Send for TpBuf

§

impl Sync for TpBuf

§

impl Unpin for TpBuf

§

impl UnwindSafe for TpBuf

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.