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>
impl<'a> Serializer<'a>
Sourcepub fn new(buffer: &'a mut [u8]) -> Self
pub fn new(buffer: &'a mut [u8]) -> Self
Returns a new Serializer that writes to the given buffer.
Sourcepub fn write(&mut self, src: &[u8]) -> Result<usize>
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.
Sourcepub fn write_to(&mut self, range: Range<usize>, src: &[u8]) -> Result<usize>
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.
Sourcepub fn skip(&mut self, len: usize) -> Result<Range<usize>>
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.