pub struct MutableStructEncoder<'a> { /* private fields */ }Expand description
Encoder for a @mutable struct that validates non-optional member
completeness (XTypes 1.3 §7.4.1.2.3).
Before each member encode, member_id is recorded as “emitted”; at
finish, every member ID listed in required_ids must have been
emitted, otherwise EncodeError::MissingNonOptionalMember is
returned.
Spec background: an EXTENSIBLE (final/appendable/mutable) encode
MUST contain all non-optional members. This validator closes the
encoder gap for @mutable, because with MUTABLE the EMHEADER order is
not fixed and encoder bugs would otherwise pass silently.
Implementations§
Source§impl<'a> MutableStructEncoder<'a>
impl<'a> MutableStructEncoder<'a>
Sourcepub fn new(writer: &'a mut BufferWriter, required_ids: Vec<u32>) -> Self
pub fn new(writer: &'a mut BufferWriter, required_ids: Vec<u32>) -> Self
New encoder. required_ids is the list of member IDs that, per
spec, MUST all be emitted (= all non-optional members of the
struct).
Sourcepub fn encode_member<F>(
&mut self,
member_id: u32,
must_understand: bool,
body: F,
) -> Result<(), EncodeError>
pub fn encode_member<F>( &mut self, member_id: u32, must_understand: bool, body: F, ) -> Result<(), EncodeError>
Encode a member. Behaves like encode_mutable_member, plus
tracking of the emitted ID.
§Errors
Same as encode_mutable_member.