1 | // This file contains generated code. Do not edit directly. |
2 | // To regenerate this, run 'make'. |
3 | |
4 | //! Bindings to the `XCMisc` 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, PiecewiseBuf}; |
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 = "XC-MISC" ; |
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, 1); |
36 | |
37 | /// Opcode for the GetVersion request |
38 | pub const GET_VERSION_REQUEST: u8 = 0; |
39 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
40 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
41 | pub struct GetVersionRequest { |
42 | pub client_major_version: u16, |
43 | pub client_minor_version: u16, |
44 | } |
45 | impl GetVersionRequest { |
46 | /// Serialize this request into bytes for the provided connection |
47 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>> { |
48 | let length_so_far = 0; |
49 | let client_major_version_bytes = self.client_major_version.serialize(); |
50 | let client_minor_version_bytes = self.client_minor_version.serialize(); |
51 | let mut request0 = vec![ |
52 | major_opcode, |
53 | GET_VERSION_REQUEST, |
54 | 0, |
55 | 0, |
56 | client_major_version_bytes[0], |
57 | client_major_version_bytes[1], |
58 | client_minor_version_bytes[0], |
59 | client_minor_version_bytes[1], |
60 | ]; |
61 | let length_so_far = length_so_far + request0.len(); |
62 | assert_eq!(length_so_far % 4, 0); |
63 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
64 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
65 | (vec![request0.into()], vec![]) |
66 | } |
67 | /// Parse this request given its header, its body, and any fds that go along with it |
68 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
69 | if header.minor_opcode != GET_VERSION_REQUEST { |
70 | return Err(ParseError::InvalidValue); |
71 | } |
72 | let (client_major_version, remaining) = u16::try_parse(value)?; |
73 | let (client_minor_version, remaining) = u16::try_parse(remaining)?; |
74 | let _ = remaining; |
75 | Ok(GetVersionRequest { |
76 | client_major_version, |
77 | client_minor_version, |
78 | }) |
79 | } |
80 | } |
81 | impl Request for GetVersionRequest { |
82 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
83 | |
84 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
85 | let (bufs: Vec>, fds: Vec) = self.serialize(major_opcode); |
86 | // Flatten the buffers into a single vector |
87 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
88 | (buf, fds) |
89 | } |
90 | } |
91 | impl crate::x11_utils::ReplyRequest for GetVersionRequest { |
92 | type Reply = GetVersionReply; |
93 | } |
94 | |
95 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
96 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
97 | pub struct GetVersionReply { |
98 | pub sequence: u16, |
99 | pub length: u32, |
100 | pub server_major_version: u16, |
101 | pub server_minor_version: u16, |
102 | } |
103 | impl TryParse for GetVersionReply { |
104 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
105 | let remaining: &[u8] = initial_value; |
106 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
107 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
108 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
109 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
110 | let (server_major_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
111 | let (server_minor_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
112 | if response_type != 1 { |
113 | return Err(ParseError::InvalidValue); |
114 | } |
115 | let result: GetVersionReply = GetVersionReply { sequence, length, server_major_version, server_minor_version }; |
116 | let _ = remaining; |
117 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
118 | .ok_or(err:ParseError::InsufficientData)?; |
119 | Ok((result, remaining)) |
120 | } |
121 | } |
122 | impl Serialize for GetVersionReply { |
123 | type Bytes = [u8; 12]; |
124 | fn serialize(&self) -> [u8; 12] { |
125 | let response_type_bytes = &[1]; |
126 | let sequence_bytes = self.sequence.serialize(); |
127 | let length_bytes = self.length.serialize(); |
128 | let server_major_version_bytes = self.server_major_version.serialize(); |
129 | let server_minor_version_bytes = self.server_minor_version.serialize(); |
130 | [ |
131 | response_type_bytes[0], |
132 | 0, |
133 | sequence_bytes[0], |
134 | sequence_bytes[1], |
135 | length_bytes[0], |
136 | length_bytes[1], |
137 | length_bytes[2], |
138 | length_bytes[3], |
139 | server_major_version_bytes[0], |
140 | server_major_version_bytes[1], |
141 | server_minor_version_bytes[0], |
142 | server_minor_version_bytes[1], |
143 | ] |
144 | } |
145 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
146 | bytes.reserve(12); |
147 | let response_type_bytes = &[1]; |
148 | bytes.push(response_type_bytes[0]); |
149 | bytes.extend_from_slice(&[0; 1]); |
150 | self.sequence.serialize_into(bytes); |
151 | self.length.serialize_into(bytes); |
152 | self.server_major_version.serialize_into(bytes); |
153 | self.server_minor_version.serialize_into(bytes); |
154 | } |
155 | } |
156 | |
157 | /// Opcode for the GetXIDRange request |
158 | pub const GET_XID_RANGE_REQUEST: u8 = 1; |
159 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
160 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
161 | pub struct GetXIDRangeRequest; |
162 | impl GetXIDRangeRequest { |
163 | /// Serialize this request into bytes for the provided connection |
164 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>> { |
165 | let length_so_far = 0; |
166 | let mut request0 = vec![ |
167 | major_opcode, |
168 | GET_XID_RANGE_REQUEST, |
169 | 0, |
170 | 0, |
171 | ]; |
172 | let length_so_far = length_so_far + request0.len(); |
173 | assert_eq!(length_so_far % 4, 0); |
174 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
175 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
176 | (vec![request0.into()], vec![]) |
177 | } |
178 | /// Parse this request given its header, its body, and any fds that go along with it |
179 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
180 | if header.minor_opcode != GET_XID_RANGE_REQUEST { |
181 | return Err(ParseError::InvalidValue); |
182 | } |
183 | let _ = value; |
184 | Ok(GetXIDRangeRequest |
185 | ) |
186 | } |
187 | } |
188 | impl Request for GetXIDRangeRequest { |
189 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
190 | |
191 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
192 | let (bufs: Vec>, fds: Vec) = self.serialize(major_opcode); |
193 | // Flatten the buffers into a single vector |
194 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
195 | (buf, fds) |
196 | } |
197 | } |
198 | impl crate::x11_utils::ReplyRequest for GetXIDRangeRequest { |
199 | type Reply = GetXIDRangeReply; |
200 | } |
201 | |
202 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
203 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
204 | pub struct GetXIDRangeReply { |
205 | pub sequence: u16, |
206 | pub length: u32, |
207 | pub start_id: u32, |
208 | pub count: u32, |
209 | } |
210 | impl TryParse for GetXIDRangeReply { |
211 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
212 | let remaining: &[u8] = initial_value; |
213 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
214 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
215 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
216 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
217 | let (start_id: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
218 | let (count: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
219 | if response_type != 1 { |
220 | return Err(ParseError::InvalidValue); |
221 | } |
222 | let result: GetXIDRangeReply = GetXIDRangeReply { sequence, length, start_id, count }; |
223 | let _ = remaining; |
224 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
225 | .ok_or(err:ParseError::InsufficientData)?; |
226 | Ok((result, remaining)) |
227 | } |
228 | } |
229 | impl Serialize for GetXIDRangeReply { |
230 | type Bytes = [u8; 16]; |
231 | fn serialize(&self) -> [u8; 16] { |
232 | let response_type_bytes = &[1]; |
233 | let sequence_bytes = self.sequence.serialize(); |
234 | let length_bytes = self.length.serialize(); |
235 | let start_id_bytes = self.start_id.serialize(); |
236 | let count_bytes = self.count.serialize(); |
237 | [ |
238 | response_type_bytes[0], |
239 | 0, |
240 | sequence_bytes[0], |
241 | sequence_bytes[1], |
242 | length_bytes[0], |
243 | length_bytes[1], |
244 | length_bytes[2], |
245 | length_bytes[3], |
246 | start_id_bytes[0], |
247 | start_id_bytes[1], |
248 | start_id_bytes[2], |
249 | start_id_bytes[3], |
250 | count_bytes[0], |
251 | count_bytes[1], |
252 | count_bytes[2], |
253 | count_bytes[3], |
254 | ] |
255 | } |
256 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
257 | bytes.reserve(16); |
258 | let response_type_bytes = &[1]; |
259 | bytes.push(response_type_bytes[0]); |
260 | bytes.extend_from_slice(&[0; 1]); |
261 | self.sequence.serialize_into(bytes); |
262 | self.length.serialize_into(bytes); |
263 | self.start_id.serialize_into(bytes); |
264 | self.count.serialize_into(bytes); |
265 | } |
266 | } |
267 | |
268 | /// Opcode for the GetXIDList request |
269 | pub const GET_XID_LIST_REQUEST: u8 = 2; |
270 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
271 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
272 | pub struct GetXIDListRequest { |
273 | pub count: u32, |
274 | } |
275 | impl GetXIDListRequest { |
276 | /// Serialize this request into bytes for the provided connection |
277 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>> { |
278 | let length_so_far = 0; |
279 | let count_bytes = self.count.serialize(); |
280 | let mut request0 = vec![ |
281 | major_opcode, |
282 | GET_XID_LIST_REQUEST, |
283 | 0, |
284 | 0, |
285 | count_bytes[0], |
286 | count_bytes[1], |
287 | count_bytes[2], |
288 | count_bytes[3], |
289 | ]; |
290 | let length_so_far = length_so_far + request0.len(); |
291 | assert_eq!(length_so_far % 4, 0); |
292 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
293 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
294 | (vec![request0.into()], vec![]) |
295 | } |
296 | /// Parse this request given its header, its body, and any fds that go along with it |
297 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
298 | if header.minor_opcode != GET_XID_LIST_REQUEST { |
299 | return Err(ParseError::InvalidValue); |
300 | } |
301 | let (count, remaining) = u32::try_parse(value)?; |
302 | let _ = remaining; |
303 | Ok(GetXIDListRequest { |
304 | count, |
305 | }) |
306 | } |
307 | } |
308 | impl Request for GetXIDListRequest { |
309 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
310 | |
311 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
312 | let (bufs: Vec>, fds: Vec) = self.serialize(major_opcode); |
313 | // Flatten the buffers into a single vector |
314 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
315 | (buf, fds) |
316 | } |
317 | } |
318 | impl crate::x11_utils::ReplyRequest for GetXIDListRequest { |
319 | type Reply = GetXIDListReply; |
320 | } |
321 | |
322 | #[derive (Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
323 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
324 | pub struct GetXIDListReply { |
325 | pub sequence: u16, |
326 | pub length: u32, |
327 | pub ids: Vec<u32>, |
328 | } |
329 | impl TryParse for GetXIDListReply { |
330 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
331 | let remaining: &[u8] = initial_value; |
332 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
333 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
334 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
335 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
336 | let (ids_len: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
337 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
338 | let (ids: Vec, remaining: &[u8]) = crate::x11_utils::parse_list::<u32>(data:remaining, list_length:ids_len.try_to_usize()?)?; |
339 | if response_type != 1 { |
340 | return Err(ParseError::InvalidValue); |
341 | } |
342 | let result: GetXIDListReply = GetXIDListReply { sequence, length, ids }; |
343 | let _ = remaining; |
344 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
345 | .ok_or(err:ParseError::InsufficientData)?; |
346 | Ok((result, remaining)) |
347 | } |
348 | } |
349 | impl Serialize for GetXIDListReply { |
350 | type Bytes = Vec<u8>; |
351 | fn serialize(&self) -> Vec<u8> { |
352 | let mut result: Vec = Vec::new(); |
353 | self.serialize_into(&mut result); |
354 | result |
355 | } |
356 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
357 | bytes.reserve(additional:32); |
358 | let response_type_bytes: &[u8; 1] = &[1]; |
359 | bytes.push(response_type_bytes[0]); |
360 | bytes.extend_from_slice(&[0; 1]); |
361 | self.sequence.serialize_into(bytes); |
362 | self.length.serialize_into(bytes); |
363 | let ids_len: u32 = u32::try_from(self.ids.len()).expect(msg:"`ids` has too many elements" ); |
364 | ids_len.serialize_into(bytes); |
365 | bytes.extend_from_slice(&[0; 20]); |
366 | self.ids.serialize_into(bytes); |
367 | } |
368 | } |
369 | impl GetXIDListReply { |
370 | /// Get the value of the `ids_len` field. |
371 | /// |
372 | /// The `ids_len` field is used as the length field of the `ids` field. |
373 | /// This function computes the field's value again based on the length of the list. |
374 | /// |
375 | /// # Panics |
376 | /// |
377 | /// Panics if the value cannot be represented in the target type. This |
378 | /// cannot happen with values of the struct received from the X11 server. |
379 | pub fn ids_len(&self) -> u32 { |
380 | self.ids.len() |
381 | .try_into().unwrap() |
382 | } |
383 | } |
384 | |
385 | |