mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-12-15 20:19:05 +08:00
adf4f3eea4
Signed-off-by: fufesou <shuanglongchen@yeah.net>
168 lines
6.0 KiB
Rust
168 lines
6.0 KiB
Rust
use clipboard::ClipbaordFile;
|
|
use hbb_common::message_proto::*;
|
|
|
|
pub fn clip_2_msg(clip: ClipbaordFile) -> Message {
|
|
match clip {
|
|
ClipbaordFile::MonitorReady => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::Ready(CliprdrMonitorReady {
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
ClipbaordFile::FormatList { format_list } => {
|
|
let mut formats: Vec<CliprdrFormat> = Vec::new();
|
|
for v in format_list.iter() {
|
|
formats.push(CliprdrFormat {
|
|
id: v.0,
|
|
format: v.1.clone(),
|
|
..Default::default()
|
|
});
|
|
}
|
|
Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FormatList(CliprdrServerFormatList {
|
|
formats,
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
}
|
|
}
|
|
ClipbaordFile::FormatListResponse { msg_flags } => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FormatListResponse(
|
|
CliprdrServerFormatListResponse {
|
|
msg_flags,
|
|
..Default::default()
|
|
},
|
|
)),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
ClipbaordFile::FormatDataRequest {
|
|
requested_format_id,
|
|
} => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FormatDataRequest(
|
|
CliprdrServerFormatDataRequest {
|
|
requested_format_id,
|
|
..Default::default()
|
|
},
|
|
)),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
ClipbaordFile::FormatDataResponse {
|
|
msg_flags,
|
|
format_data,
|
|
} => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FormatDataResponse(
|
|
CliprdrServerFormatDataResponse {
|
|
msg_flags,
|
|
format_data: format_data.into(),
|
|
..Default::default()
|
|
},
|
|
)),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
ClipbaordFile::FileContentsRequest {
|
|
stream_id,
|
|
list_index,
|
|
dw_flags,
|
|
n_position_low,
|
|
n_position_high,
|
|
cb_requested,
|
|
have_clip_data_id,
|
|
clip_data_id,
|
|
} => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FileContentsRequest(
|
|
CliprdrFileContentsRequest {
|
|
stream_id,
|
|
list_index,
|
|
dw_flags,
|
|
n_position_low,
|
|
n_position_high,
|
|
cb_requested,
|
|
have_clip_data_id,
|
|
clip_data_id,
|
|
..Default::default()
|
|
},
|
|
)),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
ClipbaordFile::FileContentsResponse {
|
|
msg_flags,
|
|
stream_id,
|
|
requested_data,
|
|
} => Message {
|
|
union: Some(message::Union::Cliprdr(Cliprdr {
|
|
union: Some(cliprdr::Union::FileContentsResponse(
|
|
CliprdrFileContentsResponse {
|
|
msg_flags,
|
|
stream_id,
|
|
requested_data: requested_data.into(),
|
|
..Default::default()
|
|
},
|
|
)),
|
|
..Default::default()
|
|
})),
|
|
..Default::default()
|
|
},
|
|
}
|
|
}
|
|
|
|
pub fn msg_2_clip(msg: Cliprdr) -> Option<ClipbaordFile> {
|
|
match msg.union {
|
|
Some(cliprdr::Union::Ready(_)) => Some(ClipbaordFile::MonitorReady),
|
|
Some(cliprdr::Union::FormatList(data)) => {
|
|
let mut format_list: Vec<(i32, String)> = Vec::new();
|
|
for v in data.formats.iter() {
|
|
format_list.push((v.id, v.format.clone()));
|
|
}
|
|
Some(ClipbaordFile::FormatList { format_list })
|
|
}
|
|
Some(cliprdr::Union::FormatListResponse(data)) => Some(ClipbaordFile::FormatListResponse {
|
|
msg_flags: data.msg_flags,
|
|
}),
|
|
Some(cliprdr::Union::FormatDataRequest(data)) => Some(ClipbaordFile::FormatDataRequest {
|
|
requested_format_id: data.requested_format_id,
|
|
}),
|
|
Some(cliprdr::Union::FormatDataResponse(data)) => Some(ClipbaordFile::FormatDataResponse {
|
|
msg_flags: data.msg_flags,
|
|
format_data: data.format_data.into(),
|
|
}),
|
|
Some(cliprdr::Union::FileContentsRequest(data)) => {
|
|
Some(ClipbaordFile::FileContentsRequest {
|
|
stream_id: data.stream_id,
|
|
list_index: data.list_index,
|
|
dw_flags: data.dw_flags,
|
|
n_position_low: data.n_position_low,
|
|
n_position_high: data.n_position_high,
|
|
cb_requested: data.cb_requested,
|
|
have_clip_data_id: data.have_clip_data_id,
|
|
clip_data_id: data.clip_data_id,
|
|
})
|
|
}
|
|
Some(cliprdr::Union::FileContentsResponse(data)) => {
|
|
Some(ClipbaordFile::FileContentsResponse {
|
|
msg_flags: data.msg_flags,
|
|
stream_id: data.stream_id,
|
|
requested_data: data.requested_data.into(),
|
|
})
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|