event_parser: make id
optional
This commit is contained in:
parent
00cae63272
commit
e3297bef15
@ -109,7 +109,7 @@ pub enum Event {
|
|||||||
VideoReconfig,
|
VideoReconfig,
|
||||||
AudioReconfig,
|
AudioReconfig,
|
||||||
PropertyChange {
|
PropertyChange {
|
||||||
id: u64,
|
id: Option<u64>,
|
||||||
name: String,
|
name: String,
|
||||||
data: Option<MpvDataType>,
|
data: Option<MpvDataType>,
|
||||||
},
|
},
|
||||||
@ -296,7 +296,7 @@ fn parse_client_message(event: &Map<String, Value>) -> Result<Event, MpvError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_property_change(event: &Map<String, Value>) -> Result<Event, MpvError> {
|
fn parse_property_change(event: &Map<String, Value>) -> Result<Event, MpvError> {
|
||||||
let id = get_key_as!(as_u64, "id", event);
|
let id = get_optional_key_as!(as_u64, "id", event);
|
||||||
let property_name = get_key_as!(as_str, "name", event);
|
let property_name = get_key_as!(as_str, "name", event);
|
||||||
let data = event.get("data").map(json_to_value).transpose()?;
|
let data = event.get("data").map(json_to_value).transpose()?;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ where
|
|||||||
match event {
|
match event {
|
||||||
Some(Ok(event)) => {
|
Some(Ok(event)) => {
|
||||||
match event {
|
match event {
|
||||||
Event::PropertyChange { id: MPV_CHANNEL_ID, name, data } => {
|
Event::PropertyChange { id: Some(MPV_CHANNEL_ID), name, data } => {
|
||||||
let property = parse_property(&name, data).unwrap();
|
let property = parse_property(&name, data).unwrap();
|
||||||
if !on_property(property.clone()) {
|
if !on_property(property.clone()) {
|
||||||
return Err(PropertyCheckingThreadError::UnexpectedPropertyError(property))
|
return Err(PropertyCheckingThreadError::UnexpectedPropertyError(property))
|
||||||
|
@ -52,7 +52,7 @@ async fn test_observe_event_successful() {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
event,
|
event,
|
||||||
Event::PropertyChange {
|
Event::PropertyChange {
|
||||||
id: 1,
|
id: Some(1),
|
||||||
name: "volume".to_string(),
|
name: "volume".to_string(),
|
||||||
data: Some(MpvDataType::Double(64.0))
|
data: Some(MpvDataType::Double(64.0))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user