Skip to main content

browser_commander/playwright/protocol/
socks_support.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 `SocksSupport`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct SocksSupportInitializer {}
16
17/// Parameters of `SocksSupport.socksConnected`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct SocksSupportSocksConnectedParams {
20    #[serde(rename = "uid")]
21    pub uid: String,
22    #[serde(rename = "host")]
23    pub host: String,
24    #[serde(rename = "port")]
25    pub port: i64,
26}
27
28/// Parameters of `SocksSupport.socksFailed`.
29#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
30pub struct SocksSupportSocksFailedParams {
31    #[serde(rename = "uid")]
32    pub uid: String,
33    #[serde(rename = "errorCode")]
34    pub error_code: String,
35}
36
37/// Parameters of `SocksSupport.socksData`.
38#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
39pub struct SocksSupportSocksDataParams {
40    #[serde(rename = "uid")]
41    pub uid: String,
42    #[serde(rename = "data")]
43    pub data: Binary,
44}
45
46/// Parameters of `SocksSupport.socksError`.
47#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
48pub struct SocksSupportSocksErrorParams {
49    #[serde(rename = "uid")]
50    pub uid: String,
51    #[serde(rename = "error")]
52    pub error: String,
53}
54
55/// Parameters of `SocksSupport.socksEnd`.
56#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
57pub struct SocksSupportSocksEndParams {
58    #[serde(rename = "uid")]
59    pub uid: String,
60}
61
62/// Payload of the `SocksSupport.socksRequested` event.
63#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
64pub struct SocksSupportSocksRequestedEventParams {
65    #[serde(rename = "uid")]
66    pub uid: String,
67    #[serde(rename = "host")]
68    pub host: String,
69    #[serde(rename = "port")]
70    pub port: i64,
71}
72
73/// Payload of the `SocksSupport.socksData` event.
74#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
75pub struct SocksSupportSocksDataEventParams {
76    #[serde(rename = "uid")]
77    pub uid: String,
78    #[serde(rename = "data")]
79    pub data: Binary,
80}
81
82/// Payload of the `SocksSupport.socksClosed` event.
83#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
84pub struct SocksSupportSocksClosedEventParams {
85    #[serde(rename = "uid")]
86    pub uid: String,
87}
88
89/// Events a `SocksSupport` channel can emit.
90#[derive(Debug, Clone, PartialEq)]
91pub enum SocksSupportEvent {
92    /// `SocksSupport.socksRequested`
93    SocksRequested(SocksSupportSocksRequestedEventParams),
94    /// `SocksSupport.socksData`
95    SocksData(SocksSupportSocksDataEventParams),
96    /// `SocksSupport.socksClosed`
97    SocksClosed(SocksSupportSocksClosedEventParams),
98    /// An event this binding does not know (a newer driver).
99    Unknown {
100        /// Event name.
101        method: String,
102        /// Raw event parameters.
103        params: serde_json::Value,
104    },
105}
106
107impl ProtocolEvent for SocksSupportEvent {
108    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
109        match method {
110            "socksRequested" => Ok(Self::SocksRequested(serde_json::from_value(params)?)),
111            "socksData" => Ok(Self::SocksData(serde_json::from_value(params)?)),
112            "socksClosed" => Ok(Self::SocksClosed(serde_json::from_value(params)?)),
113            _ => Ok(Self::Unknown { method: method.to_string(), params }),
114        }
115    }
116}
117
118/// Channel for the `SocksSupport` interface (`playwright.yml`).
119#[derive(Debug, Clone)]
120pub struct SocksSupport {
121    channel: Channel,
122}
123
124impl ChannelType for SocksSupport {
125    const INTERFACE: &'static str = "SocksSupport";
126    type Initializer = SocksSupportInitializer;
127    type Event = SocksSupportEvent;
128
129    fn accepts(interface: &str) -> bool {
130        matches!(interface, "SocksSupport")
131    }
132
133    fn from_channel(channel: Channel) -> Self {
134        Self { channel }
135    }
136
137    fn channel(&self) -> &Channel {
138        &self.channel
139    }
140}
141
142impl SocksSupport {
143    /// `SocksSupport.socksConnected` (internal).
144    pub async fn socks_connected(&self, params: SocksSupportSocksConnectedParams) -> Result<(), ProtocolError> {
145        self.channel.send_no_result("socksConnected", &params).await
146    }
147
148    /// `SocksSupport.socksFailed` (internal).
149    pub async fn socks_failed(&self, params: SocksSupportSocksFailedParams) -> Result<(), ProtocolError> {
150        self.channel.send_no_result("socksFailed", &params).await
151    }
152
153    /// `SocksSupport.socksData` (internal).
154    pub async fn socks_data(&self, params: SocksSupportSocksDataParams) -> Result<(), ProtocolError> {
155        self.channel.send_no_result("socksData", &params).await
156    }
157
158    /// `SocksSupport.socksError` (internal).
159    pub async fn socks_error(&self, params: SocksSupportSocksErrorParams) -> Result<(), ProtocolError> {
160        self.channel.send_no_result("socksError", &params).await
161    }
162
163    /// `SocksSupport.socksEnd` (internal).
164    pub async fn socks_end(&self, params: SocksSupportSocksEndParams) -> Result<(), ProtocolError> {
165        self.channel.send_no_result("socksEnd", &params).await
166    }
167}