Skip to main content

browser_commander/playwright/protocol/
android_socket.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 `AndroidSocket`.
14#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
15pub struct AndroidSocketInitializer {}
16
17/// Parameters of `AndroidSocket.write`.
18#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
19pub struct AndroidSocketWriteParams {
20    #[serde(rename = "data")]
21    pub data: Binary,
22}
23
24/// Payload of the `AndroidSocket.data` event.
25#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
26pub struct AndroidSocketDataEventParams {
27    #[serde(rename = "data")]
28    pub data: Binary,
29}
30
31/// Events a `AndroidSocket` channel can emit.
32#[derive(Debug, Clone, PartialEq)]
33pub enum AndroidSocketEvent {
34    /// `AndroidSocket.data`
35    Data(AndroidSocketDataEventParams),
36    /// `AndroidSocket.close`
37    Close,
38    /// An event this binding does not know (a newer driver).
39    Unknown {
40        /// Event name.
41        method: String,
42        /// Raw event parameters.
43        params: serde_json::Value,
44    },
45}
46
47impl ProtocolEvent for AndroidSocketEvent {
48    fn parse(method: &str, params: serde_json::Value) -> Result<Self, serde_json::Error> {
49        match method {
50            "data" => Ok(Self::Data(serde_json::from_value(params)?)),
51            "close" => Ok(Self::Close),
52            _ => Ok(Self::Unknown { method: method.to_string(), params }),
53        }
54    }
55}
56
57/// Channel for the `AndroidSocket` interface (`android.yml`).
58#[derive(Debug, Clone)]
59pub struct AndroidSocket {
60    channel: Channel,
61}
62
63impl ChannelType for AndroidSocket {
64    const INTERFACE: &'static str = "AndroidSocket";
65    type Initializer = AndroidSocketInitializer;
66    type Event = AndroidSocketEvent;
67
68    fn accepts(interface: &str) -> bool {
69        matches!(interface, "AndroidSocket")
70    }
71
72    fn from_channel(channel: Channel) -> Self {
73        Self { channel }
74    }
75
76    fn channel(&self) -> &Channel {
77        &self.channel
78    }
79}
80
81impl AndroidSocket {
82    /// `AndroidSocket.write` (internal).
83    pub async fn write(&self, params: AndroidSocketWriteParams) -> Result<(), ProtocolError> {
84        self.channel.send_no_result("write", &params).await
85    }
86
87    /// `AndroidSocket.close` (internal).
88    pub async fn close(&self) -> Result<(), ProtocolError> {
89        self.channel.send_no_result("close", &serde_json::json!({})).await
90    }
91}