fn encode_message(msg_type: ClipboardPDUType, payload: Vec<u8>) -> RdpResult<Vec<u8>> {
    let msg_flags = match msg_type {
        // the spec requires 0 for these messages
        ClipboardPDUType::CB_CLIP_CAPS => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_TEMP_DIRECTORY => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_LOCK_CLIPDATA => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_UNLOCK_CLIPDATA => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_FORMAT_DATA_REQUEST => ClipboardHeaderFlags::from_bits_truncate(0),

        // assume success for now
        ClipboardPDUType::CB_FORMAT_DATA_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_OK,
        ClipboardPDUType::CB_FORMAT_LIST_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_OK,

        // we don't advertise support for file transfers, so the server should never send this,
        // but if it does, ensure the response indicates a failure
        ClipboardPDUType::CB_FILECONTENTS_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_FAIL,

        _ => ClipboardHeaderFlags::from_bits_truncate(0),
    };

    let mut inner = ClipboardPDUHeader::new(msg_type, msg_flags, payload.len() as u32).encode()?;
    inner.extend_from_slice(&payload);

    let mut channel_flags = vchan::ChannelPDUFlags::CHANNEL_FLAG_ONLY;
    match msg_type {
        ClipboardPDUType::CB_FORMAT_LIST
        | ClipboardPDUType::CB_CLIP_CAPS
        | ClipboardPDUType::CB_FORMAT_DATA_REQUEST
        | ClipboardPDUType::CB_FORMAT_DATA_RESPONSE => {
            channel_flags.set(vchan::ChannelPDUFlags::CHANNEL_FLAG_SHOW_PROTOCOL, true)
        }
        _ => {}
    }

    let mut outer = vchan::ChannelPDUHeader::new(inner.length() as u32, channel_flags).encode()?;
    outer.extend_from_slice(&inner);
    Ok(outer)
}
/// encode_message encodes a message by wrapping it in the appropriate
/// channel header
encode_message encodes a message by wrapping it in the appropriate
channel header
encode_message encodes a message by wrapping it in the appropriate channel header
fn encode_message(msg_type: ClipboardPDUType, payload: Vec<u8>) -> RdpResult<Vec<u8>> {
    let msg_flags = match msg_type {
        // the spec requires 0 for these messages
        ClipboardPDUType::CB_CLIP_CAPS => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_TEMP_DIRECTORY => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_LOCK_CLIPDATA => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_UNLOCK_CLIPDATA => ClipboardHeaderFlags::from_bits_truncate(0),
        ClipboardPDUType::CB_FORMAT_DATA_REQUEST => ClipboardHeaderFlags::from_bits_truncate(0),
        // assume success for now
        ClipboardPDUType::CB_FORMAT_DATA_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_OK,
        ClipboardPDUType::CB_FORMAT_LIST_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_OK,
        // we don't advertise support for file transfers, so the server should never send this,
        // but if it does, ensure the response indicates a failure
        ClipboardPDUType::CB_FILECONTENTS_RESPONSE => ClipboardHeaderFlags::CB_RESPONSE_FAIL,
        _ => ClipboardHeaderFlags::from_bits_truncate(0),
    };
    let mut inner = ClipboardPDUHeader::new(msg_type, msg_flags, payload.len() as u32).encode()?;
    inner.extend_from_slice(&payload);
    let mut channel_flags = vchan::ChannelPDUFlags::CHANNEL_FLAG_ONLY;
    match msg_type {
        ClipboardPDUType::CB_FORMAT_LIST
        | ClipboardPDUType::CB_CLIP_CAPS
        | ClipboardPDUType::CB_FORMAT_DATA_REQUEST
        | ClipboardPDUType::CB_FORMAT_DATA_RESPONSE => {
            channel_flags.set(vchan::ChannelPDUFlags::CHANNEL_FLAG_SHOW_PROTOCOL, true)
        }
        _ => {}
    }
    let mut outer = vchan::ChannelPDUHeader::new(inner.length() as u32, channel_flags).encode()?;
    outer.extend_from_slice(&inner);
    Ok(outer)
}
fn encode_message ( msg_type : ClipboardPDUType , payload : Vec < u8 > ) -> RdpResult < Vec < u8 > > { let msg_flags = match msg_type { // the spec requires 0 for these messages ClipboardPDUType :: CB_CLIP_CAPS => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , ClipboardPDUType :: CB_TEMP_DIRECTORY => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , ClipboardPDUType :: CB_LOCK_CLIPDATA => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , ClipboardPDUType :: CB_UNLOCK_CLIPDATA => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , ClipboardPDUType :: CB_FORMAT_DATA_REQUEST => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , // assume success for now ClipboardPDUType :: CB_FORMAT_DATA_RESPONSE => ClipboardHeaderFlags :: CB_RESPONSE_OK , ClipboardPDUType :: CB_FORMAT_LIST_RESPONSE => ClipboardHeaderFlags :: CB_RESPONSE_OK , // we don't advertise support for file transfers, so the server should never send this, // but if it does, ensure the response indicates a failure ClipboardPDUType :: CB_FILECONTENTS_RESPONSE => ClipboardHeaderFlags :: CB_RESPONSE_FAIL , _ => ClipboardHeaderFlags :: from_bits_truncate ( 0 ) , } ; let mut inner = ClipboardPDUHeader :: new ( msg_type , msg_flags , payload . len ( ) as u32 ) . encode ( ) ? ; inner . extend_from_slice ( & payload ) ; let mut channel_flags = vchan :: ChannelPDUFlags :: CHANNEL_FLAG_ONLY ; match msg_type { ClipboardPDUType :: CB_FORMAT_LIST | ClipboardPDUType :: CB_CLIP_CAPS | ClipboardPDUType :: CB_FORMAT_DATA_REQUEST | ClipboardPDUType :: CB_FORMAT_DATA_RESPONSE => { channel_flags . set ( vchan :: ChannelPDUFlags :: CHANNEL_FLAG_SHOW_PROTOCOL , true ) } _ => { } } let mut outer = vchan :: ChannelPDUHeader :: new ( inner . length ( ) as u32 , channel_flags ) . encode ( ) ? ; outer . extend_from_slice ( & inner ) ; Ok ( outer ) }
encode_message encodes a message by wrapping it in the appropriate
channel header
encode_message encodes a message by wrapping it in the appropriate channel header
msg_type
ClipboardPDUType
payload
Vec<u8>
msg_type
ClipboardPDUType
payload
Vec<u8>