#![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 WritableStreamInitializer {}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct WritableStreamWriteParams {
#[serde(rename = "binary")]
pub binary: Binary,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WritableStreamEvent {
Unknown {
method: String,
params: serde_json::Value,
},
}
impl ProtocolEvent for WritableStreamEvent {
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 WritableStream {
channel: Channel,
}
impl ChannelType for WritableStream {
const INTERFACE: &'static str = "WritableStream";
type Initializer = WritableStreamInitializer;
type Event = WritableStreamEvent;
fn accepts(interface: &str) -> bool {
matches!(interface, "WritableStream")
}
fn from_channel(channel: Channel) -> Self {
Self { channel }
}
fn channel(&self) -> &Channel {
&self.channel
}
}
impl WritableStream {
pub async fn write(&self, params: WritableStreamWriteParams) -> 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
}
}