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
impl TpHeader
sourcepub fn new(more_segment: bool) -> TpHeader
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);
sourcepub fn with_offset(
offset: u32,
more_segment: bool
) -> Result<TpHeader, TpOffsetNotMultipleOf16Error>
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);
sourcepub fn set_offset(
&mut self,
offset: u32
) -> Result<(), TpOffsetNotMultipleOf16Error>
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.
sourcepub fn read<T: Read>(reader: &mut T) -> Result<TpHeader, Error>
pub fn read<T: Read>(reader: &mut T) -> Result<TpHeader, Error>
Read a header from a byte stream.
sourcepub fn read_from_slice(slice: &[u8]) -> Result<TpHeader, LenError>
pub fn read_from_slice(slice: &[u8]) -> Result<TpHeader, LenError>
Reads a tp header from a slice.
sourcepub unsafe fn from_slice_unchecked(slice: &[u8]) -> TpHeader
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.
sourcepub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error>
pub fn write<T: Write>(&self, writer: &mut T) -> Result<(), Error>
Writes the header to the given writer.
sourcepub fn write_to_slice(
&self,
slice: &mut [u8]
) -> Result<(), SliceWriteSpaceError>
pub fn write_to_slice( &self, slice: &mut [u8] ) -> Result<(), SliceWriteSpaceError>
Writes the header to a slice.