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 | // The code generator is simpler if it can always use conversions |
8 | #![allow (clippy::useless_conversion)] |
9 | |
10 | #[allow (unused_imports)] |
11 | use alloc::borrow::Cow; |
12 | #[allow (unused_imports)] |
13 | use core::convert::TryInto; |
14 | use alloc::vec; |
15 | use alloc::vec::Vec; |
16 | use core::convert::TryFrom; |
17 | use crate::errors::ParseError; |
18 | #[allow (unused_imports)] |
19 | use crate::x11_utils::TryIntoUSize; |
20 | use crate::BufWithFds; |
21 | #[allow (unused_imports)] |
22 | use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum}; |
23 | #[allow (unused_imports)] |
24 | use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd}; |
25 | |
26 | /// The X11 name of the extension for QueryExtension |
27 | pub const X11_EXTENSION_NAME: &str = "Generic Event Extension" ; |
28 | |
29 | /// The version number of this extension that this client library supports. |
30 | /// |
31 | /// This constant contains the version number of this extension that is supported |
32 | /// by this build of x11rb. For most things, it does not make sense to use this |
33 | /// information. If you need to send a `QueryVersion`, it is recommended to instead |
34 | /// send the maximum version of the extension that you need. |
35 | pub const X11_XML_VERSION: (u32, u32) = (1, 0); |
36 | |
37 | /// Opcode for the QueryVersion request |
38 | pub const QUERY_VERSION_REQUEST: u8 = 0; |
39 | #[derive (Clone, Copy, Default)] |
40 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
41 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
42 | pub struct QueryVersionRequest { |
43 | pub client_major_version: u16, |
44 | pub client_minor_version: u16, |
45 | } |
46 | impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest" ); |
47 | impl QueryVersionRequest { |
48 | /// Serialize this request into bytes for the provided connection |
49 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> { |
50 | let length_so_far = 0; |
51 | let client_major_version_bytes = self.client_major_version.serialize(); |
52 | let client_minor_version_bytes = self.client_minor_version.serialize(); |
53 | let mut request0 = vec![ |
54 | major_opcode, |
55 | QUERY_VERSION_REQUEST, |
56 | 0, |
57 | 0, |
58 | client_major_version_bytes[0], |
59 | client_major_version_bytes[1], |
60 | client_minor_version_bytes[0], |
61 | client_minor_version_bytes[1], |
62 | ]; |
63 | let length_so_far = length_so_far + request0.len(); |
64 | assert_eq!(length_so_far % 4, 0); |
65 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
66 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
67 | ([request0.into()], vec![]) |
68 | } |
69 | /// Parse this request given its header, its body, and any fds that go along with it |
70 | #[cfg (feature = "request-parsing" )] |
71 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
72 | if header.minor_opcode != QUERY_VERSION_REQUEST { |
73 | return Err(ParseError::InvalidValue); |
74 | } |
75 | let (client_major_version, remaining) = u16::try_parse(value)?; |
76 | let (client_minor_version, remaining) = u16::try_parse(remaining)?; |
77 | let _ = remaining; |
78 | Ok(QueryVersionRequest { |
79 | client_major_version, |
80 | client_minor_version, |
81 | }) |
82 | } |
83 | } |
84 | impl Request for QueryVersionRequest { |
85 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
86 | |
87 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
88 | let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode); |
89 | // Flatten the buffers into a single vector |
90 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
91 | (buf, fds) |
92 | } |
93 | } |
94 | impl crate::x11_utils::ReplyRequest for QueryVersionRequest { |
95 | type Reply = QueryVersionReply; |
96 | } |
97 | |
98 | #[derive (Clone, Copy, Default)] |
99 | #[cfg_attr (feature = "extra-traits" , derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))] |
100 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
101 | pub struct QueryVersionReply { |
102 | pub sequence: u16, |
103 | pub length: u32, |
104 | pub major_version: u16, |
105 | pub minor_version: u16, |
106 | } |
107 | impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply" ); |
108 | impl TryParse for QueryVersionReply { |
109 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
110 | let remaining: &[u8] = initial_value; |
111 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
112 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
113 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
114 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
115 | let (major_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
116 | let (minor_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
117 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
118 | if response_type != 1 { |
119 | return Err(ParseError::InvalidValue); |
120 | } |
121 | let result: QueryVersionReply = QueryVersionReply { sequence, length, major_version, minor_version }; |
122 | let _ = remaining; |
123 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
124 | .ok_or(err:ParseError::InsufficientData)?; |
125 | Ok((result, remaining)) |
126 | } |
127 | } |
128 | impl Serialize for QueryVersionReply { |
129 | type Bytes = [u8; 32]; |
130 | fn serialize(&self) -> [u8; 32] { |
131 | let response_type_bytes = &[1]; |
132 | let sequence_bytes = self.sequence.serialize(); |
133 | let length_bytes = self.length.serialize(); |
134 | let major_version_bytes = self.major_version.serialize(); |
135 | let minor_version_bytes = self.minor_version.serialize(); |
136 | [ |
137 | response_type_bytes[0], |
138 | 0, |
139 | sequence_bytes[0], |
140 | sequence_bytes[1], |
141 | length_bytes[0], |
142 | length_bytes[1], |
143 | length_bytes[2], |
144 | length_bytes[3], |
145 | major_version_bytes[0], |
146 | major_version_bytes[1], |
147 | minor_version_bytes[0], |
148 | minor_version_bytes[1], |
149 | 0, |
150 | 0, |
151 | 0, |
152 | 0, |
153 | 0, |
154 | 0, |
155 | 0, |
156 | 0, |
157 | 0, |
158 | 0, |
159 | 0, |
160 | 0, |
161 | 0, |
162 | 0, |
163 | 0, |
164 | 0, |
165 | 0, |
166 | 0, |
167 | 0, |
168 | 0, |
169 | ] |
170 | } |
171 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
172 | bytes.reserve(32); |
173 | let response_type_bytes = &[1]; |
174 | bytes.push(response_type_bytes[0]); |
175 | bytes.extend_from_slice(&[0; 1]); |
176 | self.sequence.serialize_into(bytes); |
177 | self.length.serialize_into(bytes); |
178 | self.major_version.serialize_into(bytes); |
179 | self.minor_version.serialize_into(bytes); |
180 | bytes.extend_from_slice(&[0; 20]); |
181 | } |
182 | } |
183 | |
184 | |