Struct someip_parse::TpHeader

source ·
pub struct TpHeader {
    pub more_segment: bool,
    /* private fields */
}
Expand description

Additional header when a packet contains a TP header (transporting large SOME/IP messages).

Fields§

§more_segment: bool

Flag signaling that more packets should follow

Implementations§

source§

impl TpHeader

source

pub fn new(more_segment: bool) -> TpHeader

Creates a tp header with offset 0 and the given “move_segment” flag.

Example:
use someip_parse::TpHeader;

// create a header with the more_segement flag set
let header = TpHeader::new(true);

assert_eq!(0, header.offset());
assert_eq!(true, header.more_segment);
source

pub fn with_offset( offset: u32, more_segment: bool ) -> Result<TpHeader, TpOffsetNotMultipleOf16Error>

Creates a tp header with the given offset & “more_segment” flag if the offset is a multiple of 16. Otherwise an TpOffsetNotMultipleOf16 error is returned.

Example:
use someip_parse::{TpHeader, err::TpOffsetNotMultipleOf16Error};

// create a header with offset 32 (multiple of 16) and the more_segement flag set
let header = TpHeader::with_offset(32, true).unwrap();

assert_eq!(32, header.offset());
assert_eq!(true, header.more_segment);

// try to create a header with a bad offset (non multiple of 16)
let error = TpHeader::with_offset(31, false);

assert_eq!(Err(TpOffsetNotMultipleOf16Error{ bad_offset: 31 }), error);
source

pub fn offset(&self) -> u32

Returns the offset field of the tp header. The offset defines

source

pub fn set_offset( &mut self, offset: u32 ) -> Result<(), TpOffsetNotMultipleOf16Error>

Sets the field of the header and returns Ok(()) on success. Note: The value must be a multiple of 16.

If the given value is not a multiple of 16, the value is not set and an error err::TpOffsetNotMultipleOf16Error is returned.

source

pub fn read<T: Read>(reader: &mut T) -> Result<TpHeader, Error>

Read a header from a byte stream.

source

pub fn read_from_slice(slice: &[u8]) -> Result<TpHeader, LenError>

Reads a tp header from a slice.

source

pub unsafe fn from_slice_unchecked(slice: &[u8]) -> TpHeader

Read the value from the slice without checking for the minimum length of the slice.

Safety

It is required that the slice has at least the length of TP_HEADER_LENGTH (4 octets/bytes). If this is not the case undefined behavior will occur.

source

pub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error>

Writes the header to the given writer.

source

pub fn write_to_slice( &self, slice: &mut [u8] ) -> Result<(), SliceWriteSpaceError>

Writes the header to a slice.

source

pub fn to_bytes(&self) -> [u8; 4]

Writes the header to a slice without checking the slice length.

Trait Implementations§

source§

impl Clone for TpHeader

source§

fn clone(&self) -> TpHeader

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for TpHeader

source§

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

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

impl Default for TpHeader

source§

fn default() -> TpHeader

Returns the “default value” for a type. Read more
source§

impl PartialEq for TpHeader

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for TpHeader

source§

impl StructuralEq for TpHeader

source§

impl StructuralPartialEq for TpHeader

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

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

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
source§

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.
source§

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

Performs the conversion.