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)]
11use alloc::borrow::Cow;
12#[allow(unused_imports)]
13use core::convert::TryInto;
14use alloc::vec;
15use alloc::vec::Vec;
16use core::convert::TryFrom;
17use crate::errors::ParseError;
18#[allow(unused_imports)]
19use crate::x11_utils::TryIntoUSize;
20use crate::BufWithFds;
21#[allow(unused_imports)]
22use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
23#[allow(unused_imports)]
24use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
25
26/// The X11 name of the extension for QueryExtension
27pub 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.
35pub const X11_XML_VERSION: (u32, u32) = (0, 0);
36
37/// Opcode for the Enable request
38pub const ENABLE_REQUEST: u8 = 0;
39/// Enable the BIG-REQUESTS extension.
40///
41/// This enables the BIG-REQUESTS extension, which allows for requests larger than
42/// 262140 bytes in length. When enabled, if the 16-bit length field is zero, it
43/// is immediately followed by a 32-bit length field specifying the length of the
44/// request in 4-byte units.
45#[derive(Clone, Copy, Default)]
46#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48pub struct EnableRequest;
49impl_debug_if_no_extra_traits!(EnableRequest, "EnableRequest");
50impl EnableRequest {
51 /// Serialize this request into bytes for the provided connection
52 pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
53 let length_so_far = 0;
54 let mut request0 = vec![
55 major_opcode,
56 ENABLE_REQUEST,
57 0,
58 0,
59 ];
60 let length_so_far = length_so_far + request0.len();
61 assert_eq!(length_so_far % 4, 0);
62 let length = u16::try_from(length_so_far / 4).unwrap_or(0);
63 request0[2..4].copy_from_slice(&length.to_ne_bytes());
64 ([request0.into()], vec![])
65 }
66 /// Parse this request given its header, its body, and any fds that go along with it
67 #[cfg(feature = "request-parsing")]
68 pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
69 if header.minor_opcode != ENABLE_REQUEST {
70 return Err(ParseError::InvalidValue);
71 }
72 let _ = value;
73 Ok(EnableRequest
74 )
75 }
76}
77impl Request for EnableRequest {
78 const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
79
80 fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
81 let (bufs: [Cow<'_, [u8]>; 1], fds: Vec) = self.serialize(major_opcode);
82 // Flatten the buffers into a single vector
83 let buf: Vec = bufs.iter().flat_map(|buf: &Cow<'_, [u8]>| buf.iter().copied()).collect();
84 (buf, fds)
85 }
86}
87impl crate::x11_utils::ReplyRequest for EnableRequest {
88 type Reply = EnableReply;
89}
90
91/// # Fields
92///
93/// * `maximum_request_length` - The maximum length of requests supported by the server, in 4-byte units.
94#[derive(Clone, Copy, Default)]
95#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
96#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
97pub struct EnableReply {
98 pub sequence: u16,
99 pub length: u32,
100 pub maximum_request_length: u32,
101}
102impl_debug_if_no_extra_traits!(EnableReply, "EnableReply");
103impl TryParse for EnableReply {
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 (maximum_request_length: u32, remaining: &[u8]) = u32::try_parse(remaining)?;
111 if response_type != 1 {
112 return Err(ParseError::InvalidValue);
113 }
114 let result: EnableReply = EnableReply { sequence, length, maximum_request_length };
115 let _ = remaining;
116 let remaining: &[u8] = initial_value.get(32 + length as usize * 4..)
117 .ok_or(err:ParseError::InsufficientData)?;
118 Ok((result, remaining))
119 }
120}
121impl Serialize for EnableReply {
122 type Bytes = [u8; 12];
123 fn serialize(&self) -> [u8; 12] {
124 let response_type_bytes = &[1];
125 let sequence_bytes = self.sequence.serialize();
126 let length_bytes = self.length.serialize();
127 let maximum_request_length_bytes = self.maximum_request_length.serialize();
128 [
129 response_type_bytes[0],
130 0,
131 sequence_bytes[0],
132 sequence_bytes[1],
133 length_bytes[0],
134 length_bytes[1],
135 length_bytes[2],
136 length_bytes[3],
137 maximum_request_length_bytes[0],
138 maximum_request_length_bytes[1],
139 maximum_request_length_bytes[2],
140 maximum_request_length_bytes[3],
141 ]
142 }
143 fn serialize_into(&self, bytes: &mut Vec<u8>) {
144 bytes.reserve(12);
145 let response_type_bytes = &[1];
146 bytes.push(response_type_bytes[0]);
147 bytes.extend_from_slice(&[0; 1]);
148 self.sequence.serialize_into(bytes);
149 self.length.serialize_into(bytes);
150 self.maximum_request_length.serialize_into(bytes);
151 }
152}
153
154