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, encoding: Encoding) -> Decoder<'a>
pub fn new(buf: &'a [u8], order: ByteOrder, encoding: Encoding) -> Decoder<'a>
Creates a decoder whose first byte is at stream offset 0.
Sourcepub fn with_offset(
buf: &'a [u8],
order: ByteOrder,
encoding: Encoding,
base: usize,
) -> Decoder<'a>
pub fn with_offset( buf: &'a [u8], order: ByteOrder, encoding: Encoding, 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], encoding: Encoding) -> Result<Decoder<'a>>
pub fn encapsulation(buf: &'a [u8], encoding: Encoding) -> 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 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, or
of the encoding’s max_align when that is
smaller.
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. In an
XCDR stream the offset counts from the alignment origin (see
set_origin).
Sourcepub fn origin(&self) -> usize
pub fn origin(&self) -> usize
The stream offset alignment counts from: 0 unless changed with
set_origin.
Sourcepub fn set_origin(&mut self, origin: usize)
pub fn set_origin(&mut self, origin: usize)
Makes alignment count from stream offset origin. This is the XCDR
PUSH(ORIGIN); read_parameter does it
itself.
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. XCDR
has an octet length and code units in the stream byte order.
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.
Source§impl<'a> Decoder<'a>
impl<'a> Decoder<'a>
Sourcepub fn xcdr_payload(buf: &'a [u8]) -> Result<(Decoder<'a>, PayloadHeader)>
pub fn xcdr_payload(buf: &'a [u8]) -> Result<(Decoder<'a>, PayloadHeader)>
Opens an RTPS SerializedPayload: reads the encapsulation header and returns a decoder positioned after it, with alignment counted from there, and the header. Padding the options say follows the data is left out of the decoder.
Sourcepub fn read_dheader(&mut self) -> Result<Delimited>
pub fn read_dheader(&mut self) -> Result<Delimited>
Reads a DHEADER (DDS-XTypes 7.4.3.4.1). Read the object, then call
end_dheader, which skips what was not
read: members that a newer version of an appendable type added.
Sourcepub fn end_dheader(&mut self, delimited: Delimited) -> Result<()>
pub fn end_dheader(&mut self, delimited: Delimited) -> Result<()>
Moves to the end of the object of delimited. Reading past it is
an error.
Sourcepub fn read_member_header(&mut self) -> Result<MemberHeader>
pub fn read_member_header(&mut self) -> Result<MemberHeader>
Reads the EMHEADER of a member of an XCDR2 mutable type
(DDS-XTypes 7.4.3.4.2) and leaves the decoder at the member. Read
it or not, then call end_member.
With length codes 5 to 7, NEXTINT is also the first 4 octets of the member (rule 22), so the decoder is left on it, and the length counts it: 4 + NEXTINT, 4 + 4 × NEXTINT or 4 + 8 × NEXTINT octets.
Sourcepub fn end_member(&mut self, header: MemberHeader) -> Result<()>
pub fn end_member(&mut self, header: MemberHeader) -> Result<()>
Moves to the end of the member of header. Reading past it is an
error.
Sourcepub fn read_parameter_header(&mut self) -> Result<Parameter>
pub fn read_parameter_header(&mut self) -> Result<Parameter>
Reads a parameter header of XCDR1 (DDS-XTypes 7.4.1.2), short or
extended, and makes alignment count from the byte after it. Read
the member or not, then call
end_parameter.
This reads the header in front of an optional member of a final or
appendable type, where a length of 0 means the member is absent.
In a parameter list use read_parameter,
which knows its end.
Sourcepub fn read_parameter(&mut self, list_end: ListEnd) -> Result<Option<Parameter>>
pub fn read_parameter(&mut self, list_end: ListEnd) -> Result<Option<Parameter>>
Reads the next parameter header of an XCDR1 parameter list, or
None at its end. Parameters with PID_IGNORE are skipped. The
list ends with PID_LIST_END (with any flags), or for
ListEnd::Rtps also with PID_SENTINEL.
Sourcepub fn end_parameter(&mut self, param: Parameter) -> Result<()>
pub fn end_parameter(&mut self, param: Parameter) -> Result<()>
Moves to the end of the parameter param and restores the
alignment origin. Reading past it is an error.