x11rb_protocol/protocol/
dri2.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `DRI2` 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#[allow(unused_imports)]
26use super::xproto;
27
28/// The X11 name of the extension for QueryExtension
29pub const X11_EXTENSION_NAME: &str = "DRI2";
30
31/// The version number of this extension that this client library supports.
32///
33/// This constant contains the version number of this extension that is supported
34/// by this build of x11rb. For most things, it does not make sense to use this
35/// information. If you need to send a `QueryVersion`, it is recommended to instead
36/// send the maximum version of the extension that you need.
37pub const X11_XML_VERSION: (u32, u32) = (1, 4);
38
39#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41pub struct Attachment(u32);
42impl Attachment {
43    pub const BUFFER_FRONT_LEFT: Self = Self(0);
44    pub const BUFFER_BACK_LEFT: Self = Self(1);
45    pub const BUFFER_FRONT_RIGHT: Self = Self(2);
46    pub const BUFFER_BACK_RIGHT: Self = Self(3);
47    pub const BUFFER_DEPTH: Self = Self(4);
48    pub const BUFFER_STENCIL: Self = Self(5);
49    pub const BUFFER_ACCUM: Self = Self(6);
50    pub const BUFFER_FAKE_FRONT_LEFT: Self = Self(7);
51    pub const BUFFER_FAKE_FRONT_RIGHT: Self = Self(8);
52    pub const BUFFER_DEPTH_STENCIL: Self = Self(9);
53    pub const BUFFER_HIZ: Self = Self(10);
54}
55impl From<Attachment> for u32 {
56    #[inline]
57    fn from(input: Attachment) -> Self {
58        input.0
59    }
60}
61impl From<Attachment> for Option<u32> {
62    #[inline]
63    fn from(input: Attachment) -> Self {
64        Some(input.0)
65    }
66}
67impl From<u8> for Attachment {
68    #[inline]
69    fn from(value: u8) -> Self {
70        Self(value.into())
71    }
72}
73impl From<u16> for Attachment {
74    #[inline]
75    fn from(value: u16) -> Self {
76        Self(value.into())
77    }
78}
79impl From<u32> for Attachment {
80    #[inline]
81    fn from(value: u32) -> Self {
82        Self(value)
83    }
84}
85impl core::fmt::Debug for Attachment  {
86    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
87        let variants = [
88            (Self::BUFFER_FRONT_LEFT.0, "BUFFER_FRONT_LEFT", "BufferFrontLeft"),
89            (Self::BUFFER_BACK_LEFT.0, "BUFFER_BACK_LEFT", "BufferBackLeft"),
90            (Self::BUFFER_FRONT_RIGHT.0, "BUFFER_FRONT_RIGHT", "BufferFrontRight"),
91            (Self::BUFFER_BACK_RIGHT.0, "BUFFER_BACK_RIGHT", "BufferBackRight"),
92            (Self::BUFFER_DEPTH.0, "BUFFER_DEPTH", "BufferDepth"),
93            (Self::BUFFER_STENCIL.0, "BUFFER_STENCIL", "BufferStencil"),
94            (Self::BUFFER_ACCUM.0, "BUFFER_ACCUM", "BufferAccum"),
95            (Self::BUFFER_FAKE_FRONT_LEFT.0, "BUFFER_FAKE_FRONT_LEFT", "BufferFakeFrontLeft"),
96            (Self::BUFFER_FAKE_FRONT_RIGHT.0, "BUFFER_FAKE_FRONT_RIGHT", "BufferFakeFrontRight"),
97            (Self::BUFFER_DEPTH_STENCIL.0, "BUFFER_DEPTH_STENCIL", "BufferDepthStencil"),
98            (Self::BUFFER_HIZ.0, "BUFFER_HIZ", "BufferHiz"),
99        ];
100        pretty_print_enum(fmt, self.0, &variants)
101    }
102}
103
104#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
105#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
106pub struct DriverType(u32);
107impl DriverType {
108    pub const DRI: Self = Self(0);
109    pub const VDPAU: Self = Self(1);
110}
111impl From<DriverType> for u32 {
112    #[inline]
113    fn from(input: DriverType) -> Self {
114        input.0
115    }
116}
117impl From<DriverType> for Option<u32> {
118    #[inline]
119    fn from(input: DriverType) -> Self {
120        Some(input.0)
121    }
122}
123impl From<u8> for DriverType {
124    #[inline]
125    fn from(value: u8) -> Self {
126        Self(value.into())
127    }
128}
129impl From<u16> for DriverType {
130    #[inline]
131    fn from(value: u16) -> Self {
132        Self(value.into())
133    }
134}
135impl From<u32> for DriverType {
136    #[inline]
137    fn from(value: u32) -> Self {
138        Self(value)
139    }
140}
141impl core::fmt::Debug for DriverType  {
142    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
143        let variants = [
144            (Self::DRI.0, "DRI", "DRI"),
145            (Self::VDPAU.0, "VDPAU", "VDPAU"),
146        ];
147        pretty_print_enum(fmt, self.0, &variants)
148    }
149}
150
151#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
152#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
153pub struct EventType(u16);
154impl EventType {
155    pub const EXCHANGE_COMPLETE: Self = Self(1);
156    pub const BLIT_COMPLETE: Self = Self(2);
157    pub const FLIP_COMPLETE: Self = Self(3);
158}
159impl From<EventType> for u16 {
160    #[inline]
161    fn from(input: EventType) -> Self {
162        input.0
163    }
164}
165impl From<EventType> for Option<u16> {
166    #[inline]
167    fn from(input: EventType) -> Self {
168        Some(input.0)
169    }
170}
171impl From<EventType> for u32 {
172    #[inline]
173    fn from(input: EventType) -> Self {
174        u32::from(input.0)
175    }
176}
177impl From<EventType> for Option<u32> {
178    #[inline]
179    fn from(input: EventType) -> Self {
180        Some(u32::from(input.0))
181    }
182}
183impl From<u8> for EventType {
184    #[inline]
185    fn from(value: u8) -> Self {
186        Self(value.into())
187    }
188}
189impl From<u16> for EventType {
190    #[inline]
191    fn from(value: u16) -> Self {
192        Self(value)
193    }
194}
195impl core::fmt::Debug for EventType  {
196    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
197        let variants = [
198            (Self::EXCHANGE_COMPLETE.0.into(), "EXCHANGE_COMPLETE", "ExchangeComplete"),
199            (Self::BLIT_COMPLETE.0.into(), "BLIT_COMPLETE", "BlitComplete"),
200            (Self::FLIP_COMPLETE.0.into(), "FLIP_COMPLETE", "FlipComplete"),
201        ];
202        pretty_print_enum(fmt, self.0.into(), &variants)
203    }
204}
205
206#[derive(Clone, Copy, Default)]
207#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
208#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
209pub struct DRI2Buffer {
210    pub attachment: Attachment,
211    pub name: u32,
212    pub pitch: u32,
213    pub cpp: u32,
214    pub flags: u32,
215}
216impl_debug_if_no_extra_traits!(DRI2Buffer, "DRI2Buffer");
217impl TryParse for DRI2Buffer {
218    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
219        let (attachment, remaining) = u32::try_parse(remaining)?;
220        let (name, remaining) = u32::try_parse(remaining)?;
221        let (pitch, remaining) = u32::try_parse(remaining)?;
222        let (cpp, remaining) = u32::try_parse(remaining)?;
223        let (flags, remaining) = u32::try_parse(remaining)?;
224        let attachment = attachment.into();
225        let result = DRI2Buffer { attachment, name, pitch, cpp, flags };
226        Ok((result, remaining))
227    }
228}
229impl Serialize for DRI2Buffer {
230    type Bytes = [u8; 20];
231    fn serialize(&self) -> [u8; 20] {
232        let attachment_bytes = u32::from(self.attachment).serialize();
233        let name_bytes = self.name.serialize();
234        let pitch_bytes = self.pitch.serialize();
235        let cpp_bytes = self.cpp.serialize();
236        let flags_bytes = self.flags.serialize();
237        [
238            attachment_bytes[0],
239            attachment_bytes[1],
240            attachment_bytes[2],
241            attachment_bytes[3],
242            name_bytes[0],
243            name_bytes[1],
244            name_bytes[2],
245            name_bytes[3],
246            pitch_bytes[0],
247            pitch_bytes[1],
248            pitch_bytes[2],
249            pitch_bytes[3],
250            cpp_bytes[0],
251            cpp_bytes[1],
252            cpp_bytes[2],
253            cpp_bytes[3],
254            flags_bytes[0],
255            flags_bytes[1],
256            flags_bytes[2],
257            flags_bytes[3],
258        ]
259    }
260    fn serialize_into(&self, bytes: &mut Vec<u8>) {
261        bytes.reserve(20);
262        u32::from(self.attachment).serialize_into(bytes);
263        self.name.serialize_into(bytes);
264        self.pitch.serialize_into(bytes);
265        self.cpp.serialize_into(bytes);
266        self.flags.serialize_into(bytes);
267    }
268}
269
270#[derive(Clone, Copy, Default)]
271#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
272#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
273pub struct AttachFormat {
274    pub attachment: Attachment,
275    pub format: u32,
276}
277impl_debug_if_no_extra_traits!(AttachFormat, "AttachFormat");
278impl TryParse for AttachFormat {
279    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
280        let (attachment, remaining) = u32::try_parse(remaining)?;
281        let (format, remaining) = u32::try_parse(remaining)?;
282        let attachment = attachment.into();
283        let result = AttachFormat { attachment, format };
284        Ok((result, remaining))
285    }
286}
287impl Serialize for AttachFormat {
288    type Bytes = [u8; 8];
289    fn serialize(&self) -> [u8; 8] {
290        let attachment_bytes = u32::from(self.attachment).serialize();
291        let format_bytes = self.format.serialize();
292        [
293            attachment_bytes[0],
294            attachment_bytes[1],
295            attachment_bytes[2],
296            attachment_bytes[3],
297            format_bytes[0],
298            format_bytes[1],
299            format_bytes[2],
300            format_bytes[3],
301        ]
302    }
303    fn serialize_into(&self, bytes: &mut Vec<u8>) {
304        bytes.reserve(8);
305        u32::from(self.attachment).serialize_into(bytes);
306        self.format.serialize_into(bytes);
307    }
308}
309
310/// Opcode for the QueryVersion request
311pub const QUERY_VERSION_REQUEST: u8 = 0;
312#[derive(Clone, Copy, Default)]
313#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
314#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
315pub struct QueryVersionRequest {
316    pub major_version: u32,
317    pub minor_version: u32,
318}
319impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
320impl QueryVersionRequest {
321    /// Serialize this request into bytes for the provided connection
322    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
323        let length_so_far = 0;
324        let major_version_bytes = self.major_version.serialize();
325        let minor_version_bytes = self.minor_version.serialize();
326        let mut request0 = vec![
327            major_opcode,
328            QUERY_VERSION_REQUEST,
329            0,
330            0,
331            major_version_bytes[0],
332            major_version_bytes[1],
333            major_version_bytes[2],
334            major_version_bytes[3],
335            minor_version_bytes[0],
336            minor_version_bytes[1],
337            minor_version_bytes[2],
338            minor_version_bytes[3],
339        ];
340        let length_so_far = length_so_far + request0.len();
341        assert_eq!(length_so_far % 4, 0);
342        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
343        request0[2..4].copy_from_slice(&length.to_ne_bytes());
344        ([request0.into()], vec![])
345    }
346    /// Parse this request given its header, its body, and any fds that go along with it
347    #[cfg(feature = "request-parsing")]
348    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
349        if header.minor_opcode != QUERY_VERSION_REQUEST {
350            return Err(ParseError::InvalidValue);
351        }
352        let (major_version, remaining) = u32::try_parse(value)?;
353        let (minor_version, remaining) = u32::try_parse(remaining)?;
354        let _ = remaining;
355        Ok(QueryVersionRequest {
356            major_version,
357            minor_version,
358        })
359    }
360}
361impl Request for QueryVersionRequest {
362    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
363
364    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
365        let (bufs, fds) = self.serialize(major_opcode);
366        // Flatten the buffers into a single vector
367        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
368        (buf, fds)
369    }
370}
371impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
372    type Reply = QueryVersionReply;
373}
374
375#[derive(Clone, Copy, Default)]
376#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
377#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
378pub struct QueryVersionReply {
379    pub sequence: u16,
380    pub length: u32,
381    pub major_version: u32,
382    pub minor_version: u32,
383}
384impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
385impl TryParse for QueryVersionReply {
386    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
387        let remaining = initial_value;
388        let (response_type, remaining) = u8::try_parse(remaining)?;
389        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
390        let (sequence, remaining) = u16::try_parse(remaining)?;
391        let (length, remaining) = u32::try_parse(remaining)?;
392        let (major_version, remaining) = u32::try_parse(remaining)?;
393        let (minor_version, remaining) = u32::try_parse(remaining)?;
394        if response_type != 1 {
395            return Err(ParseError::InvalidValue);
396        }
397        let result = QueryVersionReply { sequence, length, major_version, minor_version };
398        let _ = remaining;
399        let remaining = initial_value.get(32 + length as usize * 4..)
400            .ok_or(ParseError::InsufficientData)?;
401        Ok((result, remaining))
402    }
403}
404impl Serialize for QueryVersionReply {
405    type Bytes = [u8; 16];
406    fn serialize(&self) -> [u8; 16] {
407        let response_type_bytes = &[1];
408        let sequence_bytes = self.sequence.serialize();
409        let length_bytes = self.length.serialize();
410        let major_version_bytes = self.major_version.serialize();
411        let minor_version_bytes = self.minor_version.serialize();
412        [
413            response_type_bytes[0],
414            0,
415            sequence_bytes[0],
416            sequence_bytes[1],
417            length_bytes[0],
418            length_bytes[1],
419            length_bytes[2],
420            length_bytes[3],
421            major_version_bytes[0],
422            major_version_bytes[1],
423            major_version_bytes[2],
424            major_version_bytes[3],
425            minor_version_bytes[0],
426            minor_version_bytes[1],
427            minor_version_bytes[2],
428            minor_version_bytes[3],
429        ]
430    }
431    fn serialize_into(&self, bytes: &mut Vec<u8>) {
432        bytes.reserve(16);
433        let response_type_bytes = &[1];
434        bytes.push(response_type_bytes[0]);
435        bytes.extend_from_slice(&[0; 1]);
436        self.sequence.serialize_into(bytes);
437        self.length.serialize_into(bytes);
438        self.major_version.serialize_into(bytes);
439        self.minor_version.serialize_into(bytes);
440    }
441}
442
443/// Opcode for the Connect request
444pub const CONNECT_REQUEST: u8 = 1;
445#[derive(Clone, Copy, Default)]
446#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
447#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
448pub struct ConnectRequest {
449    pub window: xproto::Window,
450    pub driver_type: DriverType,
451}
452impl_debug_if_no_extra_traits!(ConnectRequest, "ConnectRequest");
453impl ConnectRequest {
454    /// Serialize this request into bytes for the provided connection
455    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
456        let length_so_far = 0;
457        let window_bytes = self.window.serialize();
458        let driver_type_bytes = u32::from(self.driver_type).serialize();
459        let mut request0 = vec![
460            major_opcode,
461            CONNECT_REQUEST,
462            0,
463            0,
464            window_bytes[0],
465            window_bytes[1],
466            window_bytes[2],
467            window_bytes[3],
468            driver_type_bytes[0],
469            driver_type_bytes[1],
470            driver_type_bytes[2],
471            driver_type_bytes[3],
472        ];
473        let length_so_far = length_so_far + request0.len();
474        assert_eq!(length_so_far % 4, 0);
475        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
476        request0[2..4].copy_from_slice(&length.to_ne_bytes());
477        ([request0.into()], vec![])
478    }
479    /// Parse this request given its header, its body, and any fds that go along with it
480    #[cfg(feature = "request-parsing")]
481    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
482        if header.minor_opcode != CONNECT_REQUEST {
483            return Err(ParseError::InvalidValue);
484        }
485        let (window, remaining) = xproto::Window::try_parse(value)?;
486        let (driver_type, remaining) = u32::try_parse(remaining)?;
487        let driver_type = driver_type.into();
488        let _ = remaining;
489        Ok(ConnectRequest {
490            window,
491            driver_type,
492        })
493    }
494}
495impl Request for ConnectRequest {
496    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
497
498    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
499        let (bufs, fds) = self.serialize(major_opcode);
500        // Flatten the buffers into a single vector
501        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
502        (buf, fds)
503    }
504}
505impl crate::x11_utils::ReplyRequest for ConnectRequest {
506    type Reply = ConnectReply;
507}
508
509#[derive(Clone, Default)]
510#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
511#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
512pub struct ConnectReply {
513    pub sequence: u16,
514    pub length: u32,
515    pub driver_name: Vec<u8>,
516    pub alignment_pad: Vec<u8>,
517    pub device_name: Vec<u8>,
518}
519impl_debug_if_no_extra_traits!(ConnectReply, "ConnectReply");
520impl TryParse for ConnectReply {
521    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
522        let remaining = initial_value;
523        let (response_type, remaining) = u8::try_parse(remaining)?;
524        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
525        let (sequence, remaining) = u16::try_parse(remaining)?;
526        let (length, remaining) = u32::try_parse(remaining)?;
527        let (driver_name_length, remaining) = u32::try_parse(remaining)?;
528        let (device_name_length, remaining) = u32::try_parse(remaining)?;
529        let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
530        let (driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, driver_name_length.try_to_usize()?)?;
531        let driver_name = driver_name.to_vec();
532        let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(driver_name_length).checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(driver_name_length)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
533        let alignment_pad = alignment_pad.to_vec();
534        let (device_name, remaining) = crate::x11_utils::parse_u8_list(remaining, device_name_length.try_to_usize()?)?;
535        let device_name = device_name.to_vec();
536        if response_type != 1 {
537            return Err(ParseError::InvalidValue);
538        }
539        let result = ConnectReply { sequence, length, driver_name, alignment_pad, device_name };
540        let _ = remaining;
541        let remaining = initial_value.get(32 + length as usize * 4..)
542            .ok_or(ParseError::InsufficientData)?;
543        Ok((result, remaining))
544    }
545}
546impl Serialize for ConnectReply {
547    type Bytes = Vec<u8>;
548    fn serialize(&self) -> Vec<u8> {
549        let mut result = Vec::new();
550        self.serialize_into(&mut result);
551        result
552    }
553    fn serialize_into(&self, bytes: &mut Vec<u8>) {
554        bytes.reserve(32);
555        let response_type_bytes = &[1];
556        bytes.push(response_type_bytes[0]);
557        bytes.extend_from_slice(&[0; 1]);
558        self.sequence.serialize_into(bytes);
559        self.length.serialize_into(bytes);
560        let driver_name_length = u32::try_from(self.driver_name.len()).expect("`driver_name` has too many elements");
561        driver_name_length.serialize_into(bytes);
562        let device_name_length = u32::try_from(self.device_name.len()).expect("`device_name` has too many elements");
563        device_name_length.serialize_into(bytes);
564        bytes.extend_from_slice(&[0; 16]);
565        bytes.extend_from_slice(&self.driver_name);
566        assert_eq!(self.alignment_pad.len(), usize::try_from((u32::from(driver_name_length).checked_add(3u32).unwrap() & (!3u32)).checked_sub(u32::from(driver_name_length)).unwrap()).unwrap(), "`alignment_pad` has an incorrect length");
567        bytes.extend_from_slice(&self.alignment_pad);
568        bytes.extend_from_slice(&self.device_name);
569    }
570}
571impl ConnectReply {
572    /// Get the value of the `driver_name_length` field.
573    ///
574    /// The `driver_name_length` field is used as the length field of the `driver_name` field.
575    /// This function computes the field's value again based on the length of the list.
576    ///
577    /// # Panics
578    ///
579    /// Panics if the value cannot be represented in the target type. This
580    /// cannot happen with values of the struct received from the X11 server.
581    pub fn driver_name_length(&self) -> u32 {
582        self.driver_name.len()
583            .try_into().unwrap()
584    }
585    /// Get the value of the `device_name_length` field.
586    ///
587    /// The `device_name_length` field is used as the length field of the `device_name` field.
588    /// This function computes the field's value again based on the length of the list.
589    ///
590    /// # Panics
591    ///
592    /// Panics if the value cannot be represented in the target type. This
593    /// cannot happen with values of the struct received from the X11 server.
594    pub fn device_name_length(&self) -> u32 {
595        self.device_name.len()
596            .try_into().unwrap()
597    }
598}
599
600/// Opcode for the Authenticate request
601pub const AUTHENTICATE_REQUEST: u8 = 2;
602#[derive(Clone, Copy, Default)]
603#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
604#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
605pub struct AuthenticateRequest {
606    pub window: xproto::Window,
607    pub magic: u32,
608}
609impl_debug_if_no_extra_traits!(AuthenticateRequest, "AuthenticateRequest");
610impl AuthenticateRequest {
611    /// Serialize this request into bytes for the provided connection
612    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
613        let length_so_far = 0;
614        let window_bytes = self.window.serialize();
615        let magic_bytes = self.magic.serialize();
616        let mut request0 = vec![
617            major_opcode,
618            AUTHENTICATE_REQUEST,
619            0,
620            0,
621            window_bytes[0],
622            window_bytes[1],
623            window_bytes[2],
624            window_bytes[3],
625            magic_bytes[0],
626            magic_bytes[1],
627            magic_bytes[2],
628            magic_bytes[3],
629        ];
630        let length_so_far = length_so_far + request0.len();
631        assert_eq!(length_so_far % 4, 0);
632        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
633        request0[2..4].copy_from_slice(&length.to_ne_bytes());
634        ([request0.into()], vec![])
635    }
636    /// Parse this request given its header, its body, and any fds that go along with it
637    #[cfg(feature = "request-parsing")]
638    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
639        if header.minor_opcode != AUTHENTICATE_REQUEST {
640            return Err(ParseError::InvalidValue);
641        }
642        let (window, remaining) = xproto::Window::try_parse(value)?;
643        let (magic, remaining) = u32::try_parse(remaining)?;
644        let _ = remaining;
645        Ok(AuthenticateRequest {
646            window,
647            magic,
648        })
649    }
650}
651impl Request for AuthenticateRequest {
652    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
653
654    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
655        let (bufs, fds) = self.serialize(major_opcode);
656        // Flatten the buffers into a single vector
657        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
658        (buf, fds)
659    }
660}
661impl crate::x11_utils::ReplyRequest for AuthenticateRequest {
662    type Reply = AuthenticateReply;
663}
664
665#[derive(Clone, Copy, Default)]
666#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
667#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
668pub struct AuthenticateReply {
669    pub sequence: u16,
670    pub length: u32,
671    pub authenticated: u32,
672}
673impl_debug_if_no_extra_traits!(AuthenticateReply, "AuthenticateReply");
674impl TryParse for AuthenticateReply {
675    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
676        let remaining = initial_value;
677        let (response_type, remaining) = u8::try_parse(remaining)?;
678        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
679        let (sequence, remaining) = u16::try_parse(remaining)?;
680        let (length, remaining) = u32::try_parse(remaining)?;
681        let (authenticated, remaining) = u32::try_parse(remaining)?;
682        if response_type != 1 {
683            return Err(ParseError::InvalidValue);
684        }
685        let result = AuthenticateReply { sequence, length, authenticated };
686        let _ = remaining;
687        let remaining = initial_value.get(32 + length as usize * 4..)
688            .ok_or(ParseError::InsufficientData)?;
689        Ok((result, remaining))
690    }
691}
692impl Serialize for AuthenticateReply {
693    type Bytes = [u8; 12];
694    fn serialize(&self) -> [u8; 12] {
695        let response_type_bytes = &[1];
696        let sequence_bytes = self.sequence.serialize();
697        let length_bytes = self.length.serialize();
698        let authenticated_bytes = self.authenticated.serialize();
699        [
700            response_type_bytes[0],
701            0,
702            sequence_bytes[0],
703            sequence_bytes[1],
704            length_bytes[0],
705            length_bytes[1],
706            length_bytes[2],
707            length_bytes[3],
708            authenticated_bytes[0],
709            authenticated_bytes[1],
710            authenticated_bytes[2],
711            authenticated_bytes[3],
712        ]
713    }
714    fn serialize_into(&self, bytes: &mut Vec<u8>) {
715        bytes.reserve(12);
716        let response_type_bytes = &[1];
717        bytes.push(response_type_bytes[0]);
718        bytes.extend_from_slice(&[0; 1]);
719        self.sequence.serialize_into(bytes);
720        self.length.serialize_into(bytes);
721        self.authenticated.serialize_into(bytes);
722    }
723}
724
725/// Opcode for the CreateDrawable request
726pub const CREATE_DRAWABLE_REQUEST: u8 = 3;
727#[derive(Clone, Copy, Default)]
728#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
729#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
730pub struct CreateDrawableRequest {
731    pub drawable: xproto::Drawable,
732}
733impl_debug_if_no_extra_traits!(CreateDrawableRequest, "CreateDrawableRequest");
734impl CreateDrawableRequest {
735    /// Serialize this request into bytes for the provided connection
736    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
737        let length_so_far = 0;
738        let drawable_bytes = self.drawable.serialize();
739        let mut request0 = vec![
740            major_opcode,
741            CREATE_DRAWABLE_REQUEST,
742            0,
743            0,
744            drawable_bytes[0],
745            drawable_bytes[1],
746            drawable_bytes[2],
747            drawable_bytes[3],
748        ];
749        let length_so_far = length_so_far + request0.len();
750        assert_eq!(length_so_far % 4, 0);
751        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
752        request0[2..4].copy_from_slice(&length.to_ne_bytes());
753        ([request0.into()], vec![])
754    }
755    /// Parse this request given its header, its body, and any fds that go along with it
756    #[cfg(feature = "request-parsing")]
757    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
758        if header.minor_opcode != CREATE_DRAWABLE_REQUEST {
759            return Err(ParseError::InvalidValue);
760        }
761        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
762        let _ = remaining;
763        Ok(CreateDrawableRequest {
764            drawable,
765        })
766    }
767}
768impl Request for CreateDrawableRequest {
769    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
770
771    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
772        let (bufs, fds) = self.serialize(major_opcode);
773        // Flatten the buffers into a single vector
774        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
775        (buf, fds)
776    }
777}
778impl crate::x11_utils::VoidRequest for CreateDrawableRequest {
779}
780
781/// Opcode for the DestroyDrawable request
782pub const DESTROY_DRAWABLE_REQUEST: u8 = 4;
783#[derive(Clone, Copy, Default)]
784#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
785#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
786pub struct DestroyDrawableRequest {
787    pub drawable: xproto::Drawable,
788}
789impl_debug_if_no_extra_traits!(DestroyDrawableRequest, "DestroyDrawableRequest");
790impl DestroyDrawableRequest {
791    /// Serialize this request into bytes for the provided connection
792    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
793        let length_so_far = 0;
794        let drawable_bytes = self.drawable.serialize();
795        let mut request0 = vec![
796            major_opcode,
797            DESTROY_DRAWABLE_REQUEST,
798            0,
799            0,
800            drawable_bytes[0],
801            drawable_bytes[1],
802            drawable_bytes[2],
803            drawable_bytes[3],
804        ];
805        let length_so_far = length_so_far + request0.len();
806        assert_eq!(length_so_far % 4, 0);
807        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
808        request0[2..4].copy_from_slice(&length.to_ne_bytes());
809        ([request0.into()], vec![])
810    }
811    /// Parse this request given its header, its body, and any fds that go along with it
812    #[cfg(feature = "request-parsing")]
813    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
814        if header.minor_opcode != DESTROY_DRAWABLE_REQUEST {
815            return Err(ParseError::InvalidValue);
816        }
817        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
818        let _ = remaining;
819        Ok(DestroyDrawableRequest {
820            drawable,
821        })
822    }
823}
824impl Request for DestroyDrawableRequest {
825    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
826
827    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
828        let (bufs, fds) = self.serialize(major_opcode);
829        // Flatten the buffers into a single vector
830        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
831        (buf, fds)
832    }
833}
834impl crate::x11_utils::VoidRequest for DestroyDrawableRequest {
835}
836
837/// Opcode for the GetBuffers request
838pub const GET_BUFFERS_REQUEST: u8 = 5;
839#[derive(Clone, Default)]
840#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
841#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
842pub struct GetBuffersRequest<'input> {
843    pub drawable: xproto::Drawable,
844    pub count: u32,
845    pub attachments: Cow<'input, [u32]>,
846}
847impl_debug_if_no_extra_traits!(GetBuffersRequest<'_>, "GetBuffersRequest");
848impl<'input> GetBuffersRequest<'input> {
849    /// Serialize this request into bytes for the provided connection
850    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
851        let length_so_far = 0;
852        let drawable_bytes = self.drawable.serialize();
853        let count_bytes = self.count.serialize();
854        let mut request0 = vec![
855            major_opcode,
856            GET_BUFFERS_REQUEST,
857            0,
858            0,
859            drawable_bytes[0],
860            drawable_bytes[1],
861            drawable_bytes[2],
862            drawable_bytes[3],
863            count_bytes[0],
864            count_bytes[1],
865            count_bytes[2],
866            count_bytes[3],
867        ];
868        let length_so_far = length_so_far + request0.len();
869        let attachments_bytes = self.attachments.serialize();
870        let length_so_far = length_so_far + attachments_bytes.len();
871        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
872        let length_so_far = length_so_far + padding0.len();
873        assert_eq!(length_so_far % 4, 0);
874        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
875        request0[2..4].copy_from_slice(&length.to_ne_bytes());
876        ([request0.into(), attachments_bytes.into(), padding0.into()], vec![])
877    }
878    /// Parse this request given its header, its body, and any fds that go along with it
879    #[cfg(feature = "request-parsing")]
880    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
881        if header.minor_opcode != GET_BUFFERS_REQUEST {
882            return Err(ParseError::InvalidValue);
883        }
884        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
885        let (count, remaining) = u32::try_parse(remaining)?;
886        let mut remaining = remaining;
887        // Length is 'everything left in the input'
888        let mut attachments = Vec::new();
889        while !remaining.is_empty() {
890            let (v, new_remaining) = u32::try_parse(remaining)?;
891            remaining = new_remaining;
892            attachments.push(v);
893        }
894        let _ = remaining;
895        Ok(GetBuffersRequest {
896            drawable,
897            count,
898            attachments: Cow::Owned(attachments),
899        })
900    }
901    /// Clone all borrowed data in this GetBuffersRequest.
902    pub fn into_owned(self) -> GetBuffersRequest<'static> {
903        GetBuffersRequest {
904            drawable: self.drawable,
905            count: self.count,
906            attachments: Cow::Owned(self.attachments.into_owned()),
907        }
908    }
909}
910impl<'input> Request for GetBuffersRequest<'input> {
911    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
912
913    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
914        let (bufs, fds) = self.serialize(major_opcode);
915        // Flatten the buffers into a single vector
916        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
917        (buf, fds)
918    }
919}
920impl<'input> crate::x11_utils::ReplyRequest for GetBuffersRequest<'input> {
921    type Reply = GetBuffersReply;
922}
923
924#[derive(Clone, Default)]
925#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
926#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
927pub struct GetBuffersReply {
928    pub sequence: u16,
929    pub length: u32,
930    pub width: u32,
931    pub height: u32,
932    pub buffers: Vec<DRI2Buffer>,
933}
934impl_debug_if_no_extra_traits!(GetBuffersReply, "GetBuffersReply");
935impl TryParse for GetBuffersReply {
936    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
937        let remaining = initial_value;
938        let (response_type, remaining) = u8::try_parse(remaining)?;
939        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
940        let (sequence, remaining) = u16::try_parse(remaining)?;
941        let (length, remaining) = u32::try_parse(remaining)?;
942        let (width, remaining) = u32::try_parse(remaining)?;
943        let (height, remaining) = u32::try_parse(remaining)?;
944        let (count, remaining) = u32::try_parse(remaining)?;
945        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
946        let (buffers, remaining) = crate::x11_utils::parse_list::<DRI2Buffer>(remaining, count.try_to_usize()?)?;
947        if response_type != 1 {
948            return Err(ParseError::InvalidValue);
949        }
950        let result = GetBuffersReply { sequence, length, width, height, buffers };
951        let _ = remaining;
952        let remaining = initial_value.get(32 + length as usize * 4..)
953            .ok_or(ParseError::InsufficientData)?;
954        Ok((result, remaining))
955    }
956}
957impl Serialize for GetBuffersReply {
958    type Bytes = Vec<u8>;
959    fn serialize(&self) -> Vec<u8> {
960        let mut result = Vec::new();
961        self.serialize_into(&mut result);
962        result
963    }
964    fn serialize_into(&self, bytes: &mut Vec<u8>) {
965        bytes.reserve(32);
966        let response_type_bytes = &[1];
967        bytes.push(response_type_bytes[0]);
968        bytes.extend_from_slice(&[0; 1]);
969        self.sequence.serialize_into(bytes);
970        self.length.serialize_into(bytes);
971        self.width.serialize_into(bytes);
972        self.height.serialize_into(bytes);
973        let count = u32::try_from(self.buffers.len()).expect("`buffers` has too many elements");
974        count.serialize_into(bytes);
975        bytes.extend_from_slice(&[0; 12]);
976        self.buffers.serialize_into(bytes);
977    }
978}
979impl GetBuffersReply {
980    /// Get the value of the `count` field.
981    ///
982    /// The `count` field is used as the length field of the `buffers` field.
983    /// This function computes the field's value again based on the length of the list.
984    ///
985    /// # Panics
986    ///
987    /// Panics if the value cannot be represented in the target type. This
988    /// cannot happen with values of the struct received from the X11 server.
989    pub fn count(&self) -> u32 {
990        self.buffers.len()
991            .try_into().unwrap()
992    }
993}
994
995/// Opcode for the CopyRegion request
996pub const COPY_REGION_REQUEST: u8 = 6;
997#[derive(Clone, Copy, Default)]
998#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
999#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1000pub struct CopyRegionRequest {
1001    pub drawable: xproto::Drawable,
1002    pub region: u32,
1003    pub dest: u32,
1004    pub src: u32,
1005}
1006impl_debug_if_no_extra_traits!(CopyRegionRequest, "CopyRegionRequest");
1007impl CopyRegionRequest {
1008    /// Serialize this request into bytes for the provided connection
1009    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1010        let length_so_far = 0;
1011        let drawable_bytes = self.drawable.serialize();
1012        let region_bytes = self.region.serialize();
1013        let dest_bytes = self.dest.serialize();
1014        let src_bytes = self.src.serialize();
1015        let mut request0 = vec![
1016            major_opcode,
1017            COPY_REGION_REQUEST,
1018            0,
1019            0,
1020            drawable_bytes[0],
1021            drawable_bytes[1],
1022            drawable_bytes[2],
1023            drawable_bytes[3],
1024            region_bytes[0],
1025            region_bytes[1],
1026            region_bytes[2],
1027            region_bytes[3],
1028            dest_bytes[0],
1029            dest_bytes[1],
1030            dest_bytes[2],
1031            dest_bytes[3],
1032            src_bytes[0],
1033            src_bytes[1],
1034            src_bytes[2],
1035            src_bytes[3],
1036        ];
1037        let length_so_far = length_so_far + request0.len();
1038        assert_eq!(length_so_far % 4, 0);
1039        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1040        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1041        ([request0.into()], vec![])
1042    }
1043    /// Parse this request given its header, its body, and any fds that go along with it
1044    #[cfg(feature = "request-parsing")]
1045    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1046        if header.minor_opcode != COPY_REGION_REQUEST {
1047            return Err(ParseError::InvalidValue);
1048        }
1049        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1050        let (region, remaining) = u32::try_parse(remaining)?;
1051        let (dest, remaining) = u32::try_parse(remaining)?;
1052        let (src, remaining) = u32::try_parse(remaining)?;
1053        let _ = remaining;
1054        Ok(CopyRegionRequest {
1055            drawable,
1056            region,
1057            dest,
1058            src,
1059        })
1060    }
1061}
1062impl Request for CopyRegionRequest {
1063    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1064
1065    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1066        let (bufs, fds) = self.serialize(major_opcode);
1067        // Flatten the buffers into a single vector
1068        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1069        (buf, fds)
1070    }
1071}
1072impl crate::x11_utils::ReplyRequest for CopyRegionRequest {
1073    type Reply = CopyRegionReply;
1074}
1075
1076#[derive(Clone, Copy, Default)]
1077#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1078#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1079pub struct CopyRegionReply {
1080    pub sequence: u16,
1081    pub length: u32,
1082}
1083impl_debug_if_no_extra_traits!(CopyRegionReply, "CopyRegionReply");
1084impl TryParse for CopyRegionReply {
1085    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1086        let remaining = initial_value;
1087        let (response_type, remaining) = u8::try_parse(remaining)?;
1088        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1089        let (sequence, remaining) = u16::try_parse(remaining)?;
1090        let (length, remaining) = u32::try_parse(remaining)?;
1091        if response_type != 1 {
1092            return Err(ParseError::InvalidValue);
1093        }
1094        let result = CopyRegionReply { sequence, length };
1095        let _ = remaining;
1096        let remaining = initial_value.get(32 + length as usize * 4..)
1097            .ok_or(ParseError::InsufficientData)?;
1098        Ok((result, remaining))
1099    }
1100}
1101impl Serialize for CopyRegionReply {
1102    type Bytes = [u8; 8];
1103    fn serialize(&self) -> [u8; 8] {
1104        let response_type_bytes = &[1];
1105        let sequence_bytes = self.sequence.serialize();
1106        let length_bytes = self.length.serialize();
1107        [
1108            response_type_bytes[0],
1109            0,
1110            sequence_bytes[0],
1111            sequence_bytes[1],
1112            length_bytes[0],
1113            length_bytes[1],
1114            length_bytes[2],
1115            length_bytes[3],
1116        ]
1117    }
1118    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1119        bytes.reserve(8);
1120        let response_type_bytes = &[1];
1121        bytes.push(response_type_bytes[0]);
1122        bytes.extend_from_slice(&[0; 1]);
1123        self.sequence.serialize_into(bytes);
1124        self.length.serialize_into(bytes);
1125    }
1126}
1127
1128/// Opcode for the GetBuffersWithFormat request
1129pub const GET_BUFFERS_WITH_FORMAT_REQUEST: u8 = 7;
1130#[derive(Clone, Default)]
1131#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1132#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1133pub struct GetBuffersWithFormatRequest<'input> {
1134    pub drawable: xproto::Drawable,
1135    pub count: u32,
1136    pub attachments: Cow<'input, [AttachFormat]>,
1137}
1138impl_debug_if_no_extra_traits!(GetBuffersWithFormatRequest<'_>, "GetBuffersWithFormatRequest");
1139impl<'input> GetBuffersWithFormatRequest<'input> {
1140    /// Serialize this request into bytes for the provided connection
1141    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1142        let length_so_far = 0;
1143        let drawable_bytes = self.drawable.serialize();
1144        let count_bytes = self.count.serialize();
1145        let mut request0 = vec![
1146            major_opcode,
1147            GET_BUFFERS_WITH_FORMAT_REQUEST,
1148            0,
1149            0,
1150            drawable_bytes[0],
1151            drawable_bytes[1],
1152            drawable_bytes[2],
1153            drawable_bytes[3],
1154            count_bytes[0],
1155            count_bytes[1],
1156            count_bytes[2],
1157            count_bytes[3],
1158        ];
1159        let length_so_far = length_so_far + request0.len();
1160        let attachments_bytes = self.attachments.serialize();
1161        let length_so_far = length_so_far + attachments_bytes.len();
1162        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1163        let length_so_far = length_so_far + padding0.len();
1164        assert_eq!(length_so_far % 4, 0);
1165        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1166        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1167        ([request0.into(), attachments_bytes.into(), padding0.into()], vec![])
1168    }
1169    /// Parse this request given its header, its body, and any fds that go along with it
1170    #[cfg(feature = "request-parsing")]
1171    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1172        if header.minor_opcode != GET_BUFFERS_WITH_FORMAT_REQUEST {
1173            return Err(ParseError::InvalidValue);
1174        }
1175        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1176        let (count, remaining) = u32::try_parse(remaining)?;
1177        let mut remaining = remaining;
1178        // Length is 'everything left in the input'
1179        let mut attachments = Vec::new();
1180        while !remaining.is_empty() {
1181            let (v, new_remaining) = AttachFormat::try_parse(remaining)?;
1182            remaining = new_remaining;
1183            attachments.push(v);
1184        }
1185        let _ = remaining;
1186        Ok(GetBuffersWithFormatRequest {
1187            drawable,
1188            count,
1189            attachments: Cow::Owned(attachments),
1190        })
1191    }
1192    /// Clone all borrowed data in this GetBuffersWithFormatRequest.
1193    pub fn into_owned(self) -> GetBuffersWithFormatRequest<'static> {
1194        GetBuffersWithFormatRequest {
1195            drawable: self.drawable,
1196            count: self.count,
1197            attachments: Cow::Owned(self.attachments.into_owned()),
1198        }
1199    }
1200}
1201impl<'input> Request for GetBuffersWithFormatRequest<'input> {
1202    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1203
1204    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1205        let (bufs, fds) = self.serialize(major_opcode);
1206        // Flatten the buffers into a single vector
1207        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1208        (buf, fds)
1209    }
1210}
1211impl<'input> crate::x11_utils::ReplyRequest for GetBuffersWithFormatRequest<'input> {
1212    type Reply = GetBuffersWithFormatReply;
1213}
1214
1215#[derive(Clone, Default)]
1216#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1217#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1218pub struct GetBuffersWithFormatReply {
1219    pub sequence: u16,
1220    pub length: u32,
1221    pub width: u32,
1222    pub height: u32,
1223    pub buffers: Vec<DRI2Buffer>,
1224}
1225impl_debug_if_no_extra_traits!(GetBuffersWithFormatReply, "GetBuffersWithFormatReply");
1226impl TryParse for GetBuffersWithFormatReply {
1227    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1228        let remaining = initial_value;
1229        let (response_type, remaining) = u8::try_parse(remaining)?;
1230        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1231        let (sequence, remaining) = u16::try_parse(remaining)?;
1232        let (length, remaining) = u32::try_parse(remaining)?;
1233        let (width, remaining) = u32::try_parse(remaining)?;
1234        let (height, remaining) = u32::try_parse(remaining)?;
1235        let (count, remaining) = u32::try_parse(remaining)?;
1236        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1237        let (buffers, remaining) = crate::x11_utils::parse_list::<DRI2Buffer>(remaining, count.try_to_usize()?)?;
1238        if response_type != 1 {
1239            return Err(ParseError::InvalidValue);
1240        }
1241        let result = GetBuffersWithFormatReply { sequence, length, width, height, buffers };
1242        let _ = remaining;
1243        let remaining = initial_value.get(32 + length as usize * 4..)
1244            .ok_or(ParseError::InsufficientData)?;
1245        Ok((result, remaining))
1246    }
1247}
1248impl Serialize for GetBuffersWithFormatReply {
1249    type Bytes = Vec<u8>;
1250    fn serialize(&self) -> Vec<u8> {
1251        let mut result = Vec::new();
1252        self.serialize_into(&mut result);
1253        result
1254    }
1255    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1256        bytes.reserve(32);
1257        let response_type_bytes = &[1];
1258        bytes.push(response_type_bytes[0]);
1259        bytes.extend_from_slice(&[0; 1]);
1260        self.sequence.serialize_into(bytes);
1261        self.length.serialize_into(bytes);
1262        self.width.serialize_into(bytes);
1263        self.height.serialize_into(bytes);
1264        let count = u32::try_from(self.buffers.len()).expect("`buffers` has too many elements");
1265        count.serialize_into(bytes);
1266        bytes.extend_from_slice(&[0; 12]);
1267        self.buffers.serialize_into(bytes);
1268    }
1269}
1270impl GetBuffersWithFormatReply {
1271    /// Get the value of the `count` field.
1272    ///
1273    /// The `count` field is used as the length field of the `buffers` field.
1274    /// This function computes the field's value again based on the length of the list.
1275    ///
1276    /// # Panics
1277    ///
1278    /// Panics if the value cannot be represented in the target type. This
1279    /// cannot happen with values of the struct received from the X11 server.
1280    pub fn count(&self) -> u32 {
1281        self.buffers.len()
1282            .try_into().unwrap()
1283    }
1284}
1285
1286/// Opcode for the SwapBuffers request
1287pub const SWAP_BUFFERS_REQUEST: u8 = 8;
1288#[derive(Clone, Copy, Default)]
1289#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1290#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1291pub struct SwapBuffersRequest {
1292    pub drawable: xproto::Drawable,
1293    pub target_msc_hi: u32,
1294    pub target_msc_lo: u32,
1295    pub divisor_hi: u32,
1296    pub divisor_lo: u32,
1297    pub remainder_hi: u32,
1298    pub remainder_lo: u32,
1299}
1300impl_debug_if_no_extra_traits!(SwapBuffersRequest, "SwapBuffersRequest");
1301impl SwapBuffersRequest {
1302    /// Serialize this request into bytes for the provided connection
1303    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1304        let length_so_far = 0;
1305        let drawable_bytes = self.drawable.serialize();
1306        let target_msc_hi_bytes = self.target_msc_hi.serialize();
1307        let target_msc_lo_bytes = self.target_msc_lo.serialize();
1308        let divisor_hi_bytes = self.divisor_hi.serialize();
1309        let divisor_lo_bytes = self.divisor_lo.serialize();
1310        let remainder_hi_bytes = self.remainder_hi.serialize();
1311        let remainder_lo_bytes = self.remainder_lo.serialize();
1312        let mut request0 = vec![
1313            major_opcode,
1314            SWAP_BUFFERS_REQUEST,
1315            0,
1316            0,
1317            drawable_bytes[0],
1318            drawable_bytes[1],
1319            drawable_bytes[2],
1320            drawable_bytes[3],
1321            target_msc_hi_bytes[0],
1322            target_msc_hi_bytes[1],
1323            target_msc_hi_bytes[2],
1324            target_msc_hi_bytes[3],
1325            target_msc_lo_bytes[0],
1326            target_msc_lo_bytes[1],
1327            target_msc_lo_bytes[2],
1328            target_msc_lo_bytes[3],
1329            divisor_hi_bytes[0],
1330            divisor_hi_bytes[1],
1331            divisor_hi_bytes[2],
1332            divisor_hi_bytes[3],
1333            divisor_lo_bytes[0],
1334            divisor_lo_bytes[1],
1335            divisor_lo_bytes[2],
1336            divisor_lo_bytes[3],
1337            remainder_hi_bytes[0],
1338            remainder_hi_bytes[1],
1339            remainder_hi_bytes[2],
1340            remainder_hi_bytes[3],
1341            remainder_lo_bytes[0],
1342            remainder_lo_bytes[1],
1343            remainder_lo_bytes[2],
1344            remainder_lo_bytes[3],
1345        ];
1346        let length_so_far = length_so_far + request0.len();
1347        assert_eq!(length_so_far % 4, 0);
1348        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1349        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1350        ([request0.into()], vec![])
1351    }
1352    /// Parse this request given its header, its body, and any fds that go along with it
1353    #[cfg(feature = "request-parsing")]
1354    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1355        if header.minor_opcode != SWAP_BUFFERS_REQUEST {
1356            return Err(ParseError::InvalidValue);
1357        }
1358        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1359        let (target_msc_hi, remaining) = u32::try_parse(remaining)?;
1360        let (target_msc_lo, remaining) = u32::try_parse(remaining)?;
1361        let (divisor_hi, remaining) = u32::try_parse(remaining)?;
1362        let (divisor_lo, remaining) = u32::try_parse(remaining)?;
1363        let (remainder_hi, remaining) = u32::try_parse(remaining)?;
1364        let (remainder_lo, remaining) = u32::try_parse(remaining)?;
1365        let _ = remaining;
1366        Ok(SwapBuffersRequest {
1367            drawable,
1368            target_msc_hi,
1369            target_msc_lo,
1370            divisor_hi,
1371            divisor_lo,
1372            remainder_hi,
1373            remainder_lo,
1374        })
1375    }
1376}
1377impl Request for SwapBuffersRequest {
1378    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1379
1380    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1381        let (bufs, fds) = self.serialize(major_opcode);
1382        // Flatten the buffers into a single vector
1383        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1384        (buf, fds)
1385    }
1386}
1387impl crate::x11_utils::ReplyRequest for SwapBuffersRequest {
1388    type Reply = SwapBuffersReply;
1389}
1390
1391#[derive(Clone, Copy, Default)]
1392#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1393#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1394pub struct SwapBuffersReply {
1395    pub sequence: u16,
1396    pub length: u32,
1397    pub swap_hi: u32,
1398    pub swap_lo: u32,
1399}
1400impl_debug_if_no_extra_traits!(SwapBuffersReply, "SwapBuffersReply");
1401impl TryParse for SwapBuffersReply {
1402    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1403        let remaining = initial_value;
1404        let (response_type, remaining) = u8::try_parse(remaining)?;
1405        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1406        let (sequence, remaining) = u16::try_parse(remaining)?;
1407        let (length, remaining) = u32::try_parse(remaining)?;
1408        let (swap_hi, remaining) = u32::try_parse(remaining)?;
1409        let (swap_lo, remaining) = u32::try_parse(remaining)?;
1410        if response_type != 1 {
1411            return Err(ParseError::InvalidValue);
1412        }
1413        let result = SwapBuffersReply { sequence, length, swap_hi, swap_lo };
1414        let _ = remaining;
1415        let remaining = initial_value.get(32 + length as usize * 4..)
1416            .ok_or(ParseError::InsufficientData)?;
1417        Ok((result, remaining))
1418    }
1419}
1420impl Serialize for SwapBuffersReply {
1421    type Bytes = [u8; 16];
1422    fn serialize(&self) -> [u8; 16] {
1423        let response_type_bytes = &[1];
1424        let sequence_bytes = self.sequence.serialize();
1425        let length_bytes = self.length.serialize();
1426        let swap_hi_bytes = self.swap_hi.serialize();
1427        let swap_lo_bytes = self.swap_lo.serialize();
1428        [
1429            response_type_bytes[0],
1430            0,
1431            sequence_bytes[0],
1432            sequence_bytes[1],
1433            length_bytes[0],
1434            length_bytes[1],
1435            length_bytes[2],
1436            length_bytes[3],
1437            swap_hi_bytes[0],
1438            swap_hi_bytes[1],
1439            swap_hi_bytes[2],
1440            swap_hi_bytes[3],
1441            swap_lo_bytes[0],
1442            swap_lo_bytes[1],
1443            swap_lo_bytes[2],
1444            swap_lo_bytes[3],
1445        ]
1446    }
1447    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1448        bytes.reserve(16);
1449        let response_type_bytes = &[1];
1450        bytes.push(response_type_bytes[0]);
1451        bytes.extend_from_slice(&[0; 1]);
1452        self.sequence.serialize_into(bytes);
1453        self.length.serialize_into(bytes);
1454        self.swap_hi.serialize_into(bytes);
1455        self.swap_lo.serialize_into(bytes);
1456    }
1457}
1458
1459/// Opcode for the GetMSC request
1460pub const GET_MSC_REQUEST: u8 = 9;
1461#[derive(Clone, Copy, Default)]
1462#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1463#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1464pub struct GetMSCRequest {
1465    pub drawable: xproto::Drawable,
1466}
1467impl_debug_if_no_extra_traits!(GetMSCRequest, "GetMSCRequest");
1468impl GetMSCRequest {
1469    /// Serialize this request into bytes for the provided connection
1470    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1471        let length_so_far = 0;
1472        let drawable_bytes = self.drawable.serialize();
1473        let mut request0 = vec![
1474            major_opcode,
1475            GET_MSC_REQUEST,
1476            0,
1477            0,
1478            drawable_bytes[0],
1479            drawable_bytes[1],
1480            drawable_bytes[2],
1481            drawable_bytes[3],
1482        ];
1483        let length_so_far = length_so_far + request0.len();
1484        assert_eq!(length_so_far % 4, 0);
1485        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1486        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1487        ([request0.into()], vec![])
1488    }
1489    /// Parse this request given its header, its body, and any fds that go along with it
1490    #[cfg(feature = "request-parsing")]
1491    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1492        if header.minor_opcode != GET_MSC_REQUEST {
1493            return Err(ParseError::InvalidValue);
1494        }
1495        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1496        let _ = remaining;
1497        Ok(GetMSCRequest {
1498            drawable,
1499        })
1500    }
1501}
1502impl Request for GetMSCRequest {
1503    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1504
1505    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1506        let (bufs, fds) = self.serialize(major_opcode);
1507        // Flatten the buffers into a single vector
1508        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1509        (buf, fds)
1510    }
1511}
1512impl crate::x11_utils::ReplyRequest for GetMSCRequest {
1513    type Reply = GetMSCReply;
1514}
1515
1516#[derive(Clone, Copy, Default)]
1517#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1518#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1519pub struct GetMSCReply {
1520    pub sequence: u16,
1521    pub length: u32,
1522    pub ust_hi: u32,
1523    pub ust_lo: u32,
1524    pub msc_hi: u32,
1525    pub msc_lo: u32,
1526    pub sbc_hi: u32,
1527    pub sbc_lo: u32,
1528}
1529impl_debug_if_no_extra_traits!(GetMSCReply, "GetMSCReply");
1530impl TryParse for GetMSCReply {
1531    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1532        let remaining = initial_value;
1533        let (response_type, remaining) = u8::try_parse(remaining)?;
1534        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1535        let (sequence, remaining) = u16::try_parse(remaining)?;
1536        let (length, remaining) = u32::try_parse(remaining)?;
1537        let (ust_hi, remaining) = u32::try_parse(remaining)?;
1538        let (ust_lo, remaining) = u32::try_parse(remaining)?;
1539        let (msc_hi, remaining) = u32::try_parse(remaining)?;
1540        let (msc_lo, remaining) = u32::try_parse(remaining)?;
1541        let (sbc_hi, remaining) = u32::try_parse(remaining)?;
1542        let (sbc_lo, remaining) = u32::try_parse(remaining)?;
1543        if response_type != 1 {
1544            return Err(ParseError::InvalidValue);
1545        }
1546        let result = GetMSCReply { sequence, length, ust_hi, ust_lo, msc_hi, msc_lo, sbc_hi, sbc_lo };
1547        let _ = remaining;
1548        let remaining = initial_value.get(32 + length as usize * 4..)
1549            .ok_or(ParseError::InsufficientData)?;
1550        Ok((result, remaining))
1551    }
1552}
1553impl Serialize for GetMSCReply {
1554    type Bytes = [u8; 32];
1555    fn serialize(&self) -> [u8; 32] {
1556        let response_type_bytes = &[1];
1557        let sequence_bytes = self.sequence.serialize();
1558        let length_bytes = self.length.serialize();
1559        let ust_hi_bytes = self.ust_hi.serialize();
1560        let ust_lo_bytes = self.ust_lo.serialize();
1561        let msc_hi_bytes = self.msc_hi.serialize();
1562        let msc_lo_bytes = self.msc_lo.serialize();
1563        let sbc_hi_bytes = self.sbc_hi.serialize();
1564        let sbc_lo_bytes = self.sbc_lo.serialize();
1565        [
1566            response_type_bytes[0],
1567            0,
1568            sequence_bytes[0],
1569            sequence_bytes[1],
1570            length_bytes[0],
1571            length_bytes[1],
1572            length_bytes[2],
1573            length_bytes[3],
1574            ust_hi_bytes[0],
1575            ust_hi_bytes[1],
1576            ust_hi_bytes[2],
1577            ust_hi_bytes[3],
1578            ust_lo_bytes[0],
1579            ust_lo_bytes[1],
1580            ust_lo_bytes[2],
1581            ust_lo_bytes[3],
1582            msc_hi_bytes[0],
1583            msc_hi_bytes[1],
1584            msc_hi_bytes[2],
1585            msc_hi_bytes[3],
1586            msc_lo_bytes[0],
1587            msc_lo_bytes[1],
1588            msc_lo_bytes[2],
1589            msc_lo_bytes[3],
1590            sbc_hi_bytes[0],
1591            sbc_hi_bytes[1],
1592            sbc_hi_bytes[2],
1593            sbc_hi_bytes[3],
1594            sbc_lo_bytes[0],
1595            sbc_lo_bytes[1],
1596            sbc_lo_bytes[2],
1597            sbc_lo_bytes[3],
1598        ]
1599    }
1600    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1601        bytes.reserve(32);
1602        let response_type_bytes = &[1];
1603        bytes.push(response_type_bytes[0]);
1604        bytes.extend_from_slice(&[0; 1]);
1605        self.sequence.serialize_into(bytes);
1606        self.length.serialize_into(bytes);
1607        self.ust_hi.serialize_into(bytes);
1608        self.ust_lo.serialize_into(bytes);
1609        self.msc_hi.serialize_into(bytes);
1610        self.msc_lo.serialize_into(bytes);
1611        self.sbc_hi.serialize_into(bytes);
1612        self.sbc_lo.serialize_into(bytes);
1613    }
1614}
1615
1616/// Opcode for the WaitMSC request
1617pub const WAIT_MSC_REQUEST: u8 = 10;
1618#[derive(Clone, Copy, Default)]
1619#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1620#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1621pub struct WaitMSCRequest {
1622    pub drawable: xproto::Drawable,
1623    pub target_msc_hi: u32,
1624    pub target_msc_lo: u32,
1625    pub divisor_hi: u32,
1626    pub divisor_lo: u32,
1627    pub remainder_hi: u32,
1628    pub remainder_lo: u32,
1629}
1630impl_debug_if_no_extra_traits!(WaitMSCRequest, "WaitMSCRequest");
1631impl WaitMSCRequest {
1632    /// Serialize this request into bytes for the provided connection
1633    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1634        let length_so_far = 0;
1635        let drawable_bytes = self.drawable.serialize();
1636        let target_msc_hi_bytes = self.target_msc_hi.serialize();
1637        let target_msc_lo_bytes = self.target_msc_lo.serialize();
1638        let divisor_hi_bytes = self.divisor_hi.serialize();
1639        let divisor_lo_bytes = self.divisor_lo.serialize();
1640        let remainder_hi_bytes = self.remainder_hi.serialize();
1641        let remainder_lo_bytes = self.remainder_lo.serialize();
1642        let mut request0 = vec![
1643            major_opcode,
1644            WAIT_MSC_REQUEST,
1645            0,
1646            0,
1647            drawable_bytes[0],
1648            drawable_bytes[1],
1649            drawable_bytes[2],
1650            drawable_bytes[3],
1651            target_msc_hi_bytes[0],
1652            target_msc_hi_bytes[1],
1653            target_msc_hi_bytes[2],
1654            target_msc_hi_bytes[3],
1655            target_msc_lo_bytes[0],
1656            target_msc_lo_bytes[1],
1657            target_msc_lo_bytes[2],
1658            target_msc_lo_bytes[3],
1659            divisor_hi_bytes[0],
1660            divisor_hi_bytes[1],
1661            divisor_hi_bytes[2],
1662            divisor_hi_bytes[3],
1663            divisor_lo_bytes[0],
1664            divisor_lo_bytes[1],
1665            divisor_lo_bytes[2],
1666            divisor_lo_bytes[3],
1667            remainder_hi_bytes[0],
1668            remainder_hi_bytes[1],
1669            remainder_hi_bytes[2],
1670            remainder_hi_bytes[3],
1671            remainder_lo_bytes[0],
1672            remainder_lo_bytes[1],
1673            remainder_lo_bytes[2],
1674            remainder_lo_bytes[3],
1675        ];
1676        let length_so_far = length_so_far + request0.len();
1677        assert_eq!(length_so_far % 4, 0);
1678        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1679        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1680        ([request0.into()], vec![])
1681    }
1682    /// Parse this request given its header, its body, and any fds that go along with it
1683    #[cfg(feature = "request-parsing")]
1684    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1685        if header.minor_opcode != WAIT_MSC_REQUEST {
1686            return Err(ParseError::InvalidValue);
1687        }
1688        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1689        let (target_msc_hi, remaining) = u32::try_parse(remaining)?;
1690        let (target_msc_lo, remaining) = u32::try_parse(remaining)?;
1691        let (divisor_hi, remaining) = u32::try_parse(remaining)?;
1692        let (divisor_lo, remaining) = u32::try_parse(remaining)?;
1693        let (remainder_hi, remaining) = u32::try_parse(remaining)?;
1694        let (remainder_lo, remaining) = u32::try_parse(remaining)?;
1695        let _ = remaining;
1696        Ok(WaitMSCRequest {
1697            drawable,
1698            target_msc_hi,
1699            target_msc_lo,
1700            divisor_hi,
1701            divisor_lo,
1702            remainder_hi,
1703            remainder_lo,
1704        })
1705    }
1706}
1707impl Request for WaitMSCRequest {
1708    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1709
1710    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1711        let (bufs, fds) = self.serialize(major_opcode);
1712        // Flatten the buffers into a single vector
1713        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1714        (buf, fds)
1715    }
1716}
1717impl crate::x11_utils::ReplyRequest for WaitMSCRequest {
1718    type Reply = WaitMSCReply;
1719}
1720
1721#[derive(Clone, Copy, Default)]
1722#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1723#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1724pub struct WaitMSCReply {
1725    pub sequence: u16,
1726    pub length: u32,
1727    pub ust_hi: u32,
1728    pub ust_lo: u32,
1729    pub msc_hi: u32,
1730    pub msc_lo: u32,
1731    pub sbc_hi: u32,
1732    pub sbc_lo: u32,
1733}
1734impl_debug_if_no_extra_traits!(WaitMSCReply, "WaitMSCReply");
1735impl TryParse for WaitMSCReply {
1736    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1737        let remaining = initial_value;
1738        let (response_type, remaining) = u8::try_parse(remaining)?;
1739        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1740        let (sequence, remaining) = u16::try_parse(remaining)?;
1741        let (length, remaining) = u32::try_parse(remaining)?;
1742        let (ust_hi, remaining) = u32::try_parse(remaining)?;
1743        let (ust_lo, remaining) = u32::try_parse(remaining)?;
1744        let (msc_hi, remaining) = u32::try_parse(remaining)?;
1745        let (msc_lo, remaining) = u32::try_parse(remaining)?;
1746        let (sbc_hi, remaining) = u32::try_parse(remaining)?;
1747        let (sbc_lo, remaining) = u32::try_parse(remaining)?;
1748        if response_type != 1 {
1749            return Err(ParseError::InvalidValue);
1750        }
1751        let result = WaitMSCReply { sequence, length, ust_hi, ust_lo, msc_hi, msc_lo, sbc_hi, sbc_lo };
1752        let _ = remaining;
1753        let remaining = initial_value.get(32 + length as usize * 4..)
1754            .ok_or(ParseError::InsufficientData)?;
1755        Ok((result, remaining))
1756    }
1757}
1758impl Serialize for WaitMSCReply {
1759    type Bytes = [u8; 32];
1760    fn serialize(&self) -> [u8; 32] {
1761        let response_type_bytes = &[1];
1762        let sequence_bytes = self.sequence.serialize();
1763        let length_bytes = self.length.serialize();
1764        let ust_hi_bytes = self.ust_hi.serialize();
1765        let ust_lo_bytes = self.ust_lo.serialize();
1766        let msc_hi_bytes = self.msc_hi.serialize();
1767        let msc_lo_bytes = self.msc_lo.serialize();
1768        let sbc_hi_bytes = self.sbc_hi.serialize();
1769        let sbc_lo_bytes = self.sbc_lo.serialize();
1770        [
1771            response_type_bytes[0],
1772            0,
1773            sequence_bytes[0],
1774            sequence_bytes[1],
1775            length_bytes[0],
1776            length_bytes[1],
1777            length_bytes[2],
1778            length_bytes[3],
1779            ust_hi_bytes[0],
1780            ust_hi_bytes[1],
1781            ust_hi_bytes[2],
1782            ust_hi_bytes[3],
1783            ust_lo_bytes[0],
1784            ust_lo_bytes[1],
1785            ust_lo_bytes[2],
1786            ust_lo_bytes[3],
1787            msc_hi_bytes[0],
1788            msc_hi_bytes[1],
1789            msc_hi_bytes[2],
1790            msc_hi_bytes[3],
1791            msc_lo_bytes[0],
1792            msc_lo_bytes[1],
1793            msc_lo_bytes[2],
1794            msc_lo_bytes[3],
1795            sbc_hi_bytes[0],
1796            sbc_hi_bytes[1],
1797            sbc_hi_bytes[2],
1798            sbc_hi_bytes[3],
1799            sbc_lo_bytes[0],
1800            sbc_lo_bytes[1],
1801            sbc_lo_bytes[2],
1802            sbc_lo_bytes[3],
1803        ]
1804    }
1805    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1806        bytes.reserve(32);
1807        let response_type_bytes = &[1];
1808        bytes.push(response_type_bytes[0]);
1809        bytes.extend_from_slice(&[0; 1]);
1810        self.sequence.serialize_into(bytes);
1811        self.length.serialize_into(bytes);
1812        self.ust_hi.serialize_into(bytes);
1813        self.ust_lo.serialize_into(bytes);
1814        self.msc_hi.serialize_into(bytes);
1815        self.msc_lo.serialize_into(bytes);
1816        self.sbc_hi.serialize_into(bytes);
1817        self.sbc_lo.serialize_into(bytes);
1818    }
1819}
1820
1821/// Opcode for the WaitSBC request
1822pub const WAIT_SBC_REQUEST: u8 = 11;
1823#[derive(Clone, Copy, Default)]
1824#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1825#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1826pub struct WaitSBCRequest {
1827    pub drawable: xproto::Drawable,
1828    pub target_sbc_hi: u32,
1829    pub target_sbc_lo: u32,
1830}
1831impl_debug_if_no_extra_traits!(WaitSBCRequest, "WaitSBCRequest");
1832impl WaitSBCRequest {
1833    /// Serialize this request into bytes for the provided connection
1834    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1835        let length_so_far = 0;
1836        let drawable_bytes = self.drawable.serialize();
1837        let target_sbc_hi_bytes = self.target_sbc_hi.serialize();
1838        let target_sbc_lo_bytes = self.target_sbc_lo.serialize();
1839        let mut request0 = vec![
1840            major_opcode,
1841            WAIT_SBC_REQUEST,
1842            0,
1843            0,
1844            drawable_bytes[0],
1845            drawable_bytes[1],
1846            drawable_bytes[2],
1847            drawable_bytes[3],
1848            target_sbc_hi_bytes[0],
1849            target_sbc_hi_bytes[1],
1850            target_sbc_hi_bytes[2],
1851            target_sbc_hi_bytes[3],
1852            target_sbc_lo_bytes[0],
1853            target_sbc_lo_bytes[1],
1854            target_sbc_lo_bytes[2],
1855            target_sbc_lo_bytes[3],
1856        ];
1857        let length_so_far = length_so_far + request0.len();
1858        assert_eq!(length_so_far % 4, 0);
1859        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1860        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1861        ([request0.into()], vec![])
1862    }
1863    /// Parse this request given its header, its body, and any fds that go along with it
1864    #[cfg(feature = "request-parsing")]
1865    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1866        if header.minor_opcode != WAIT_SBC_REQUEST {
1867            return Err(ParseError::InvalidValue);
1868        }
1869        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1870        let (target_sbc_hi, remaining) = u32::try_parse(remaining)?;
1871        let (target_sbc_lo, remaining) = u32::try_parse(remaining)?;
1872        let _ = remaining;
1873        Ok(WaitSBCRequest {
1874            drawable,
1875            target_sbc_hi,
1876            target_sbc_lo,
1877        })
1878    }
1879}
1880impl Request for WaitSBCRequest {
1881    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1882
1883    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1884        let (bufs, fds) = self.serialize(major_opcode);
1885        // Flatten the buffers into a single vector
1886        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1887        (buf, fds)
1888    }
1889}
1890impl crate::x11_utils::ReplyRequest for WaitSBCRequest {
1891    type Reply = WaitSBCReply;
1892}
1893
1894#[derive(Clone, Copy, Default)]
1895#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1896#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1897pub struct WaitSBCReply {
1898    pub sequence: u16,
1899    pub length: u32,
1900    pub ust_hi: u32,
1901    pub ust_lo: u32,
1902    pub msc_hi: u32,
1903    pub msc_lo: u32,
1904    pub sbc_hi: u32,
1905    pub sbc_lo: u32,
1906}
1907impl_debug_if_no_extra_traits!(WaitSBCReply, "WaitSBCReply");
1908impl TryParse for WaitSBCReply {
1909    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1910        let remaining = initial_value;
1911        let (response_type, remaining) = u8::try_parse(remaining)?;
1912        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1913        let (sequence, remaining) = u16::try_parse(remaining)?;
1914        let (length, remaining) = u32::try_parse(remaining)?;
1915        let (ust_hi, remaining) = u32::try_parse(remaining)?;
1916        let (ust_lo, remaining) = u32::try_parse(remaining)?;
1917        let (msc_hi, remaining) = u32::try_parse(remaining)?;
1918        let (msc_lo, remaining) = u32::try_parse(remaining)?;
1919        let (sbc_hi, remaining) = u32::try_parse(remaining)?;
1920        let (sbc_lo, remaining) = u32::try_parse(remaining)?;
1921        if response_type != 1 {
1922            return Err(ParseError::InvalidValue);
1923        }
1924        let result = WaitSBCReply { sequence, length, ust_hi, ust_lo, msc_hi, msc_lo, sbc_hi, sbc_lo };
1925        let _ = remaining;
1926        let remaining = initial_value.get(32 + length as usize * 4..)
1927            .ok_or(ParseError::InsufficientData)?;
1928        Ok((result, remaining))
1929    }
1930}
1931impl Serialize for WaitSBCReply {
1932    type Bytes = [u8; 32];
1933    fn serialize(&self) -> [u8; 32] {
1934        let response_type_bytes = &[1];
1935        let sequence_bytes = self.sequence.serialize();
1936        let length_bytes = self.length.serialize();
1937        let ust_hi_bytes = self.ust_hi.serialize();
1938        let ust_lo_bytes = self.ust_lo.serialize();
1939        let msc_hi_bytes = self.msc_hi.serialize();
1940        let msc_lo_bytes = self.msc_lo.serialize();
1941        let sbc_hi_bytes = self.sbc_hi.serialize();
1942        let sbc_lo_bytes = self.sbc_lo.serialize();
1943        [
1944            response_type_bytes[0],
1945            0,
1946            sequence_bytes[0],
1947            sequence_bytes[1],
1948            length_bytes[0],
1949            length_bytes[1],
1950            length_bytes[2],
1951            length_bytes[3],
1952            ust_hi_bytes[0],
1953            ust_hi_bytes[1],
1954            ust_hi_bytes[2],
1955            ust_hi_bytes[3],
1956            ust_lo_bytes[0],
1957            ust_lo_bytes[1],
1958            ust_lo_bytes[2],
1959            ust_lo_bytes[3],
1960            msc_hi_bytes[0],
1961            msc_hi_bytes[1],
1962            msc_hi_bytes[2],
1963            msc_hi_bytes[3],
1964            msc_lo_bytes[0],
1965            msc_lo_bytes[1],
1966            msc_lo_bytes[2],
1967            msc_lo_bytes[3],
1968            sbc_hi_bytes[0],
1969            sbc_hi_bytes[1],
1970            sbc_hi_bytes[2],
1971            sbc_hi_bytes[3],
1972            sbc_lo_bytes[0],
1973            sbc_lo_bytes[1],
1974            sbc_lo_bytes[2],
1975            sbc_lo_bytes[3],
1976        ]
1977    }
1978    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1979        bytes.reserve(32);
1980        let response_type_bytes = &[1];
1981        bytes.push(response_type_bytes[0]);
1982        bytes.extend_from_slice(&[0; 1]);
1983        self.sequence.serialize_into(bytes);
1984        self.length.serialize_into(bytes);
1985        self.ust_hi.serialize_into(bytes);
1986        self.ust_lo.serialize_into(bytes);
1987        self.msc_hi.serialize_into(bytes);
1988        self.msc_lo.serialize_into(bytes);
1989        self.sbc_hi.serialize_into(bytes);
1990        self.sbc_lo.serialize_into(bytes);
1991    }
1992}
1993
1994/// Opcode for the SwapInterval request
1995pub const SWAP_INTERVAL_REQUEST: u8 = 12;
1996#[derive(Clone, Copy, Default)]
1997#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1998#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1999pub struct SwapIntervalRequest {
2000    pub drawable: xproto::Drawable,
2001    pub interval: u32,
2002}
2003impl_debug_if_no_extra_traits!(SwapIntervalRequest, "SwapIntervalRequest");
2004impl SwapIntervalRequest {
2005    /// Serialize this request into bytes for the provided connection
2006    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2007        let length_so_far = 0;
2008        let drawable_bytes = self.drawable.serialize();
2009        let interval_bytes = self.interval.serialize();
2010        let mut request0 = vec![
2011            major_opcode,
2012            SWAP_INTERVAL_REQUEST,
2013            0,
2014            0,
2015            drawable_bytes[0],
2016            drawable_bytes[1],
2017            drawable_bytes[2],
2018            drawable_bytes[3],
2019            interval_bytes[0],
2020            interval_bytes[1],
2021            interval_bytes[2],
2022            interval_bytes[3],
2023        ];
2024        let length_so_far = length_so_far + request0.len();
2025        assert_eq!(length_so_far % 4, 0);
2026        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2027        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2028        ([request0.into()], vec![])
2029    }
2030    /// Parse this request given its header, its body, and any fds that go along with it
2031    #[cfg(feature = "request-parsing")]
2032    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2033        if header.minor_opcode != SWAP_INTERVAL_REQUEST {
2034            return Err(ParseError::InvalidValue);
2035        }
2036        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
2037        let (interval, remaining) = u32::try_parse(remaining)?;
2038        let _ = remaining;
2039        Ok(SwapIntervalRequest {
2040            drawable,
2041            interval,
2042        })
2043    }
2044}
2045impl Request for SwapIntervalRequest {
2046    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2047
2048    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2049        let (bufs, fds) = self.serialize(major_opcode);
2050        // Flatten the buffers into a single vector
2051        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2052        (buf, fds)
2053    }
2054}
2055impl crate::x11_utils::VoidRequest for SwapIntervalRequest {
2056}
2057
2058/// Opcode for the GetParam request
2059pub const GET_PARAM_REQUEST: u8 = 13;
2060#[derive(Clone, Copy, Default)]
2061#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2062#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2063pub struct GetParamRequest {
2064    pub drawable: xproto::Drawable,
2065    pub param: u32,
2066}
2067impl_debug_if_no_extra_traits!(GetParamRequest, "GetParamRequest");
2068impl GetParamRequest {
2069    /// Serialize this request into bytes for the provided connection
2070    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2071        let length_so_far = 0;
2072        let drawable_bytes = self.drawable.serialize();
2073        let param_bytes = self.param.serialize();
2074        let mut request0 = vec![
2075            major_opcode,
2076            GET_PARAM_REQUEST,
2077            0,
2078            0,
2079            drawable_bytes[0],
2080            drawable_bytes[1],
2081            drawable_bytes[2],
2082            drawable_bytes[3],
2083            param_bytes[0],
2084            param_bytes[1],
2085            param_bytes[2],
2086            param_bytes[3],
2087        ];
2088        let length_so_far = length_so_far + request0.len();
2089        assert_eq!(length_so_far % 4, 0);
2090        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2091        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2092        ([request0.into()], vec![])
2093    }
2094    /// Parse this request given its header, its body, and any fds that go along with it
2095    #[cfg(feature = "request-parsing")]
2096    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2097        if header.minor_opcode != GET_PARAM_REQUEST {
2098            return Err(ParseError::InvalidValue);
2099        }
2100        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
2101        let (param, remaining) = u32::try_parse(remaining)?;
2102        let _ = remaining;
2103        Ok(GetParamRequest {
2104            drawable,
2105            param,
2106        })
2107    }
2108}
2109impl Request for GetParamRequest {
2110    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2111
2112    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2113        let (bufs, fds) = self.serialize(major_opcode);
2114        // Flatten the buffers into a single vector
2115        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2116        (buf, fds)
2117    }
2118}
2119impl crate::x11_utils::ReplyRequest for GetParamRequest {
2120    type Reply = GetParamReply;
2121}
2122
2123#[derive(Clone, Copy, Default)]
2124#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2125#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2126pub struct GetParamReply {
2127    pub is_param_recognized: bool,
2128    pub sequence: u16,
2129    pub length: u32,
2130    pub value_hi: u32,
2131    pub value_lo: u32,
2132}
2133impl_debug_if_no_extra_traits!(GetParamReply, "GetParamReply");
2134impl TryParse for GetParamReply {
2135    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2136        let remaining = initial_value;
2137        let (response_type, remaining) = u8::try_parse(remaining)?;
2138        let (is_param_recognized, remaining) = bool::try_parse(remaining)?;
2139        let (sequence, remaining) = u16::try_parse(remaining)?;
2140        let (length, remaining) = u32::try_parse(remaining)?;
2141        let (value_hi, remaining) = u32::try_parse(remaining)?;
2142        let (value_lo, remaining) = u32::try_parse(remaining)?;
2143        if response_type != 1 {
2144            return Err(ParseError::InvalidValue);
2145        }
2146        let result = GetParamReply { is_param_recognized, sequence, length, value_hi, value_lo };
2147        let _ = remaining;
2148        let remaining = initial_value.get(32 + length as usize * 4..)
2149            .ok_or(ParseError::InsufficientData)?;
2150        Ok((result, remaining))
2151    }
2152}
2153impl Serialize for GetParamReply {
2154    type Bytes = [u8; 16];
2155    fn serialize(&self) -> [u8; 16] {
2156        let response_type_bytes = &[1];
2157        let is_param_recognized_bytes = self.is_param_recognized.serialize();
2158        let sequence_bytes = self.sequence.serialize();
2159        let length_bytes = self.length.serialize();
2160        let value_hi_bytes = self.value_hi.serialize();
2161        let value_lo_bytes = self.value_lo.serialize();
2162        [
2163            response_type_bytes[0],
2164            is_param_recognized_bytes[0],
2165            sequence_bytes[0],
2166            sequence_bytes[1],
2167            length_bytes[0],
2168            length_bytes[1],
2169            length_bytes[2],
2170            length_bytes[3],
2171            value_hi_bytes[0],
2172            value_hi_bytes[1],
2173            value_hi_bytes[2],
2174            value_hi_bytes[3],
2175            value_lo_bytes[0],
2176            value_lo_bytes[1],
2177            value_lo_bytes[2],
2178            value_lo_bytes[3],
2179        ]
2180    }
2181    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2182        bytes.reserve(16);
2183        let response_type_bytes = &[1];
2184        bytes.push(response_type_bytes[0]);
2185        self.is_param_recognized.serialize_into(bytes);
2186        self.sequence.serialize_into(bytes);
2187        self.length.serialize_into(bytes);
2188        self.value_hi.serialize_into(bytes);
2189        self.value_lo.serialize_into(bytes);
2190    }
2191}
2192
2193/// Opcode for the BufferSwapComplete event
2194pub const BUFFER_SWAP_COMPLETE_EVENT: u8 = 0;
2195#[derive(Clone, Copy, Default)]
2196#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2197#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2198pub struct BufferSwapCompleteEvent {
2199    pub response_type: u8,
2200    pub sequence: u16,
2201    pub event_type: EventType,
2202    pub drawable: xproto::Drawable,
2203    pub ust_hi: u32,
2204    pub ust_lo: u32,
2205    pub msc_hi: u32,
2206    pub msc_lo: u32,
2207    pub sbc: u32,
2208}
2209impl_debug_if_no_extra_traits!(BufferSwapCompleteEvent, "BufferSwapCompleteEvent");
2210impl TryParse for BufferSwapCompleteEvent {
2211    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2212        let remaining = initial_value;
2213        let (response_type, remaining) = u8::try_parse(remaining)?;
2214        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2215        let (sequence, remaining) = u16::try_parse(remaining)?;
2216        let (event_type, remaining) = u16::try_parse(remaining)?;
2217        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2218        let (drawable, remaining) = xproto::Drawable::try_parse(remaining)?;
2219        let (ust_hi, remaining) = u32::try_parse(remaining)?;
2220        let (ust_lo, remaining) = u32::try_parse(remaining)?;
2221        let (msc_hi, remaining) = u32::try_parse(remaining)?;
2222        let (msc_lo, remaining) = u32::try_parse(remaining)?;
2223        let (sbc, remaining) = u32::try_parse(remaining)?;
2224        let event_type = event_type.into();
2225        let result = BufferSwapCompleteEvent { response_type, sequence, event_type, drawable, ust_hi, ust_lo, msc_hi, msc_lo, sbc };
2226        let _ = remaining;
2227        let remaining = initial_value.get(32..)
2228            .ok_or(ParseError::InsufficientData)?;
2229        Ok((result, remaining))
2230    }
2231}
2232impl Serialize for BufferSwapCompleteEvent {
2233    type Bytes = [u8; 32];
2234    fn serialize(&self) -> [u8; 32] {
2235        let response_type_bytes = self.response_type.serialize();
2236        let sequence_bytes = self.sequence.serialize();
2237        let event_type_bytes = u16::from(self.event_type).serialize();
2238        let drawable_bytes = self.drawable.serialize();
2239        let ust_hi_bytes = self.ust_hi.serialize();
2240        let ust_lo_bytes = self.ust_lo.serialize();
2241        let msc_hi_bytes = self.msc_hi.serialize();
2242        let msc_lo_bytes = self.msc_lo.serialize();
2243        let sbc_bytes = self.sbc.serialize();
2244        [
2245            response_type_bytes[0],
2246            0,
2247            sequence_bytes[0],
2248            sequence_bytes[1],
2249            event_type_bytes[0],
2250            event_type_bytes[1],
2251            0,
2252            0,
2253            drawable_bytes[0],
2254            drawable_bytes[1],
2255            drawable_bytes[2],
2256            drawable_bytes[3],
2257            ust_hi_bytes[0],
2258            ust_hi_bytes[1],
2259            ust_hi_bytes[2],
2260            ust_hi_bytes[3],
2261            ust_lo_bytes[0],
2262            ust_lo_bytes[1],
2263            ust_lo_bytes[2],
2264            ust_lo_bytes[3],
2265            msc_hi_bytes[0],
2266            msc_hi_bytes[1],
2267            msc_hi_bytes[2],
2268            msc_hi_bytes[3],
2269            msc_lo_bytes[0],
2270            msc_lo_bytes[1],
2271            msc_lo_bytes[2],
2272            msc_lo_bytes[3],
2273            sbc_bytes[0],
2274            sbc_bytes[1],
2275            sbc_bytes[2],
2276            sbc_bytes[3],
2277        ]
2278    }
2279    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2280        bytes.reserve(32);
2281        self.response_type.serialize_into(bytes);
2282        bytes.extend_from_slice(&[0; 1]);
2283        self.sequence.serialize_into(bytes);
2284        u16::from(self.event_type).serialize_into(bytes);
2285        bytes.extend_from_slice(&[0; 2]);
2286        self.drawable.serialize_into(bytes);
2287        self.ust_hi.serialize_into(bytes);
2288        self.ust_lo.serialize_into(bytes);
2289        self.msc_hi.serialize_into(bytes);
2290        self.msc_lo.serialize_into(bytes);
2291        self.sbc.serialize_into(bytes);
2292    }
2293}
2294impl From<&BufferSwapCompleteEvent> for [u8; 32] {
2295    fn from(input: &BufferSwapCompleteEvent) -> Self {
2296        let response_type_bytes = input.response_type.serialize();
2297        let sequence_bytes = input.sequence.serialize();
2298        let event_type_bytes = u16::from(input.event_type).serialize();
2299        let drawable_bytes = input.drawable.serialize();
2300        let ust_hi_bytes = input.ust_hi.serialize();
2301        let ust_lo_bytes = input.ust_lo.serialize();
2302        let msc_hi_bytes = input.msc_hi.serialize();
2303        let msc_lo_bytes = input.msc_lo.serialize();
2304        let sbc_bytes = input.sbc.serialize();
2305        [
2306            response_type_bytes[0],
2307            0,
2308            sequence_bytes[0],
2309            sequence_bytes[1],
2310            event_type_bytes[0],
2311            event_type_bytes[1],
2312            0,
2313            0,
2314            drawable_bytes[0],
2315            drawable_bytes[1],
2316            drawable_bytes[2],
2317            drawable_bytes[3],
2318            ust_hi_bytes[0],
2319            ust_hi_bytes[1],
2320            ust_hi_bytes[2],
2321            ust_hi_bytes[3],
2322            ust_lo_bytes[0],
2323            ust_lo_bytes[1],
2324            ust_lo_bytes[2],
2325            ust_lo_bytes[3],
2326            msc_hi_bytes[0],
2327            msc_hi_bytes[1],
2328            msc_hi_bytes[2],
2329            msc_hi_bytes[3],
2330            msc_lo_bytes[0],
2331            msc_lo_bytes[1],
2332            msc_lo_bytes[2],
2333            msc_lo_bytes[3],
2334            sbc_bytes[0],
2335            sbc_bytes[1],
2336            sbc_bytes[2],
2337            sbc_bytes[3],
2338        ]
2339    }
2340}
2341impl From<BufferSwapCompleteEvent> for [u8; 32] {
2342    fn from(input: BufferSwapCompleteEvent) -> Self {
2343        Self::from(&input)
2344    }
2345}
2346
2347/// Opcode for the InvalidateBuffers event
2348pub const INVALIDATE_BUFFERS_EVENT: u8 = 1;
2349#[derive(Clone, Copy, Default)]
2350#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2351#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2352pub struct InvalidateBuffersEvent {
2353    pub response_type: u8,
2354    pub sequence: u16,
2355    pub drawable: xproto::Drawable,
2356}
2357impl_debug_if_no_extra_traits!(InvalidateBuffersEvent, "InvalidateBuffersEvent");
2358impl TryParse for InvalidateBuffersEvent {
2359    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2360        let remaining = initial_value;
2361        let (response_type, remaining) = u8::try_parse(remaining)?;
2362        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2363        let (sequence, remaining) = u16::try_parse(remaining)?;
2364        let (drawable, remaining) = xproto::Drawable::try_parse(remaining)?;
2365        let result = InvalidateBuffersEvent { response_type, sequence, drawable };
2366        let _ = remaining;
2367        let remaining = initial_value.get(32..)
2368            .ok_or(ParseError::InsufficientData)?;
2369        Ok((result, remaining))
2370    }
2371}
2372impl Serialize for InvalidateBuffersEvent {
2373    type Bytes = [u8; 8];
2374    fn serialize(&self) -> [u8; 8] {
2375        let response_type_bytes = self.response_type.serialize();
2376        let sequence_bytes = self.sequence.serialize();
2377        let drawable_bytes = self.drawable.serialize();
2378        [
2379            response_type_bytes[0],
2380            0,
2381            sequence_bytes[0],
2382            sequence_bytes[1],
2383            drawable_bytes[0],
2384            drawable_bytes[1],
2385            drawable_bytes[2],
2386            drawable_bytes[3],
2387        ]
2388    }
2389    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2390        bytes.reserve(8);
2391        self.response_type.serialize_into(bytes);
2392        bytes.extend_from_slice(&[0; 1]);
2393        self.sequence.serialize_into(bytes);
2394        self.drawable.serialize_into(bytes);
2395    }
2396}
2397impl From<&InvalidateBuffersEvent> for [u8; 32] {
2398    fn from(input: &InvalidateBuffersEvent) -> Self {
2399        let response_type_bytes = input.response_type.serialize();
2400        let sequence_bytes = input.sequence.serialize();
2401        let drawable_bytes = input.drawable.serialize();
2402        [
2403            response_type_bytes[0],
2404            0,
2405            sequence_bytes[0],
2406            sequence_bytes[1],
2407            drawable_bytes[0],
2408            drawable_bytes[1],
2409            drawable_bytes[2],
2410            drawable_bytes[3],
2411            // trailing padding
2412            0,
2413            0,
2414            0,
2415            0,
2416            0,
2417            0,
2418            0,
2419            0,
2420            0,
2421            0,
2422            0,
2423            0,
2424            0,
2425            0,
2426            0,
2427            0,
2428            0,
2429            0,
2430            0,
2431            0,
2432            0,
2433            0,
2434            0,
2435            0,
2436        ]
2437    }
2438}
2439impl From<InvalidateBuffersEvent> for [u8; 32] {
2440    fn from(input: InvalidateBuffersEvent) -> Self {
2441        Self::from(&input)
2442    }
2443}
2444