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, 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 = "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 (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
40 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
41 | pub struct QueryVersionRequest { |
42 | pub client_major_version: u16, |
43 | pub client_minor_version: u16, |
44 | } |
45 | impl QueryVersionRequest { |
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 | QUERY_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 != QUERY_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(QueryVersionRequest { |
76 | client_major_version, |
77 | client_minor_version, |
78 | }) |
79 | } |
80 | } |
81 | impl Request for QueryVersionRequest { |
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 QueryVersionRequest { |
92 | type Reply = QueryVersionReply; |
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 QueryVersionReply { |
98 | pub sequence: u16, |
99 | pub length: u32, |
100 | pub major_version: u16, |
101 | pub minor_version: u16, |
102 | } |
103 | impl TryParse for QueryVersionReply { |
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 (major_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
111 | let (minor_version: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
112 | let remaining: &[u8] = remaining.get(20..).ok_or(err:ParseError::InsufficientData)?; |
113 | if response_type != 1 { |
114 | return Err(ParseError::InvalidValue); |
115 | } |
116 | let result: QueryVersionReply = QueryVersionReply { sequence, length, major_version, minor_version }; |
117 | let _ = remaining; |
118 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
119 | .ok_or(err:ParseError::InsufficientData)?; |
120 | Ok((result, remaining)) |
121 | } |
122 | } |
123 | impl Serialize for QueryVersionReply { |
124 | type Bytes = [u8; 32]; |
125 | fn serialize(&self) -> [u8; 32] { |
126 | let response_type_bytes = &[1]; |
127 | let sequence_bytes = self.sequence.serialize(); |
128 | let length_bytes = self.length.serialize(); |
129 | let major_version_bytes = self.major_version.serialize(); |
130 | let minor_version_bytes = self.minor_version.serialize(); |
131 | [ |
132 | response_type_bytes[0], |
133 | 0, |
134 | sequence_bytes[0], |
135 | sequence_bytes[1], |
136 | length_bytes[0], |
137 | length_bytes[1], |
138 | length_bytes[2], |
139 | length_bytes[3], |
140 | major_version_bytes[0], |
141 | major_version_bytes[1], |
142 | minor_version_bytes[0], |
143 | minor_version_bytes[1], |
144 | 0, |
145 | 0, |
146 | 0, |
147 | 0, |
148 | 0, |
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 | ] |
165 | } |
166 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
167 | bytes.reserve(32); |
168 | let response_type_bytes = &[1]; |
169 | bytes.push(response_type_bytes[0]); |
170 | bytes.extend_from_slice(&[0; 1]); |
171 | self.sequence.serialize_into(bytes); |
172 | self.length.serialize_into(bytes); |
173 | self.major_version.serialize_into(bytes); |
174 | self.minor_version.serialize_into(bytes); |
175 | bytes.extend_from_slice(&[0; 20]); |
176 | } |
177 | } |
178 | |
179 | |