pub fn encode_in_envelope(
    val: &mut Option<&mut dyn Encodable>,
    encoder: &mut Encoder<'_>,
) -> Result<()> {
    // u32 num_bytes
    // u32 num_handles
    // 64-bit presence indicator

    // Record the offset of the number of bytes handles in the envelope,
    // so that we can come back to it after writing the bytes and handles
    // (until which point we don't know how many handles will be written).
    let envelope_offset = encoder.offset;
    0u32.encode(encoder)?; // num_bytes
    0u32.encode(encoder)?; // num_handles

    match val {
        Some(x) => {
            ALLOC_PRESENT_U64.encode(encoder)?;
            let bytes_before = encoder.buf.len();
            let handles_before = encoder.handles.len();
            encoder.write_out_of_line(x.inline_size(encoder.context), |e| x.encode(e))?;
            let mut bytes_written = (encoder.buf.len() - bytes_before) as u32;
            let mut handles_written = (encoder.handles.len() - handles_before) as u32;
            // Back up and overwrite the `0s` for num_bytes and num_handles
            let after_offset = encoder.offset;
            encoder.offset = envelope_offset;
            bytes_written.encode(encoder)?;
            handles_written.encode(encoder)?;
            encoder.offset = after_offset;
        }
        None => ALLOC_ABSENT_U64.encode(encoder)?,
    }
    Ok(())
}
/// Encode the provided value behind a FIDL "envelope".
Encode the provided value behind a FIDL "envelope".
Encode the provided value behind a FIDL " envelope " .
pub fn encode_in_envelope(
    val: &mut Option<&mut dyn Encodable>,
    encoder: &mut Encoder<'_>,
) -> Result<()> {
    // u32 num_bytes
    // u32 num_handles
    // 64-bit presence indicator
    // Record the offset of the number of bytes handles in the envelope,
    // so that we can come back to it after writing the bytes and handles
    // (until which point we don't know how many handles will be written).
    let envelope_offset = encoder.offset;
    0u32.encode(encoder)?; // num_bytes
    0u32.encode(encoder)?; // num_handles
    match val {
        Some(x) => {
            ALLOC_PRESENT_U64.encode(encoder)?;
            let bytes_before = encoder.buf.len();
            let handles_before = encoder.handles.len();
            encoder.write_out_of_line(x.inline_size(encoder.context), |e| x.encode(e))?;
            let mut bytes_written = (encoder.buf.len() - bytes_before) as u32;
            let mut handles_written = (encoder.handles.len() - handles_before) as u32;
            // Back up and overwrite the `0s` for num_bytes and num_handles
            let after_offset = encoder.offset;
            encoder.offset = envelope_offset;
            bytes_written.encode(encoder)?;
            handles_written.encode(encoder)?;
            encoder.offset = after_offset;
        }
        None => ALLOC_ABSENT_U64.encode(encoder)?,
    }
    Ok(())
}
pub fn encode_in_envelope ( val : & mut Option < & mut dyn Encodable > , encoder : & mut Encoder < ' _ > , ) -> Result < ( ) > { // u32 num_bytes // u32 num_handles // 64-bit presence indicator // Record the offset of the number of bytes handles in the envelope, // so that we can come back to it after writing the bytes and handles // (until which point we don't know how many handles will be written). let envelope_offset = encoder . offset ; 0u32 . encode ( encoder ) ? ; // num_bytes 0u32 . encode ( encoder ) ? ; // num_handles match val { Some ( x ) => { ALLOC_PRESENT_U64 . encode ( encoder ) ? ; let bytes_before = encoder . buf . len ( ) ; let handles_before = encoder . handles . len ( ) ; encoder . write_out_of_line ( x . inline_size ( encoder . context ) , | e | x . encode ( e ) ) ? ; let mut bytes_written = ( encoder . buf . len ( ) - bytes_before ) as u32 ; let mut handles_written = ( encoder . handles . len ( ) - handles_before ) as u32 ; // Back up and overwrite the `0s` for num_bytes and num_handles let after_offset = encoder . offset ; encoder . offset = envelope_offset ; bytes_written . encode ( encoder ) ? ; handles_written . encode ( encoder ) ? ; encoder . offset = after_offset ; } None => ALLOC_ABSENT_U64 . encode ( encoder ) ? , } Ok ( ( ) ) }
Encode the provided value behind a FIDL "envelope".
Encode the provided value behind a FIDL " envelope " .
val
&mut Option<&mut dyn Encodable>
encoder
&mut Encoder<'_>
val
&mut Option<&mut dyn Encodable>
encoder
&mut Encoder<'_>