pub struct Encoder { /* private fields */ }Expand description
Writes CDR into a growable buffer.
Alignment is relative to the stream offset of the first byte, which is
0 unless the encoder was created with Encoder::with_offset.
An encoder that allows shared octets keeps
large octet sequences written with
write_octet_seq_shared apart from
its buffer: into_parts gives the buffer and
where each goes, for a vectored write, and
into_bytes puts them in place.
Implementations§
Source§impl Encoder
impl Encoder
Sourcepub fn new(order: ByteOrder, encoding: Encoding) -> Encoder
pub fn new(order: ByteOrder, encoding: Encoding) -> Encoder
Creates an encoder whose first byte is at stream offset 0.
Sourcepub fn with_offset(order: ByteOrder, encoding: Encoding, base: usize) -> Encoder
pub fn with_offset(order: ByteOrder, encoding: Encoding, base: usize) -> Encoder
Creates an encoder whose first byte is at stream offset base.
Sourcepub fn encapsulation(order: ByteOrder, encoding: Encoding) -> Encoder
pub fn encapsulation(order: ByteOrder, encoding: Encoding) -> Encoder
Starts an encapsulation: offset 0, with the byte order octet written.
Sourcepub fn set_wstring_bom(&mut self, bom: bool)
pub fn set_wstring_bom(&mut self, bom: bool)
Chooses how a GIOP 1.2 wstring is written: with a BOM followed by
code units in the stream byte order (the default, as omniORB does),
or, when false, big endian without a BOM (the form the
specification defines for a missing BOM). Readers that follow
CORBA 2.4 or later accept both.
Sourcepub fn byte_order(&self) -> ByteOrder
pub fn byte_order(&self) -> ByteOrder
The byte order of the stream.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
The bytes written into the buffer so far: all of them, unless shared octets were kept apart.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Mutable access to the buffer, for patching lengths. Indexes are buffer indexes, which differ from stream offsets after shared octets.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Drops bytes past len, which must not be before shared octets.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Consumes the encoder and returns the bytes, shared octets copied in place.
Sourcepub fn into_parts(self) -> (Vec<u8>, Vec<(usize, Octets)>)
pub fn into_parts(self) -> (Vec<u8>, Vec<(usize, Octets)>)
Consumes the encoder and returns the buffer and the shared octets, each with the buffer length at which it goes.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Makes room for at least additional more bytes in the buffer.
Lets write_octet_seq_shared
keep large octet sequences apart from the buffer. Only for an
encoder whose result goes out through
into_parts or
into_bytes, not one read through
as_bytes.
Sourcepub fn align(&mut self, align: usize)
pub fn align(&mut self, align: usize)
Pads with zero octets until the stream offset is a multiple of
align, or of the encoding’s max_align
when that is smaller.
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, which must not
be past position. This is the XCDR
PUSH(ORIGIN); the parameter headers of
begin_parameter do it themselves.
Sourcepub fn write_octet(&mut self, value: u8)
pub fn write_octet(&mut self, value: u8)
Writes an octet.
Sourcepub fn write_bool(&mut self, value: bool)
pub fn write_bool(&mut self, value: bool)
Writes a boolean.
Sourcepub fn write_char(&mut self, value: u8)
pub fn write_char(&mut self, value: u8)
Writes a char as a single octet in the transmission code set.
Sourcepub fn write_long_double(&mut self, value: LongDouble)
pub fn write_long_double(&mut self, value: LongDouble)
Writes a long double: 16 octets on an 8 octet boundary.
Sourcepub fn write_octets(&mut self, bytes: &[u8])
pub fn write_octets(&mut self, bytes: &[u8])
Writes raw octets without alignment or a length.
Sourcepub fn write_octet_seq(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_octet_seq(&mut self, bytes: &[u8]) -> Result<()>
Writes a sequence<octet>.
Writes a sequence<octet> without copying a large one, if the
encoder allows it and no valuetype is
being written (whose chunk lengths count the buffer), and the
encoding is a GIOP one (XCDR headers are patched in the buffer). Otherwise
like write_octet_seq.
Sourcepub fn write_string_bytes(&mut self, bytes: &[u8]) -> Result<()>
pub fn write_string_bytes(&mut self, bytes: &[u8]) -> Result<()>
Writes a string from bytes already in the transmission code set.
The length includes the terminating NUL, which is appended here.
Sourcepub fn write_string(&mut self, value: &str) -> Result<()>
pub fn write_string(&mut self, value: &str) -> Result<()>
Writes a string as UTF-8.
Sourcepub fn write_wchar(&mut self, value: u16) -> Result<()>
pub fn write_wchar(&mut self, value: u16) -> Result<()>
Writes a wchar holding one UTF-16 code unit.
GIOP 1.1 and XCDR (Char16, DDS-XTypes 7.4.1.1.1) write an aligned
unsigned short in the stream byte order. GIOP 1.2 writes an octet length of 2 followed by the code unit in big
endian without a BOM, as omniORB does.
Sourcepub fn write_wstring(&mut self, value: &str) -> Result<()>
pub fn write_wstring(&mut self, value: &str) -> Result<()>
Writes a wstring encoded as UTF-16.
GIOP 1.1 writes the number of code units including a terminating
NUL, then aligned code units in the stream byte order. GIOP 1.2
writes the octet length, then the code units without a terminator:
by default a BOM followed by the stream byte order, or big endian
without a BOM (see Encoder::set_wstring_bom). An empty string is
just a zero length. XCDR (DDS-XTypes 7.4.1.1.2) writes the length in
octets, then the code units in the stream byte order, without a BOM
or a terminator.
Sourcepub fn write_encapsulation<F>(&mut self, f: F) -> Result<()>
pub fn write_encapsulation<F>(&mut self, f: F) -> Result<()>
Writes an encapsulation as a sequence<octet>.
f writes the contents into a fresh encoder whose alignment starts
at the byte order octet. The encapsulation uses this stream’s byte
order and version.
Source§impl Encoder
impl Encoder
Sourcepub fn write_null_value(&mut self)
pub fn write_null_value(&mut self)
Writes a null value.
Sourcepub fn begin_value(
&mut self,
key: u64,
ids: &[&str],
chunked: bool,
) -> Result<bool>
pub fn begin_value( &mut self, key: u64, ids: &[&str], chunked: bool, ) -> Result<bool>
Starts writing a value.
key identifies the value: if a value with the same key was
written before in this stream, an indirection to it is written and
false is returned. Otherwise the value tag and ids (repository
ids, most derived first; none leaves the type to the receiver) are
written and true is returned: the caller writes the state and
then calls Encoder::end_value.
A value nested in a chunked value is chunked as well.
Sourcepub fn end_value(&mut self) -> Result<()>
pub fn end_value(&mut self) -> Result<()>
Ends the value started by the last Encoder::begin_value that
returned true.
Source§impl Encoder
impl Encoder
Sourcepub fn xcdr_payload(format: XcdrFormat, order: ByteOrder) -> Encoder
pub fn xcdr_payload(format: XcdrFormat, order: ByteOrder) -> Encoder
Starts an RTPS SerializedPayload: the encapsulation identifier of
format and order, the options, and alignment counted from the
byte after them (DDSI-RTPS 2.5 10.2, DDS-XTypes 7.4.3.5.3 rule 1).
End it with finish_xcdr_payload.
Sourcepub fn finish_xcdr_payload(self) -> Vec<u8> ⓘ
pub fn finish_xcdr_payload(self) -> Vec<u8> ⓘ
Ends a payload started with
xcdr_payload: zero padding up to a
multiple of 4 octets, its length recorded in the options
(DDS-XTypes 7.6.3.1.2), and the bytes.
Sourcepub fn begin_dheader(&mut self) -> DHeaderMark
pub fn begin_dheader(&mut self) -> DHeaderMark
Writes a DHEADER to be filled in by
end_dheader with the length of what is
written in between (DDS-XTypes 7.4.3.4.1).
Marks of begin_dheader,
begin_member and
begin_parameter must be ended
innermost first.
Sourcepub fn end_dheader(&mut self, mark: DHeaderMark) -> Result<()>
pub fn end_dheader(&mut self, mark: DHeaderMark) -> Result<()>
Fills in the DHEADER of mark.
Sourcepub fn begin_member(
&mut self,
id: u32,
must_understand: bool,
) -> Result<MemberMark>
pub fn begin_member( &mut self, id: u32, must_understand: bool, ) -> Result<MemberMark>
Starts a member of an XCDR2 mutable type: an EMHEADER for member
id, filled in by end_member with the
length of what is written in between (DDS-XTypes 7.4.3.4.2, rule
22). Only for Encoding::Xcdr2.
Sourcepub fn end_member(&mut self, mark: MemberMark) -> Result<()>
pub fn end_member(&mut self, mark: MemberMark) -> Result<()>
Fills in the EMHEADER of mark. A member of 1, 2, 4 or 8 octets
gets a length code of 0 to 3 and no NEXTINT; any other gets length
code 4 and its length in NEXTINT. (Length codes 5 to 7, which share
NEXTINT with the member, are read but not written.)
Sourcepub fn begin_parameter(
&mut self,
id: u32,
must_understand: bool,
) -> Result<ParameterMark>
pub fn begin_parameter( &mut self, id: u32, must_understand: bool, ) -> Result<ParameterMark>
Starts a parameter of an XCDR1 parameter list, or the header of an
XCDR1 optional member: a parameter header for member id, filled
in by end_parameter with the length of
what is written in between (DDS-XTypes 7.4.1.2, rules 24 and 25).
The header is a short one (16-bit ID and length) when id is at
most MAX_SHORT_PID, and an extended one (PID_EXTENDED)
otherwise or when the member turns out longer than 65535 octets.
Alignment counts from the byte after the header until
end_parameter. An absent optional member is a parameter with
nothing written in it.
Sourcepub fn end_parameter(&mut self, mark: ParameterMark) -> Result<()>
pub fn end_parameter(&mut self, mark: ParameterMark) -> Result<()>
Fills in the parameter header of mark and restores the alignment
origin. The length is that of the member, without padding
(DDS-XTypes 7.4.1.2).
Sourcepub fn end_parameter_list(&mut self, end: ListEnd)
pub fn end_parameter_list(&mut self, end: ListEnd)
Ends an XCDR1 parameter list with end and a zero length (rule
23).