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
impl TpBuf
pub fn new(config: TpBufConfig) -> TpBuf
Sourcepub fn consume_tp(
&mut self,
someip_slice: SomeipMsgSlice<'_>,
) -> Result<(), TpReassembleError>
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).
pub fn is_complete(&self) -> bool
Sourcepub fn try_finalize(&mut self) -> Option<SomeipMsgSlice<'_>>
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 Ord for TpBuf
impl Ord for TpBuf
Source§impl PartialOrd for TpBuf
impl PartialOrd for TpBuf
impl Eq for TpBuf
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)