#![allow(clippy::all, missing_docs, unused_imports)]
use serde::{Deserialize, Serialize};
use super::*;
use crate::playwright::connection::{
Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidSocketInitializer {}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidSocketWriteParams {
#[serde(rename = "data")]
pub data: Binary,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct AndroidSocketDataEventParams {
#[serde(rename = "data")]
pub data: Binary,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AndroidSocketEvent {
Data(AndroidSocketDataEventParams),
Close,
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for AndroidSocketEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
"data" => Ok(Self::Data(serde_json::from_value(params)?)),
"close" => Ok(Self::Close),
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct AndroidSocket {
channel: Channel,
}
impl ChannelType for AndroidSocket {
const INTERFACE: &'static str = "AndroidSocket";
type Initializer = AndroidSocketInitializer;
type Event = AndroidSocketEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "AndroidSocket")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl AndroidSocket {
pub async fn write(&self, params: AndroidSocketWriteParams) -> Result<(), ProtocolError> {
self.channel.send_no_result("write", ¶ms).await
}
pub async fn close(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("close", &serde_json::json!({})).await
}
}