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>
impl<'a> Decoder<'a>
Sourcepub fn new(buf: &'a [u8], order: ByteOrder, version: CdrVersion) -> Decoder<'a>
pub fn new(buf: &'a [u8], order: ByteOrder, version: CdrVersion) -> Decoder<'a>
Creates a decoder whose first byte is at stream offset 0.
Sourcepub fn with_offset(
buf: &'a [u8],
order: ByteOrder,
version: CdrVersion,
base: usize,
) -> Decoder<'a>
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.
Sourcepub fn set_segments(&mut self, segments: &'a [Segment])
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.
Sourcepub fn encapsulation(buf: &'a [u8], version: CdrVersion) -> Result<Decoder<'a>>
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.
Sourcepub fn set_wstring_default_order(&mut self, order: ByteOrder)
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.
Sourcepub fn byte_order(&self) -> ByteOrder
pub fn byte_order(&self) -> ByteOrder
The byte order of the stream.
Sourcepub fn version(&self) -> CdrVersion
pub fn version(&self) -> CdrVersion
The GIOP version whose CDR rules apply.
Sourcepub fn remaining_bytes(&self) -> &'a [u8] ⓘ
pub fn remaining_bytes(&self) -> &'a [u8] ⓘ
The bytes left to read, without consuming them.
Sourcepub fn align(&mut self, align: usize) -> Result<()>
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.
Sourcepub fn read_octets(&mut self, n: usize) -> Result<&'a [u8]>
pub fn read_octets(&mut self, n: usize) -> Result<&'a [u8]>
Reads n raw octets without alignment.
Sourcepub fn read_octet(&mut self) -> Result<u8>
pub fn read_octet(&mut self) -> Result<u8>
Reads an octet.
Sourcepub fn read_bool(&mut self) -> Result<bool>
pub fn read_bool(&mut self) -> Result<bool>
Reads a boolean. Octets other than 0 and 1 are rejected.
Sourcepub fn read_char(&mut self) -> Result<u8>
pub fn read_char(&mut self) -> Result<u8>
Reads a char as a single octet in the transmission code set.
Sourcepub fn read_long_double(&mut self) -> Result<LongDouble>
pub fn read_long_double(&mut self) -> Result<LongDouble>
Reads a long double: 16 octets on an 8 octet boundary.
Sourcepub fn read_len(&mut self, min_element_size: usize) -> Result<usize>
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.
Sourcepub fn read_octet_seq(&mut self) -> Result<&'a [u8]>
pub fn read_octet_seq(&mut self) -> Result<&'a [u8]>
Reads a sequence<octet> without copying.
Tells the decoder that its bytes lie in buf, so that
read_octet_seq_shared can share
them.
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.
Reads len raw octets like
read_octet_seq_shared reads a
sequence’s.
Sourcepub fn read_string_bytes(&mut self) -> Result<&'a [u8]>
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.
Sourcepub fn read_string(&mut self) -> Result<String>
pub fn read_string(&mut self) -> Result<String>
Reads a string as UTF-8.
Sourcepub fn read_wchar(&mut self) -> Result<u16>
pub fn read_wchar(&mut self) -> Result<u16>
Reads a wchar holding one UTF-16 code unit.
Sourcepub fn read_wstring(&mut self) -> Result<String>
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.
Sourcepub fn read_encapsulation(&mut self) -> Result<Decoder<'a>>
pub fn read_encapsulation(&mut self) -> Result<Decoder<'a>>
Reads an encapsulation and returns a decoder over its contents.
Source§impl Decoder<'_>
impl Decoder<'_>
Sourcepub fn read_value_header(&mut self) -> Result<ValueHeader>
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.