1 // This file contains generated code. Do not edit directly.
2 // To regenerate this, run 'make'.
3 
4 //! Bindings to the `GenericEvent` X11 extension.
5 
6 #![allow(clippy::too_many_arguments)]
7 
8 #[allow(unused_imports)]
9 use std::borrow::Cow;
10 use std::convert::TryFrom;
11 #[allow(unused_imports)]
12 use std::convert::TryInto;
13 use std::io::IoSlice;
14 #[allow(unused_imports)]
15 use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
16 #[allow(unused_imports)]
17 use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize};
18 use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection};
19 #[allow(unused_imports)]
20 use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
21 use crate::errors::{ConnectionError, ParseError};
22 
23 /// The X11 name of the extension for QueryExtension
24 pub const X11_EXTENSION_NAME: &str = "Generic Event Extension";
25 
26 /// The version number of this extension that this client library supports.
27 ///
28 /// This constant contains the version number of this extension that is supported
29 /// by this build of x11rb. For most things, it does not make sense to use this
30 /// information. If you need to send a `QueryVersion`, it is recommended to instead
31 /// send the maximum version of the extension that you need.
32 pub const X11_XML_VERSION: (u32, u32) = (1, 0);
33 
34 /// Opcode for the QueryVersion request
35 pub const QUERY_VERSION_REQUEST: u8 = 0;
36 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
37 pub struct QueryVersionRequest {
38     pub client_major_version: u16,
39     pub client_minor_version: u16,
40 }
41 impl QueryVersionRequest {
42     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,43     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
44     where
45         Conn: RequestConnection + ?Sized,
46     {
47         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
48             .ok_or(ConnectionError::UnsupportedExtension)?;
49         let length_so_far = 0;
50         let client_major_version_bytes = self.client_major_version.serialize();
51         let client_minor_version_bytes = self.client_minor_version.serialize();
52         let mut request0 = vec![
53             extension_information.major_opcode,
54             QUERY_VERSION_REQUEST,
55             0,
56             0,
57             client_major_version_bytes[0],
58             client_major_version_bytes[1],
59             client_minor_version_bytes[0],
60             client_minor_version_bytes[1],
61         ];
62         let length_so_far = length_so_far + request0.len();
63         assert_eq!(length_so_far % 4, 0);
64         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
65         request0[2..4].copy_from_slice(&length.to_ne_bytes());
66         Ok((vec![request0.into()], vec![]))
67     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,68     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
69     where
70         Conn: RequestConnection + ?Sized,
71     {
72         let (bytes, fds) = self.serialize(conn)?;
73         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
74         conn.send_request_with_reply(&slices, fds)
75     }
76     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>77     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
78         if header.minor_opcode != QUERY_VERSION_REQUEST {
79             return Err(ParseError::InvalidValue);
80         }
81         let (client_major_version, remaining) = u16::try_parse(value)?;
82         let (client_minor_version, remaining) = u16::try_parse(remaining)?;
83         let _ = remaining;
84         Ok(QueryVersionRequest {
85             client_major_version,
86             client_minor_version,
87         })
88     }
89 }
90 impl Request for QueryVersionRequest {
91     type Reply = QueryVersionReply;
92 }
query_version<Conn>(conn: &Conn, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,93 pub fn query_version<Conn>(conn: &Conn, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
94 where
95     Conn: RequestConnection + ?Sized,
96 {
97     let request0 = QueryVersionRequest {
98         client_major_version,
99         client_minor_version,
100     };
101     request0.send(conn)
102 }
103 
104 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
105 pub struct QueryVersionReply {
106     pub sequence: u16,
107     pub length: u32,
108     pub major_version: u16,
109     pub minor_version: u16,
110 }
111 impl TryParse for QueryVersionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>112     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
113         let remaining = initial_value;
114         let (response_type, remaining) = u8::try_parse(remaining)?;
115         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
116         let (sequence, remaining) = u16::try_parse(remaining)?;
117         let (length, remaining) = u32::try_parse(remaining)?;
118         let (major_version, remaining) = u16::try_parse(remaining)?;
119         let (minor_version, remaining) = u16::try_parse(remaining)?;
120         let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
121         if response_type != 1 {
122             return Err(ParseError::InvalidValue);
123         }
124         let result = QueryVersionReply { sequence, length, major_version, minor_version };
125         let _ = remaining;
126         let remaining = initial_value.get(32 + length as usize * 4..)
127             .ok_or(ParseError::InsufficientData)?;
128         Ok((result, remaining))
129     }
130 }
131 
132 /// Extension trait defining the requests of this extension.
133 pub trait ConnectionExt: RequestConnection {
ge_query_version(&self, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>134     fn ge_query_version(&self, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>
135     {
136         query_version(self, client_major_version, client_minor_version)
137     }
138 }
139 
140 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
141