#![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 StreamInitializer {}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StreamReadParams {
#[serde(rename = "size", default, skip_serializing_if = "Option::is_none")]
pub size: Option<i64>,
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct StreamReadResult {
#[serde(rename = "binary")]
pub binary: Binary,
}
#[derive(Debug, Clone, PartialEq)]
pub enum StreamEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for StreamEvent {
fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
match method {
_ => Ok(Self::Unknown { method: method.to_string(), params }),
}
}
}
#[derive(Debug, Clone)]
pub struct Stream {
channel: Channel,
}
impl ChannelType for Stream {
const INTERFACE: &'static str = "Stream";
type Initializer = StreamInitializer;
type Event = StreamEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "Stream")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl Stream {
pub async fn read(&self, params: StreamReadParams) -> Result<StreamReadResult, ProtocolError> {
self.channel.send("read", ¶ms).await
}
pub async fn close(&self) -> Result<(), ProtocolError> {
self.channel.send_no_result("close", &serde_json::json!({})).await
}
}