Serializer

Struct Serializer 

Source
pub struct Serializer<'a> { /* private fields */ }
Expand description

Writes data to byte buffers, according to the SOME/IP specification.

Implementations§

Source§

impl<'a> Serializer<'a>

Source

pub fn new(buffer: &'a mut [u8]) -> Self

Returns a new Serializer that writes to the given buffer.

Source

pub fn write(&mut self, src: &[u8]) -> Result<usize>

Copies the contents of the source slice into the buffer, at the cursor’s current position.

If successful, it will advance the cursor position by the amount of bytes written, so that the next call to write will place the new bytes after the last ones.

§Errors

Returns an error if writing to the cursor’s current position would exceed the buffer’s capacity.

Source

pub fn write_to(&mut self, range: Range<usize>, src: &[u8]) -> Result<usize>

Copies the contents of the source slice into the buffer, over the given range.

If the range goes past the cursors old position, it will move the cursor to the new end position, so that the next call to write will place the new bytes after the range.

§Errors

Returns an error if writing at the given range would exceed the buffer’s capacity, in which case, nothing is written to the buffer nor the cursor updated.

Source

pub fn skip(&mut self, len: usize) -> Result<Range<usize>>

Advances the cursor position without writing anything to the buffer, returning the range that was skipped.

This function may be useful for inserting padding in the serialized data.

§Errors

Returns an error if the new cursor position would exceed the buffer’s capacity, in which case, the cursor is not moved.

Auto Trait Implementations§

§

impl<'a> Freeze for Serializer<'a>

§

impl<'a> RefUnwindSafe for Serializer<'a>

§

impl<'a> Send for Serializer<'a>

§

impl<'a> Sync for Serializer<'a>

§

impl<'a> Unpin for Serializer<'a>

§

impl<'a> !UnwindSafe for Serializer<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.