Skip to main content

browser_commander/playwright/protocol/
stream.rs

1// @generated by scripts/generate-playwright-protocol.mjs from
2// rust/protocol/playwright/*.yml. Do not edit by hand.
3
4#![allow(clippy::all, missing_docs, unused_imports)]
5
6use serde::{Deserialize, Serialize};
7
8use super::*;
9use crate::playwright::connection::{
10    Binary, Channel, ChannelType, ObjectRef, ProtocolError, ProtocolEvent, Ref,
11};
12
13/// Initializer the driver sends when it creates a `Stream`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct StreamInitializer {}
16
17/// Parameters of `Stream.read`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct StreamReadParams {
20    #[serde(rename = "size", default, skip_serializing_if = "Option::is_none")]
21    pub size: Option<i64>,
22}
23
24/// Result of `Stream.read`.
25#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct StreamReadResult {
27    #[serde(rename = "binary")]
28    pub binary: Binary,
29}
30
31/// Events a `Stream` channel can emit.
32#[derive(Debug, Clone, PartialEq)]
33pub enum StreamEvent {
34    /// An event this binding does not know (a newer driver).
35    Unknown {
36        /// Event name.
37        method: String,
38        /// Raw event parameters.
39        params: serde_json::Value,
40    },
41}
42
43impl ProtocolEvent for StreamEvent {
44    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
45        match method {
46            _ => Ok(Self::Unknown { method: method.to_string(), params }),
47        }
48    }
49}
50
51/// Channel for the `Stream` interface (`artifact.yml`).
52#[derive(Debug, Clone)]
53pub struct Stream {
54    channel: Channel,
55}
56
57impl ChannelType for Stream {
58    const INTERFACE: &'static str = "Stream";
59    type Initializer = StreamInitializer;
60    type Event = StreamEvent;
61
62    fn accepts(interface: &str) -> bool {
63        matches!(interface, "Stream")
64    }
65
66    fn from_channel(channel: Channel) -> Self {
67        Self { channel }
68    }
69
70    fn channel(&self) -> &Channel {
71        &self.channel
72    }
73}
74
75impl Stream {
76    /// `Stream.read` (internal).
77    pub async fn read(&self, params: StreamReadParams) -> Result<StreamReadResult, ProtocolError> {
78        self.channel.send("read", &params).await
79    }
80
81    /// `Stream.close` (internal).
82    pub async fn close(&self) -> Result<(), ProtocolError> {
83        self.channel.send_no_result("close", &serde_json::json!({})).await
84    }
85}