| |
| |
| |
| |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| pub enum BexEventKind { |
| InstallResult, |
| UninstallResult, |
| HomeResult, |
| CategoryResult, |
| SearchResult, |
| InfoResult, |
| ServersResult, |
| StreamResult, |
| SubtitleSearchResult, |
| SubtitleDownloadResult, |
| ArticleResult, |
| Log, |
| Progress, |
| Error, |
| Cancelled, |
| } |
|
|
| impl BexEventKind { |
| |
| |
| pub fn to_tag(self) -> u8 { |
| match self { |
| Self::InstallResult => 0, |
| Self::UninstallResult => 1, |
| Self::HomeResult => 2, |
| Self::CategoryResult => 3, |
| Self::SearchResult => 4, |
| Self::InfoResult => 5, |
| Self::ServersResult => 6, |
| Self::StreamResult => 7, |
| Self::SubtitleSearchResult => 8, |
| Self::SubtitleDownloadResult => 9, |
| Self::ArticleResult => 10, |
| Self::Log => 11, |
| Self::Progress => 12, |
| Self::Error => 13, |
| Self::Cancelled => 14, |
| } |
| } |
| } |
|
|
| |
| |
| |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| pub enum BexPayloadFormat { |
| |
| None, |
| |
| FlatBuffer, |
| |
| JsonDebug, |
| |
| Binary, |
| } |
|
|
| |
| |
| |
| |
| #[derive(Debug, Clone)] |
| pub struct BexEvent { |
| |
| pub request_id: u64, |
| |
| pub seq: u64, |
| |
| pub kind: BexEventKind, |
| |
| pub ok: bool, |
| |
| pub plugin_id: String, |
| |
| pub payload_format: BexPayloadFormat, |
| |
| pub payload: Vec<u8>, |
| |
| pub error_code: String, |
| |
| pub error_message: String, |
| } |
|
|
| impl BexEvent { |
| |
| pub fn success( |
| request_id: u64, |
| seq: u64, |
| kind: BexEventKind, |
| plugin_id: String, |
| payload: Vec<u8>, |
| ) -> Self { |
| Self { |
| request_id, |
| seq, |
| kind, |
| ok: true, |
| plugin_id, |
| payload_format: BexPayloadFormat::FlatBuffer, |
| payload, |
| error_code: String::new(), |
| error_message: String::new(), |
| } |
| } |
|
|
| |
| pub fn success_json( |
| request_id: u64, |
| seq: u64, |
| kind: BexEventKind, |
| plugin_id: String, |
| json: String, |
| ) -> Self { |
| Self { |
| request_id, |
| seq, |
| kind, |
| ok: true, |
| plugin_id, |
| payload_format: BexPayloadFormat::JsonDebug, |
| payload: json.into_bytes(), |
| error_code: String::new(), |
| error_message: String::new(), |
| } |
| } |
|
|
| |
| pub fn error( |
| request_id: u64, |
| seq: u64, |
| kind: BexEventKind, |
| plugin_id: String, |
| error_code: &str, |
| error_message: &str, |
| ) -> Self { |
| Self { |
| request_id, |
| seq, |
| kind, |
| ok: false, |
| plugin_id, |
| payload_format: BexPayloadFormat::None, |
| payload: Vec::new(), |
| error_code: error_code.to_string(), |
| error_message: error_message.to_string(), |
| } |
| } |
|
|
| |
| pub fn cancelled(request_id: u64, seq: u64, plugin_id: String) -> Self { |
| Self { |
| request_id, |
| seq, |
| kind: BexEventKind::Cancelled, |
| ok: false, |
| plugin_id, |
| payload_format: BexPayloadFormat::None, |
| payload: Vec::new(), |
| error_code: "CANCELLED".to_string(), |
| error_message: "Request was cancelled".to_string(), |
| } |
| } |
| } |
|
|