parent
36fb89b956
commit
5d7c23124c
1 changed files with 15 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::io::Read;
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
use crate::error::FF2MpvError;
|
use crate::error::FF2MpvError;
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@ pub struct FF2MpvMessage {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_reply() -> Result<(), io::Error> {
|
||||||
|
send_message("ok")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_mpv_message() -> Result<FF2MpvMessage, FF2MpvError> {
|
pub fn get_mpv_message() -> Result<FF2MpvMessage, FF2MpvError> {
|
||||||
let message = read_message()?;
|
let message = read_message()?;
|
||||||
let ff2mpv_message = serde_json::from_str(&message)?;
|
let ff2mpv_message = serde_json::from_str(&message)?;
|
||||||
|
@ -28,3 +32,13 @@ fn read_message() -> Result<String, io::Error> {
|
||||||
reader.read_to_string(&mut string)?;
|
reader.read_to_string(&mut string)?;
|
||||||
Ok(string)
|
Ok(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn send_message(message: &str) -> Result<(), io::Error> {
|
||||||
|
let length = (message.len() as u32).to_ne_bytes();
|
||||||
|
let message = message.as_bytes();
|
||||||
|
|
||||||
|
let mut stdout = io::stdout();
|
||||||
|
stdout.write_all(&length)?;
|
||||||
|
stdout.write_all(message)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue