Skip to main content

Decoder

Struct Decoder 

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

Reads CDR from a byte slice.

Alignment is relative to the stream offset of the first byte, which is 0 unless the decoder was created with Decoder::with_offset. Decoder::set_segments restarts the stream offset at given bytes, for data joined from several messages.

Implementations§

Source§

impl<'a> Decoder<'a>

Source

pub fn new(buf: &'a [u8], order: ByteOrder, version: CdrVersion) -> Decoder<'a>

Creates a decoder whose first byte is at stream offset 0.

Source

pub fn with_offset( buf: &'a [u8], order: ByteOrder, version: CdrVersion, base: usize, ) -> Decoder<'a>

Creates a decoder whose first byte is at stream offset base.

Source

pub fn set_segments(&mut self, segments: &'a [Segment])

Restarts the stream offset at the given buffer indexes. segments must be sorted by start; bytes before the first segment keep the offset given when the decoder was created.

Source

pub fn encapsulation(buf: &'a [u8], version: CdrVersion) -> Result<Decoder<'a>>

Opens an encapsulation: reads the byte order octet and returns a decoder positioned after it, with alignment starting at that octet.

Source

pub fn set_wstring_default_order(&mut self, order: ByteOrder)

Sets the byte order assumed for a GIOP 1.2 wstring or wchar without a BOM. The specification says big endian, which is the default; some ORBs use the stream byte order instead.

Source

pub fn byte_order(&self) -> ByteOrder

The byte order of the stream.

Source

pub fn version(&self) -> CdrVersion

The GIOP version whose CDR rules apply.

Source

pub fn position(&self) -> usize

The stream offset of the next byte.

Source

pub fn remaining(&self) -> usize

Bytes left to read.

Source

pub fn is_empty(&self) -> bool

Whether every byte has been read.

Source

pub fn remaining_bytes(&self) -> &'a [u8] ⓘ

The bytes left to read, without consuming them.

Source

pub fn align(&mut self, align: usize) -> Result<()>

Skips padding until the stream offset is a multiple of align.

Inside a chunked valuetype, a chunk that ends here is followed by the next one: its length is read and the data aligned in it.

Source

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

Skips n bytes.

Source

pub fn read_octets(&mut self, n: usize) -> Result<&'a [u8]>

Reads n raw octets without alignment.

Source

pub fn read_octet(&mut self) -> Result<u8>

Reads an octet.

Source

pub fn read_bool(&mut self) -> Result<bool>

Reads a boolean. Octets other than 0 and 1 are rejected.

Source

pub fn read_char(&mut self) -> Result<u8>

Reads a char as a single octet in the transmission code set.

Source

pub fn read_i16(&mut self) -> Result<i16>

Reads a short.

Source

pub fn read_u16(&mut self) -> Result<u16>

Reads an unsigned short.

Source

pub fn read_i32(&mut self) -> Result<i32>

Reads a long.

Source

pub fn read_u32(&mut self) -> Result<u32>

Reads an unsigned long.

Source

pub fn read_i64(&mut self) -> Result<i64>

Reads a long long.

Source

pub fn read_u64(&mut self) -> Result<u64>

Reads an unsigned long long.

Source

pub fn read_f32(&mut self) -> Result<f32>

Reads a float.

Source

pub fn read_f64(&mut self) -> Result<f64>

Reads a double.

Source

pub fn read_long_double(&mut self) -> Result<LongDouble>

Reads a long double: 16 octets on an 8 octet boundary.

Source

pub fn read_len(&mut self, min_element_size: usize) -> Result<usize>

Reads a sequence length and checks that len * min_element_size bytes are left, so a corrupt length cannot cause a huge allocation.

Source

pub fn read_octet_seq(&mut self) -> Result<&'a [u8]>

Reads a sequence<octet> without copying.

Source

pub fn set_shared(&mut self, buf: &'a Arc<Vec<u8>>)

Tells the decoder that its bytes lie in buf, so that read_octet_seq_shared can share them.

Source

pub fn read_octet_seq_shared(&mut self) -> Result<Octets>

Reads a sequence<octet> that keeps pointing into the decoder’s buffer, when that is shared (see set_shared) and the sequence is not short; otherwise a copy.

Source

pub fn read_octets_shared(&mut self, len: usize) -> Result<Octets>

Reads len raw octets like read_octet_seq_shared reads a sequence’s.

Source

pub fn read_string_bytes(&mut self) -> Result<&'a [u8]>

Reads a string as bytes in the transmission code set, without the terminating NUL.

A length of 0 is not allowed by the specification but is accepted as an empty string, since some ORBs send it.

Source

pub fn read_string(&mut self) -> Result<String>

Reads a string as UTF-8.

Source

pub fn read_wchar(&mut self) -> Result<u16>

Reads a wchar holding one UTF-16 code unit.

Source

pub fn read_wstring(&mut self) -> Result<String>

Reads a wstring encoded as UTF-16.

For GIOP 1.2 a leading BOM selects the byte order; without one the order set by Decoder::set_wstring_default_order is used.

Source

pub fn read_encapsulation(&mut self) -> Result<Decoder<'a>>

Reads an encapsulation and returns a decoder over its contents.

Source§

impl Decoder<'_>

Source

pub fn read_value_header(&mut self) -> Result<ValueHeader>

Reads what stands where a value is expected: null, an indirection to a value read before, or the header of a new value.

After ValueHeader::Value, the caller reads the state and then calls Decoder::end_value.

Source

pub fn end_value(&mut self) -> Result<()>

Ends the value whose header was read last and is not yet ended.

For a chunked value, the rest of its state (chunks and nested values a truncating reader did not read) is skipped up to its end tag.

Trait Implementations§

Source§

impl<'a> Clone for Decoder<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Decoder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Decoder<'a>

§

impl<'a> RefUnwindSafe for Decoder<'a>

§

impl<'a> Send for Decoder<'a>

§

impl<'a> Sync for Decoder<'a>

§

impl<'a> Unpin for Decoder<'a>

§

impl<'a> UnsafeUnpin for Decoder<'a>

§

impl<'a> UnwindSafe for Decoder<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.