1 | // This file contains generated code. Do not edit directly. |
2 | // To regenerate this, run 'make'. |
3 | |
4 | //! Bindings to the `BigRequests` 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 = "BIG-REQUESTS" ; |
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) = (0, 0); |
36 | |
37 | /// Opcode for the Enable request |
38 | pub const ENABLE_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 EnableRequest; |
42 | impl EnableRequest { |
43 | /// Serialize this request into bytes for the provided connection |
44 | pub fn serialize(self, major_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>> { |
45 | let length_so_far = 0; |
46 | let mut request0 = vec![ |
47 | major_opcode, |
48 | ENABLE_REQUEST, |
49 | 0, |
50 | 0, |
51 | ]; |
52 | let length_so_far = length_so_far + request0.len(); |
53 | assert_eq!(length_so_far % 4, 0); |
54 | let length = u16::try_from(length_so_far / 4).unwrap_or(0); |
55 | request0[2..4].copy_from_slice(&length.to_ne_bytes()); |
56 | (vec![request0.into()], vec![]) |
57 | } |
58 | /// Parse this request given its header, its body, and any fds that go along with it |
59 | pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> { |
60 | if header.minor_opcode != ENABLE_REQUEST { |
61 | return Err(ParseError::InvalidValue); |
62 | } |
63 | let _ = value; |
64 | Ok(EnableRequest |
65 | ) |
66 | } |
67 | } |
68 | impl Request for EnableRequest { |
69 | const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME); |
70 | |
71 | fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> { |
72 | let (bufs: Vec>, fds: Vec) = self.serialize(major_opcode); |
73 | // Flatten the buffers into a single vector |
74 | let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect(); |
75 | (buf, fds) |
76 | } |
77 | } |
78 | impl crate::x11_utils::ReplyRequest for EnableRequest { |
79 | type Reply = EnableReply; |
80 | } |
81 | |
82 | #[derive (Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
83 | #[cfg_attr (feature = "serde" , derive(serde::Serialize, serde::Deserialize))] |
84 | pub struct EnableReply { |
85 | pub sequence: u16, |
86 | pub length: u32, |
87 | pub maximum_request_length: u32, |
88 | } |
89 | impl TryParse for EnableReply { |
90 | fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> { |
91 | let remaining: &[u8] = initial_value; |
92 | let (response_type: u8, remaining: &[u8]) = u8::try_parse(remaining)?; |
93 | let remaining: &[u8] = remaining.get(1..).ok_or(err:ParseError::InsufficientData)?; |
94 | let (sequence: u16, remaining: &[u8]) = u16::try_parse(remaining)?; |
95 | let (length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
96 | let (maximum_request_length: u32, remaining: &[u8]) = u32::try_parse(remaining)?; |
97 | if response_type != 1 { |
98 | return Err(ParseError::InvalidValue); |
99 | } |
100 | let result: EnableReply = EnableReply { sequence, length, maximum_request_length }; |
101 | let _ = remaining; |
102 | let remaining: &[u8] = initial_value.get(32 + length as usize * 4..) |
103 | .ok_or(err:ParseError::InsufficientData)?; |
104 | Ok((result, remaining)) |
105 | } |
106 | } |
107 | impl Serialize for EnableReply { |
108 | type Bytes = [u8; 12]; |
109 | fn serialize(&self) -> [u8; 12] { |
110 | let response_type_bytes = &[1]; |
111 | let sequence_bytes = self.sequence.serialize(); |
112 | let length_bytes = self.length.serialize(); |
113 | let maximum_request_length_bytes = self.maximum_request_length.serialize(); |
114 | [ |
115 | response_type_bytes[0], |
116 | 0, |
117 | sequence_bytes[0], |
118 | sequence_bytes[1], |
119 | length_bytes[0], |
120 | length_bytes[1], |
121 | length_bytes[2], |
122 | length_bytes[3], |
123 | maximum_request_length_bytes[0], |
124 | maximum_request_length_bytes[1], |
125 | maximum_request_length_bytes[2], |
126 | maximum_request_length_bytes[3], |
127 | ] |
128 | } |
129 | fn serialize_into(&self, bytes: &mut Vec<u8>) { |
130 | bytes.reserve(12); |
131 | let response_type_bytes = &[1]; |
132 | bytes.push(response_type_bytes[0]); |
133 | bytes.extend_from_slice(&[0; 1]); |
134 | self.sequence.serialize_into(bytes); |
135 | self.length.serialize_into(bytes); |
136 | self.maximum_request_length.serialize_into(bytes); |
137 | } |
138 | } |
139 | |
140 | |