x11rb_protocol/protocol/
xprint.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `XPrint` 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 = "XpExtension";
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, 0);
38
39pub type String8 = u8;
40
41#[derive(Clone, Default)]
42#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44pub struct Printer {
45    pub name: Vec<String8>,
46    pub description: Vec<String8>,
47}
48impl_debug_if_no_extra_traits!(Printer, "Printer");
49impl TryParse for Printer {
50    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
51        let value = remaining;
52        let (name_len, remaining) = u32::try_parse(remaining)?;
53        let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
54        let name = name.to_vec();
55        // Align offset to multiple of 4
56        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
57        let misalignment = (4 - (offset % 4)) % 4;
58        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
59        let (desc_len, remaining) = u32::try_parse(remaining)?;
60        let (description, remaining) = crate::x11_utils::parse_u8_list(remaining, desc_len.try_to_usize()?)?;
61        let description = description.to_vec();
62        // Align offset to multiple of 4
63        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
64        let misalignment = (4 - (offset % 4)) % 4;
65        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
66        let result = Printer { name, description };
67        Ok((result, remaining))
68    }
69}
70impl Serialize for Printer {
71    type Bytes = Vec<u8>;
72    fn serialize(&self) -> Vec<u8> {
73        let mut result = Vec::new();
74        self.serialize_into(&mut result);
75        result
76    }
77    fn serialize_into(&self, bytes: &mut Vec<u8>) {
78        let name_len = u32::try_from(self.name.len()).expect("`name` has too many elements");
79        name_len.serialize_into(bytes);
80        bytes.extend_from_slice(&self.name);
81        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
82        let desc_len = u32::try_from(self.description.len()).expect("`description` has too many elements");
83        desc_len.serialize_into(bytes);
84        bytes.extend_from_slice(&self.description);
85        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
86    }
87}
88impl Printer {
89    /// Get the value of the `nameLen` field.
90    ///
91    /// The `nameLen` field is used as the length field of the `name` field.
92    /// This function computes the field's value again based on the length of the list.
93    ///
94    /// # Panics
95    ///
96    /// Panics if the value cannot be represented in the target type. This
97    /// cannot happen with values of the struct received from the X11 server.
98    pub fn name_len(&self) -> u32 {
99        self.name.len()
100            .try_into().unwrap()
101    }
102    /// Get the value of the `descLen` field.
103    ///
104    /// The `descLen` field is used as the length field of the `description` field.
105    /// This function computes the field's value again based on the length of the list.
106    ///
107    /// # Panics
108    ///
109    /// Panics if the value cannot be represented in the target type. This
110    /// cannot happen with values of the struct received from the X11 server.
111    pub fn desc_len(&self) -> u32 {
112        self.description.len()
113            .try_into().unwrap()
114    }
115}
116
117pub type Pcontext = u32;
118
119#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
120#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
121pub struct GetDoc(bool);
122impl GetDoc {
123    pub const FINISHED: Self = Self(false);
124    pub const SECOND_CONSUMER: Self = Self(true);
125}
126impl From<GetDoc> for bool {
127    #[inline]
128    fn from(input: GetDoc) -> Self {
129        input.0
130    }
131}
132impl From<GetDoc> for Option<bool> {
133    #[inline]
134    fn from(input: GetDoc) -> Self {
135        Some(input.0)
136    }
137}
138impl From<GetDoc> for u8 {
139    #[inline]
140    fn from(input: GetDoc) -> Self {
141        u8::from(input.0)
142    }
143}
144impl From<GetDoc> for Option<u8> {
145    #[inline]
146    fn from(input: GetDoc) -> Self {
147        Some(u8::from(input.0))
148    }
149}
150impl From<GetDoc> for u16 {
151    #[inline]
152    fn from(input: GetDoc) -> Self {
153        u16::from(input.0)
154    }
155}
156impl From<GetDoc> for Option<u16> {
157    #[inline]
158    fn from(input: GetDoc) -> Self {
159        Some(u16::from(input.0))
160    }
161}
162impl From<GetDoc> for u32 {
163    #[inline]
164    fn from(input: GetDoc) -> Self {
165        u32::from(input.0)
166    }
167}
168impl From<GetDoc> for Option<u32> {
169    #[inline]
170    fn from(input: GetDoc) -> Self {
171        Some(u32::from(input.0))
172    }
173}
174impl From<bool> for GetDoc {
175    #[inline]
176    fn from(value: bool) -> Self {
177        Self(value)
178    }
179}
180impl core::fmt::Debug for GetDoc  {
181    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
182        let variants = [
183            (Self::FINISHED.0.into(), "FINISHED", "Finished"),
184            (Self::SECOND_CONSUMER.0.into(), "SECOND_CONSUMER", "SecondConsumer"),
185        ];
186        pretty_print_enum(fmt, self.0.into(), &variants)
187    }
188}
189
190#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
191#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
192pub struct EvMask(u8);
193impl EvMask {
194    pub const NO_EVENT_MASK: Self = Self(0);
195    pub const PRINT_MASK: Self = Self(1 << 0);
196    pub const ATTRIBUTE_MASK: Self = Self(1 << 1);
197}
198impl From<EvMask> for u8 {
199    #[inline]
200    fn from(input: EvMask) -> Self {
201        input.0
202    }
203}
204impl From<EvMask> for Option<u8> {
205    #[inline]
206    fn from(input: EvMask) -> Self {
207        Some(input.0)
208    }
209}
210impl From<EvMask> for u16 {
211    #[inline]
212    fn from(input: EvMask) -> Self {
213        u16::from(input.0)
214    }
215}
216impl From<EvMask> for Option<u16> {
217    #[inline]
218    fn from(input: EvMask) -> Self {
219        Some(u16::from(input.0))
220    }
221}
222impl From<EvMask> for u32 {
223    #[inline]
224    fn from(input: EvMask) -> Self {
225        u32::from(input.0)
226    }
227}
228impl From<EvMask> for Option<u32> {
229    #[inline]
230    fn from(input: EvMask) -> Self {
231        Some(u32::from(input.0))
232    }
233}
234impl From<u8> for EvMask {
235    #[inline]
236    fn from(value: u8) -> Self {
237        Self(value)
238    }
239}
240impl core::fmt::Debug for EvMask  {
241    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
242        let variants = [
243            (Self::NO_EVENT_MASK.0.into(), "NO_EVENT_MASK", "NoEventMask"),
244            (Self::PRINT_MASK.0.into(), "PRINT_MASK", "PrintMask"),
245            (Self::ATTRIBUTE_MASK.0.into(), "ATTRIBUTE_MASK", "AttributeMask"),
246        ];
247        pretty_print_bitmask(fmt, self.0.into(), &variants)
248    }
249}
250bitmask_binop!(EvMask, u8);
251
252#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
253#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
254pub struct Detail(u8);
255impl Detail {
256    pub const START_JOB_NOTIFY: Self = Self(1);
257    pub const END_JOB_NOTIFY: Self = Self(2);
258    pub const START_DOC_NOTIFY: Self = Self(3);
259    pub const END_DOC_NOTIFY: Self = Self(4);
260    pub const START_PAGE_NOTIFY: Self = Self(5);
261    pub const END_PAGE_NOTIFY: Self = Self(6);
262}
263impl From<Detail> for u8 {
264    #[inline]
265    fn from(input: Detail) -> Self {
266        input.0
267    }
268}
269impl From<Detail> for Option<u8> {
270    #[inline]
271    fn from(input: Detail) -> Self {
272        Some(input.0)
273    }
274}
275impl From<Detail> for u16 {
276    #[inline]
277    fn from(input: Detail) -> Self {
278        u16::from(input.0)
279    }
280}
281impl From<Detail> for Option<u16> {
282    #[inline]
283    fn from(input: Detail) -> Self {
284        Some(u16::from(input.0))
285    }
286}
287impl From<Detail> for u32 {
288    #[inline]
289    fn from(input: Detail) -> Self {
290        u32::from(input.0)
291    }
292}
293impl From<Detail> for Option<u32> {
294    #[inline]
295    fn from(input: Detail) -> Self {
296        Some(u32::from(input.0))
297    }
298}
299impl From<u8> for Detail {
300    #[inline]
301    fn from(value: u8) -> Self {
302        Self(value)
303    }
304}
305impl core::fmt::Debug for Detail  {
306    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
307        let variants = [
308            (Self::START_JOB_NOTIFY.0.into(), "START_JOB_NOTIFY", "StartJobNotify"),
309            (Self::END_JOB_NOTIFY.0.into(), "END_JOB_NOTIFY", "EndJobNotify"),
310            (Self::START_DOC_NOTIFY.0.into(), "START_DOC_NOTIFY", "StartDocNotify"),
311            (Self::END_DOC_NOTIFY.0.into(), "END_DOC_NOTIFY", "EndDocNotify"),
312            (Self::START_PAGE_NOTIFY.0.into(), "START_PAGE_NOTIFY", "StartPageNotify"),
313            (Self::END_PAGE_NOTIFY.0.into(), "END_PAGE_NOTIFY", "EndPageNotify"),
314        ];
315        pretty_print_enum(fmt, self.0.into(), &variants)
316    }
317}
318
319#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
320#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
321pub struct Attr(u8);
322impl Attr {
323    pub const JOB_ATTR: Self = Self(1);
324    pub const DOC_ATTR: Self = Self(2);
325    pub const PAGE_ATTR: Self = Self(3);
326    pub const PRINTER_ATTR: Self = Self(4);
327    pub const SERVER_ATTR: Self = Self(5);
328    pub const MEDIUM_ATTR: Self = Self(6);
329    pub const SPOOLER_ATTR: Self = Self(7);
330}
331impl From<Attr> for u8 {
332    #[inline]
333    fn from(input: Attr) -> Self {
334        input.0
335    }
336}
337impl From<Attr> for Option<u8> {
338    #[inline]
339    fn from(input: Attr) -> Self {
340        Some(input.0)
341    }
342}
343impl From<Attr> for u16 {
344    #[inline]
345    fn from(input: Attr) -> Self {
346        u16::from(input.0)
347    }
348}
349impl From<Attr> for Option<u16> {
350    #[inline]
351    fn from(input: Attr) -> Self {
352        Some(u16::from(input.0))
353    }
354}
355impl From<Attr> for u32 {
356    #[inline]
357    fn from(input: Attr) -> Self {
358        u32::from(input.0)
359    }
360}
361impl From<Attr> for Option<u32> {
362    #[inline]
363    fn from(input: Attr) -> Self {
364        Some(u32::from(input.0))
365    }
366}
367impl From<u8> for Attr {
368    #[inline]
369    fn from(value: u8) -> Self {
370        Self(value)
371    }
372}
373impl core::fmt::Debug for Attr  {
374    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
375        let variants = [
376            (Self::JOB_ATTR.0.into(), "JOB_ATTR", "JobAttr"),
377            (Self::DOC_ATTR.0.into(), "DOC_ATTR", "DocAttr"),
378            (Self::PAGE_ATTR.0.into(), "PAGE_ATTR", "PageAttr"),
379            (Self::PRINTER_ATTR.0.into(), "PRINTER_ATTR", "PrinterAttr"),
380            (Self::SERVER_ATTR.0.into(), "SERVER_ATTR", "ServerAttr"),
381            (Self::MEDIUM_ATTR.0.into(), "MEDIUM_ATTR", "MediumAttr"),
382            (Self::SPOOLER_ATTR.0.into(), "SPOOLER_ATTR", "SpoolerAttr"),
383        ];
384        pretty_print_enum(fmt, self.0.into(), &variants)
385    }
386}
387
388/// Opcode for the PrintQueryVersion request
389pub const PRINT_QUERY_VERSION_REQUEST: u8 = 0;
390#[derive(Clone, Copy, Default)]
391#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
392#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
393pub struct PrintQueryVersionRequest;
394impl_debug_if_no_extra_traits!(PrintQueryVersionRequest, "PrintQueryVersionRequest");
395impl PrintQueryVersionRequest {
396    /// Serialize this request into bytes for the provided connection
397    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
398        let length_so_far = 0;
399        let mut request0 = vec![
400            major_opcode,
401            PRINT_QUERY_VERSION_REQUEST,
402            0,
403            0,
404        ];
405        let length_so_far = length_so_far + request0.len();
406        assert_eq!(length_so_far % 4, 0);
407        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
408        request0[2..4].copy_from_slice(&length.to_ne_bytes());
409        ([request0.into()], vec![])
410    }
411    /// Parse this request given its header, its body, and any fds that go along with it
412    #[cfg(feature = "request-parsing")]
413    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
414        if header.minor_opcode != PRINT_QUERY_VERSION_REQUEST {
415            return Err(ParseError::InvalidValue);
416        }
417        let _ = value;
418        Ok(PrintQueryVersionRequest
419        )
420    }
421}
422impl Request for PrintQueryVersionRequest {
423    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
424
425    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
426        let (bufs, fds) = self.serialize(major_opcode);
427        // Flatten the buffers into a single vector
428        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
429        (buf, fds)
430    }
431}
432impl crate::x11_utils::ReplyRequest for PrintQueryVersionRequest {
433    type Reply = PrintQueryVersionReply;
434}
435
436#[derive(Clone, Copy, Default)]
437#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
438#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
439pub struct PrintQueryVersionReply {
440    pub sequence: u16,
441    pub length: u32,
442    pub major_version: u16,
443    pub minor_version: u16,
444}
445impl_debug_if_no_extra_traits!(PrintQueryVersionReply, "PrintQueryVersionReply");
446impl TryParse for PrintQueryVersionReply {
447    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
448        let remaining = initial_value;
449        let (response_type, remaining) = u8::try_parse(remaining)?;
450        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
451        let (sequence, remaining) = u16::try_parse(remaining)?;
452        let (length, remaining) = u32::try_parse(remaining)?;
453        let (major_version, remaining) = u16::try_parse(remaining)?;
454        let (minor_version, remaining) = u16::try_parse(remaining)?;
455        if response_type != 1 {
456            return Err(ParseError::InvalidValue);
457        }
458        let result = PrintQueryVersionReply { sequence, length, major_version, minor_version };
459        let _ = remaining;
460        let remaining = initial_value.get(32 + length as usize * 4..)
461            .ok_or(ParseError::InsufficientData)?;
462        Ok((result, remaining))
463    }
464}
465impl Serialize for PrintQueryVersionReply {
466    type Bytes = [u8; 12];
467    fn serialize(&self) -> [u8; 12] {
468        let response_type_bytes = &[1];
469        let sequence_bytes = self.sequence.serialize();
470        let length_bytes = self.length.serialize();
471        let major_version_bytes = self.major_version.serialize();
472        let minor_version_bytes = self.minor_version.serialize();
473        [
474            response_type_bytes[0],
475            0,
476            sequence_bytes[0],
477            sequence_bytes[1],
478            length_bytes[0],
479            length_bytes[1],
480            length_bytes[2],
481            length_bytes[3],
482            major_version_bytes[0],
483            major_version_bytes[1],
484            minor_version_bytes[0],
485            minor_version_bytes[1],
486        ]
487    }
488    fn serialize_into(&self, bytes: &mut Vec<u8>) {
489        bytes.reserve(12);
490        let response_type_bytes = &[1];
491        bytes.push(response_type_bytes[0]);
492        bytes.extend_from_slice(&[0; 1]);
493        self.sequence.serialize_into(bytes);
494        self.length.serialize_into(bytes);
495        self.major_version.serialize_into(bytes);
496        self.minor_version.serialize_into(bytes);
497    }
498}
499
500/// Opcode for the PrintGetPrinterList request
501pub const PRINT_GET_PRINTER_LIST_REQUEST: u8 = 1;
502#[derive(Clone, Default)]
503#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
504#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
505pub struct PrintGetPrinterListRequest<'input> {
506    pub printer_name: Cow<'input, [String8]>,
507    pub locale: Cow<'input, [String8]>,
508}
509impl_debug_if_no_extra_traits!(PrintGetPrinterListRequest<'_>, "PrintGetPrinterListRequest");
510impl<'input> PrintGetPrinterListRequest<'input> {
511    /// Serialize this request into bytes for the provided connection
512    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 5]> {
513        let length_so_far = 0;
514        let printer_name_len = u32::try_from(self.printer_name.len()).expect("`printer_name` has too many elements");
515        let printer_name_len_bytes = printer_name_len.serialize();
516        let locale_len = u32::try_from(self.locale.len()).expect("`locale` has too many elements");
517        let locale_len_bytes = locale_len.serialize();
518        let mut request0 = vec![
519            major_opcode,
520            PRINT_GET_PRINTER_LIST_REQUEST,
521            0,
522            0,
523            printer_name_len_bytes[0],
524            printer_name_len_bytes[1],
525            printer_name_len_bytes[2],
526            printer_name_len_bytes[3],
527            locale_len_bytes[0],
528            locale_len_bytes[1],
529            locale_len_bytes[2],
530            locale_len_bytes[3],
531        ];
532        let length_so_far = length_so_far + request0.len();
533        let length_so_far = length_so_far + self.printer_name.len();
534        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
535        let length_so_far = length_so_far + padding0.len();
536        let length_so_far = length_so_far + self.locale.len();
537        let padding1 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
538        let length_so_far = length_so_far + padding1.len();
539        assert_eq!(length_so_far % 4, 0);
540        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
541        request0[2..4].copy_from_slice(&length.to_ne_bytes());
542        ([request0.into(), self.printer_name, padding0.into(), self.locale, padding1.into()], vec![])
543    }
544    /// Parse this request given its header, its body, and any fds that go along with it
545    #[cfg(feature = "request-parsing")]
546    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
547        if header.minor_opcode != PRINT_GET_PRINTER_LIST_REQUEST {
548            return Err(ParseError::InvalidValue);
549        }
550        let (printer_name_len, remaining) = u32::try_parse(value)?;
551        let (locale_len, remaining) = u32::try_parse(remaining)?;
552        let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_to_usize()?)?;
553        // Align offset to multiple of 4
554        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
555        let misalignment = (4 - (offset % 4)) % 4;
556        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
557        let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_to_usize()?)?;
558        let _ = remaining;
559        Ok(PrintGetPrinterListRequest {
560            printer_name: Cow::Borrowed(printer_name),
561            locale: Cow::Borrowed(locale),
562        })
563    }
564    /// Clone all borrowed data in this PrintGetPrinterListRequest.
565    pub fn into_owned(self) -> PrintGetPrinterListRequest<'static> {
566        PrintGetPrinterListRequest {
567            printer_name: Cow::Owned(self.printer_name.into_owned()),
568            locale: Cow::Owned(self.locale.into_owned()),
569        }
570    }
571}
572impl<'input> Request for PrintGetPrinterListRequest<'input> {
573    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
574
575    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
576        let (bufs, fds) = self.serialize(major_opcode);
577        // Flatten the buffers into a single vector
578        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
579        (buf, fds)
580    }
581}
582impl<'input> crate::x11_utils::ReplyRequest for PrintGetPrinterListRequest<'input> {
583    type Reply = PrintGetPrinterListReply;
584}
585
586#[derive(Clone, Default)]
587#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
588#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
589pub struct PrintGetPrinterListReply {
590    pub sequence: u16,
591    pub length: u32,
592    pub printers: Vec<Printer>,
593}
594impl_debug_if_no_extra_traits!(PrintGetPrinterListReply, "PrintGetPrinterListReply");
595impl TryParse for PrintGetPrinterListReply {
596    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
597        let remaining = initial_value;
598        let (response_type, remaining) = u8::try_parse(remaining)?;
599        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
600        let (sequence, remaining) = u16::try_parse(remaining)?;
601        let (length, remaining) = u32::try_parse(remaining)?;
602        let (list_count, remaining) = u32::try_parse(remaining)?;
603        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
604        let (printers, remaining) = crate::x11_utils::parse_list::<Printer>(remaining, list_count.try_to_usize()?)?;
605        if response_type != 1 {
606            return Err(ParseError::InvalidValue);
607        }
608        let result = PrintGetPrinterListReply { sequence, length, printers };
609        let _ = remaining;
610        let remaining = initial_value.get(32 + length as usize * 4..)
611            .ok_or(ParseError::InsufficientData)?;
612        Ok((result, remaining))
613    }
614}
615impl Serialize for PrintGetPrinterListReply {
616    type Bytes = Vec<u8>;
617    fn serialize(&self) -> Vec<u8> {
618        let mut result = Vec::new();
619        self.serialize_into(&mut result);
620        result
621    }
622    fn serialize_into(&self, bytes: &mut Vec<u8>) {
623        bytes.reserve(32);
624        let response_type_bytes = &[1];
625        bytes.push(response_type_bytes[0]);
626        bytes.extend_from_slice(&[0; 1]);
627        self.sequence.serialize_into(bytes);
628        self.length.serialize_into(bytes);
629        let list_count = u32::try_from(self.printers.len()).expect("`printers` has too many elements");
630        list_count.serialize_into(bytes);
631        bytes.extend_from_slice(&[0; 20]);
632        self.printers.serialize_into(bytes);
633    }
634}
635impl PrintGetPrinterListReply {
636    /// Get the value of the `listCount` field.
637    ///
638    /// The `listCount` field is used as the length field of the `printers` field.
639    /// This function computes the field's value again based on the length of the list.
640    ///
641    /// # Panics
642    ///
643    /// Panics if the value cannot be represented in the target type. This
644    /// cannot happen with values of the struct received from the X11 server.
645    pub fn list_count(&self) -> u32 {
646        self.printers.len()
647            .try_into().unwrap()
648    }
649}
650
651/// Opcode for the PrintRehashPrinterList request
652pub const PRINT_REHASH_PRINTER_LIST_REQUEST: u8 = 20;
653#[derive(Clone, Copy, Default)]
654#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
655#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
656pub struct PrintRehashPrinterListRequest;
657impl_debug_if_no_extra_traits!(PrintRehashPrinterListRequest, "PrintRehashPrinterListRequest");
658impl PrintRehashPrinterListRequest {
659    /// Serialize this request into bytes for the provided connection
660    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
661        let length_so_far = 0;
662        let mut request0 = vec![
663            major_opcode,
664            PRINT_REHASH_PRINTER_LIST_REQUEST,
665            0,
666            0,
667        ];
668        let length_so_far = length_so_far + request0.len();
669        assert_eq!(length_so_far % 4, 0);
670        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
671        request0[2..4].copy_from_slice(&length.to_ne_bytes());
672        ([request0.into()], vec![])
673    }
674    /// Parse this request given its header, its body, and any fds that go along with it
675    #[cfg(feature = "request-parsing")]
676    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
677        if header.minor_opcode != PRINT_REHASH_PRINTER_LIST_REQUEST {
678            return Err(ParseError::InvalidValue);
679        }
680        let _ = value;
681        Ok(PrintRehashPrinterListRequest
682        )
683    }
684}
685impl Request for PrintRehashPrinterListRequest {
686    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
687
688    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
689        let (bufs, fds) = self.serialize(major_opcode);
690        // Flatten the buffers into a single vector
691        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
692        (buf, fds)
693    }
694}
695impl crate::x11_utils::VoidRequest for PrintRehashPrinterListRequest {
696}
697
698/// Opcode for the CreateContext request
699pub const CREATE_CONTEXT_REQUEST: u8 = 2;
700#[derive(Clone, Default)]
701#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
702#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
703pub struct CreateContextRequest<'input> {
704    pub context_id: u32,
705    pub printer_name: Cow<'input, [String8]>,
706    pub locale: Cow<'input, [String8]>,
707}
708impl_debug_if_no_extra_traits!(CreateContextRequest<'_>, "CreateContextRequest");
709impl<'input> CreateContextRequest<'input> {
710    /// Serialize this request into bytes for the provided connection
711    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 5]> {
712        let length_so_far = 0;
713        let context_id_bytes = self.context_id.serialize();
714        let printer_name_len = u32::try_from(self.printer_name.len()).expect("`printer_name` has too many elements");
715        let printer_name_len_bytes = printer_name_len.serialize();
716        let locale_len = u32::try_from(self.locale.len()).expect("`locale` has too many elements");
717        let locale_len_bytes = locale_len.serialize();
718        let mut request0 = vec![
719            major_opcode,
720            CREATE_CONTEXT_REQUEST,
721            0,
722            0,
723            context_id_bytes[0],
724            context_id_bytes[1],
725            context_id_bytes[2],
726            context_id_bytes[3],
727            printer_name_len_bytes[0],
728            printer_name_len_bytes[1],
729            printer_name_len_bytes[2],
730            printer_name_len_bytes[3],
731            locale_len_bytes[0],
732            locale_len_bytes[1],
733            locale_len_bytes[2],
734            locale_len_bytes[3],
735        ];
736        let length_so_far = length_so_far + request0.len();
737        let length_so_far = length_so_far + self.printer_name.len();
738        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
739        let length_so_far = length_so_far + padding0.len();
740        let length_so_far = length_so_far + self.locale.len();
741        let padding1 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
742        let length_so_far = length_so_far + padding1.len();
743        assert_eq!(length_so_far % 4, 0);
744        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
745        request0[2..4].copy_from_slice(&length.to_ne_bytes());
746        ([request0.into(), self.printer_name, padding0.into(), self.locale, padding1.into()], vec![])
747    }
748    /// Parse this request given its header, its body, and any fds that go along with it
749    #[cfg(feature = "request-parsing")]
750    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
751        if header.minor_opcode != CREATE_CONTEXT_REQUEST {
752            return Err(ParseError::InvalidValue);
753        }
754        let (context_id, remaining) = u32::try_parse(value)?;
755        let (printer_name_len, remaining) = u32::try_parse(remaining)?;
756        let (locale_len, remaining) = u32::try_parse(remaining)?;
757        let (printer_name, remaining) = crate::x11_utils::parse_u8_list(remaining, printer_name_len.try_to_usize()?)?;
758        // Align offset to multiple of 4
759        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
760        let misalignment = (4 - (offset % 4)) % 4;
761        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
762        let (locale, remaining) = crate::x11_utils::parse_u8_list(remaining, locale_len.try_to_usize()?)?;
763        let _ = remaining;
764        Ok(CreateContextRequest {
765            context_id,
766            printer_name: Cow::Borrowed(printer_name),
767            locale: Cow::Borrowed(locale),
768        })
769    }
770    /// Clone all borrowed data in this CreateContextRequest.
771    pub fn into_owned(self) -> CreateContextRequest<'static> {
772        CreateContextRequest {
773            context_id: self.context_id,
774            printer_name: Cow::Owned(self.printer_name.into_owned()),
775            locale: Cow::Owned(self.locale.into_owned()),
776        }
777    }
778}
779impl<'input> Request for CreateContextRequest<'input> {
780    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
781
782    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
783        let (bufs, fds) = self.serialize(major_opcode);
784        // Flatten the buffers into a single vector
785        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
786        (buf, fds)
787    }
788}
789impl<'input> crate::x11_utils::VoidRequest for CreateContextRequest<'input> {
790}
791
792/// Opcode for the PrintSetContext request
793pub const PRINT_SET_CONTEXT_REQUEST: u8 = 3;
794#[derive(Clone, Copy, Default)]
795#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
796#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
797pub struct PrintSetContextRequest {
798    pub context: u32,
799}
800impl_debug_if_no_extra_traits!(PrintSetContextRequest, "PrintSetContextRequest");
801impl PrintSetContextRequest {
802    /// Serialize this request into bytes for the provided connection
803    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
804        let length_so_far = 0;
805        let context_bytes = self.context.serialize();
806        let mut request0 = vec![
807            major_opcode,
808            PRINT_SET_CONTEXT_REQUEST,
809            0,
810            0,
811            context_bytes[0],
812            context_bytes[1],
813            context_bytes[2],
814            context_bytes[3],
815        ];
816        let length_so_far = length_so_far + request0.len();
817        assert_eq!(length_so_far % 4, 0);
818        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
819        request0[2..4].copy_from_slice(&length.to_ne_bytes());
820        ([request0.into()], vec![])
821    }
822    /// Parse this request given its header, its body, and any fds that go along with it
823    #[cfg(feature = "request-parsing")]
824    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
825        if header.minor_opcode != PRINT_SET_CONTEXT_REQUEST {
826            return Err(ParseError::InvalidValue);
827        }
828        let (context, remaining) = u32::try_parse(value)?;
829        let _ = remaining;
830        Ok(PrintSetContextRequest {
831            context,
832        })
833    }
834}
835impl Request for PrintSetContextRequest {
836    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
837
838    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
839        let (bufs, fds) = self.serialize(major_opcode);
840        // Flatten the buffers into a single vector
841        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
842        (buf, fds)
843    }
844}
845impl crate::x11_utils::VoidRequest for PrintSetContextRequest {
846}
847
848/// Opcode for the PrintGetContext request
849pub const PRINT_GET_CONTEXT_REQUEST: u8 = 4;
850#[derive(Clone, Copy, Default)]
851#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
852#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
853pub struct PrintGetContextRequest;
854impl_debug_if_no_extra_traits!(PrintGetContextRequest, "PrintGetContextRequest");
855impl PrintGetContextRequest {
856    /// Serialize this request into bytes for the provided connection
857    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
858        let length_so_far = 0;
859        let mut request0 = vec![
860            major_opcode,
861            PRINT_GET_CONTEXT_REQUEST,
862            0,
863            0,
864        ];
865        let length_so_far = length_so_far + request0.len();
866        assert_eq!(length_so_far % 4, 0);
867        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
868        request0[2..4].copy_from_slice(&length.to_ne_bytes());
869        ([request0.into()], vec![])
870    }
871    /// Parse this request given its header, its body, and any fds that go along with it
872    #[cfg(feature = "request-parsing")]
873    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
874        if header.minor_opcode != PRINT_GET_CONTEXT_REQUEST {
875            return Err(ParseError::InvalidValue);
876        }
877        let _ = value;
878        Ok(PrintGetContextRequest
879        )
880    }
881}
882impl Request for PrintGetContextRequest {
883    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
884
885    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
886        let (bufs, fds) = self.serialize(major_opcode);
887        // Flatten the buffers into a single vector
888        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
889        (buf, fds)
890    }
891}
892impl crate::x11_utils::ReplyRequest for PrintGetContextRequest {
893    type Reply = PrintGetContextReply;
894}
895
896#[derive(Clone, Copy, Default)]
897#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
898#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
899pub struct PrintGetContextReply {
900    pub sequence: u16,
901    pub length: u32,
902    pub context: u32,
903}
904impl_debug_if_no_extra_traits!(PrintGetContextReply, "PrintGetContextReply");
905impl TryParse for PrintGetContextReply {
906    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
907        let remaining = initial_value;
908        let (response_type, remaining) = u8::try_parse(remaining)?;
909        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
910        let (sequence, remaining) = u16::try_parse(remaining)?;
911        let (length, remaining) = u32::try_parse(remaining)?;
912        let (context, remaining) = u32::try_parse(remaining)?;
913        if response_type != 1 {
914            return Err(ParseError::InvalidValue);
915        }
916        let result = PrintGetContextReply { sequence, length, context };
917        let _ = remaining;
918        let remaining = initial_value.get(32 + length as usize * 4..)
919            .ok_or(ParseError::InsufficientData)?;
920        Ok((result, remaining))
921    }
922}
923impl Serialize for PrintGetContextReply {
924    type Bytes = [u8; 12];
925    fn serialize(&self) -> [u8; 12] {
926        let response_type_bytes = &[1];
927        let sequence_bytes = self.sequence.serialize();
928        let length_bytes = self.length.serialize();
929        let context_bytes = self.context.serialize();
930        [
931            response_type_bytes[0],
932            0,
933            sequence_bytes[0],
934            sequence_bytes[1],
935            length_bytes[0],
936            length_bytes[1],
937            length_bytes[2],
938            length_bytes[3],
939            context_bytes[0],
940            context_bytes[1],
941            context_bytes[2],
942            context_bytes[3],
943        ]
944    }
945    fn serialize_into(&self, bytes: &mut Vec<u8>) {
946        bytes.reserve(12);
947        let response_type_bytes = &[1];
948        bytes.push(response_type_bytes[0]);
949        bytes.extend_from_slice(&[0; 1]);
950        self.sequence.serialize_into(bytes);
951        self.length.serialize_into(bytes);
952        self.context.serialize_into(bytes);
953    }
954}
955
956/// Opcode for the PrintDestroyContext request
957pub const PRINT_DESTROY_CONTEXT_REQUEST: u8 = 5;
958#[derive(Clone, Copy, Default)]
959#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
960#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
961pub struct PrintDestroyContextRequest {
962    pub context: u32,
963}
964impl_debug_if_no_extra_traits!(PrintDestroyContextRequest, "PrintDestroyContextRequest");
965impl PrintDestroyContextRequest {
966    /// Serialize this request into bytes for the provided connection
967    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
968        let length_so_far = 0;
969        let context_bytes = self.context.serialize();
970        let mut request0 = vec![
971            major_opcode,
972            PRINT_DESTROY_CONTEXT_REQUEST,
973            0,
974            0,
975            context_bytes[0],
976            context_bytes[1],
977            context_bytes[2],
978            context_bytes[3],
979        ];
980        let length_so_far = length_so_far + request0.len();
981        assert_eq!(length_so_far % 4, 0);
982        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
983        request0[2..4].copy_from_slice(&length.to_ne_bytes());
984        ([request0.into()], vec![])
985    }
986    /// Parse this request given its header, its body, and any fds that go along with it
987    #[cfg(feature = "request-parsing")]
988    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
989        if header.minor_opcode != PRINT_DESTROY_CONTEXT_REQUEST {
990            return Err(ParseError::InvalidValue);
991        }
992        let (context, remaining) = u32::try_parse(value)?;
993        let _ = remaining;
994        Ok(PrintDestroyContextRequest {
995            context,
996        })
997    }
998}
999impl Request for PrintDestroyContextRequest {
1000    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1001
1002    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1003        let (bufs, fds) = self.serialize(major_opcode);
1004        // Flatten the buffers into a single vector
1005        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1006        (buf, fds)
1007    }
1008}
1009impl crate::x11_utils::VoidRequest for PrintDestroyContextRequest {
1010}
1011
1012/// Opcode for the PrintGetScreenOfContext request
1013pub const PRINT_GET_SCREEN_OF_CONTEXT_REQUEST: u8 = 6;
1014#[derive(Clone, Copy, Default)]
1015#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1016#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1017pub struct PrintGetScreenOfContextRequest;
1018impl_debug_if_no_extra_traits!(PrintGetScreenOfContextRequest, "PrintGetScreenOfContextRequest");
1019impl PrintGetScreenOfContextRequest {
1020    /// Serialize this request into bytes for the provided connection
1021    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1022        let length_so_far = 0;
1023        let mut request0 = vec![
1024            major_opcode,
1025            PRINT_GET_SCREEN_OF_CONTEXT_REQUEST,
1026            0,
1027            0,
1028        ];
1029        let length_so_far = length_so_far + request0.len();
1030        assert_eq!(length_so_far % 4, 0);
1031        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1032        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1033        ([request0.into()], vec![])
1034    }
1035    /// Parse this request given its header, its body, and any fds that go along with it
1036    #[cfg(feature = "request-parsing")]
1037    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1038        if header.minor_opcode != PRINT_GET_SCREEN_OF_CONTEXT_REQUEST {
1039            return Err(ParseError::InvalidValue);
1040        }
1041        let _ = value;
1042        Ok(PrintGetScreenOfContextRequest
1043        )
1044    }
1045}
1046impl Request for PrintGetScreenOfContextRequest {
1047    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1048
1049    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1050        let (bufs, fds) = self.serialize(major_opcode);
1051        // Flatten the buffers into a single vector
1052        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1053        (buf, fds)
1054    }
1055}
1056impl crate::x11_utils::ReplyRequest for PrintGetScreenOfContextRequest {
1057    type Reply = PrintGetScreenOfContextReply;
1058}
1059
1060#[derive(Clone, Copy, Default)]
1061#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1062#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1063pub struct PrintGetScreenOfContextReply {
1064    pub sequence: u16,
1065    pub length: u32,
1066    pub root: xproto::Window,
1067}
1068impl_debug_if_no_extra_traits!(PrintGetScreenOfContextReply, "PrintGetScreenOfContextReply");
1069impl TryParse for PrintGetScreenOfContextReply {
1070    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1071        let remaining = initial_value;
1072        let (response_type, remaining) = u8::try_parse(remaining)?;
1073        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1074        let (sequence, remaining) = u16::try_parse(remaining)?;
1075        let (length, remaining) = u32::try_parse(remaining)?;
1076        let (root, remaining) = xproto::Window::try_parse(remaining)?;
1077        if response_type != 1 {
1078            return Err(ParseError::InvalidValue);
1079        }
1080        let result = PrintGetScreenOfContextReply { sequence, length, root };
1081        let _ = remaining;
1082        let remaining = initial_value.get(32 + length as usize * 4..)
1083            .ok_or(ParseError::InsufficientData)?;
1084        Ok((result, remaining))
1085    }
1086}
1087impl Serialize for PrintGetScreenOfContextReply {
1088    type Bytes = [u8; 12];
1089    fn serialize(&self) -> [u8; 12] {
1090        let response_type_bytes = &[1];
1091        let sequence_bytes = self.sequence.serialize();
1092        let length_bytes = self.length.serialize();
1093        let root_bytes = self.root.serialize();
1094        [
1095            response_type_bytes[0],
1096            0,
1097            sequence_bytes[0],
1098            sequence_bytes[1],
1099            length_bytes[0],
1100            length_bytes[1],
1101            length_bytes[2],
1102            length_bytes[3],
1103            root_bytes[0],
1104            root_bytes[1],
1105            root_bytes[2],
1106            root_bytes[3],
1107        ]
1108    }
1109    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1110        bytes.reserve(12);
1111        let response_type_bytes = &[1];
1112        bytes.push(response_type_bytes[0]);
1113        bytes.extend_from_slice(&[0; 1]);
1114        self.sequence.serialize_into(bytes);
1115        self.length.serialize_into(bytes);
1116        self.root.serialize_into(bytes);
1117    }
1118}
1119
1120/// Opcode for the PrintStartJob request
1121pub const PRINT_START_JOB_REQUEST: u8 = 7;
1122#[derive(Clone, Copy, Default)]
1123#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1124#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1125pub struct PrintStartJobRequest {
1126    pub output_mode: u8,
1127}
1128impl_debug_if_no_extra_traits!(PrintStartJobRequest, "PrintStartJobRequest");
1129impl PrintStartJobRequest {
1130    /// Serialize this request into bytes for the provided connection
1131    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1132        let length_so_far = 0;
1133        let output_mode_bytes = self.output_mode.serialize();
1134        let mut request0 = vec![
1135            major_opcode,
1136            PRINT_START_JOB_REQUEST,
1137            0,
1138            0,
1139            output_mode_bytes[0],
1140            0,
1141            0,
1142            0,
1143        ];
1144        let length_so_far = length_so_far + request0.len();
1145        assert_eq!(length_so_far % 4, 0);
1146        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1147        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1148        ([request0.into()], vec![])
1149    }
1150    /// Parse this request given its header, its body, and any fds that go along with it
1151    #[cfg(feature = "request-parsing")]
1152    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1153        if header.minor_opcode != PRINT_START_JOB_REQUEST {
1154            return Err(ParseError::InvalidValue);
1155        }
1156        let (output_mode, remaining) = u8::try_parse(value)?;
1157        let _ = remaining;
1158        Ok(PrintStartJobRequest {
1159            output_mode,
1160        })
1161    }
1162}
1163impl Request for PrintStartJobRequest {
1164    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1165
1166    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1167        let (bufs, fds) = self.serialize(major_opcode);
1168        // Flatten the buffers into a single vector
1169        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1170        (buf, fds)
1171    }
1172}
1173impl crate::x11_utils::VoidRequest for PrintStartJobRequest {
1174}
1175
1176/// Opcode for the PrintEndJob request
1177pub const PRINT_END_JOB_REQUEST: u8 = 8;
1178#[derive(Clone, Copy, Default)]
1179#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1180#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1181pub struct PrintEndJobRequest {
1182    pub cancel: bool,
1183}
1184impl_debug_if_no_extra_traits!(PrintEndJobRequest, "PrintEndJobRequest");
1185impl PrintEndJobRequest {
1186    /// Serialize this request into bytes for the provided connection
1187    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1188        let length_so_far = 0;
1189        let cancel_bytes = self.cancel.serialize();
1190        let mut request0 = vec![
1191            major_opcode,
1192            PRINT_END_JOB_REQUEST,
1193            0,
1194            0,
1195            cancel_bytes[0],
1196            0,
1197            0,
1198            0,
1199        ];
1200        let length_so_far = length_so_far + request0.len();
1201        assert_eq!(length_so_far % 4, 0);
1202        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1203        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1204        ([request0.into()], vec![])
1205    }
1206    /// Parse this request given its header, its body, and any fds that go along with it
1207    #[cfg(feature = "request-parsing")]
1208    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1209        if header.minor_opcode != PRINT_END_JOB_REQUEST {
1210            return Err(ParseError::InvalidValue);
1211        }
1212        let (cancel, remaining) = bool::try_parse(value)?;
1213        let _ = remaining;
1214        Ok(PrintEndJobRequest {
1215            cancel,
1216        })
1217    }
1218}
1219impl Request for PrintEndJobRequest {
1220    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1221
1222    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1223        let (bufs, fds) = self.serialize(major_opcode);
1224        // Flatten the buffers into a single vector
1225        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1226        (buf, fds)
1227    }
1228}
1229impl crate::x11_utils::VoidRequest for PrintEndJobRequest {
1230}
1231
1232/// Opcode for the PrintStartDoc request
1233pub const PRINT_START_DOC_REQUEST: u8 = 9;
1234#[derive(Clone, Copy, Default)]
1235#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1236#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1237pub struct PrintStartDocRequest {
1238    pub driver_mode: u8,
1239}
1240impl_debug_if_no_extra_traits!(PrintStartDocRequest, "PrintStartDocRequest");
1241impl PrintStartDocRequest {
1242    /// Serialize this request into bytes for the provided connection
1243    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1244        let length_so_far = 0;
1245        let driver_mode_bytes = self.driver_mode.serialize();
1246        let mut request0 = vec![
1247            major_opcode,
1248            PRINT_START_DOC_REQUEST,
1249            0,
1250            0,
1251            driver_mode_bytes[0],
1252            0,
1253            0,
1254            0,
1255        ];
1256        let length_so_far = length_so_far + request0.len();
1257        assert_eq!(length_so_far % 4, 0);
1258        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1259        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1260        ([request0.into()], vec![])
1261    }
1262    /// Parse this request given its header, its body, and any fds that go along with it
1263    #[cfg(feature = "request-parsing")]
1264    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1265        if header.minor_opcode != PRINT_START_DOC_REQUEST {
1266            return Err(ParseError::InvalidValue);
1267        }
1268        let (driver_mode, remaining) = u8::try_parse(value)?;
1269        let _ = remaining;
1270        Ok(PrintStartDocRequest {
1271            driver_mode,
1272        })
1273    }
1274}
1275impl Request for PrintStartDocRequest {
1276    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1277
1278    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1279        let (bufs, fds) = self.serialize(major_opcode);
1280        // Flatten the buffers into a single vector
1281        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1282        (buf, fds)
1283    }
1284}
1285impl crate::x11_utils::VoidRequest for PrintStartDocRequest {
1286}
1287
1288/// Opcode for the PrintEndDoc request
1289pub const PRINT_END_DOC_REQUEST: u8 = 10;
1290#[derive(Clone, Copy, Default)]
1291#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1292#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1293pub struct PrintEndDocRequest {
1294    pub cancel: bool,
1295}
1296impl_debug_if_no_extra_traits!(PrintEndDocRequest, "PrintEndDocRequest");
1297impl PrintEndDocRequest {
1298    /// Serialize this request into bytes for the provided connection
1299    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1300        let length_so_far = 0;
1301        let cancel_bytes = self.cancel.serialize();
1302        let mut request0 = vec![
1303            major_opcode,
1304            PRINT_END_DOC_REQUEST,
1305            0,
1306            0,
1307            cancel_bytes[0],
1308            0,
1309            0,
1310            0,
1311        ];
1312        let length_so_far = length_so_far + request0.len();
1313        assert_eq!(length_so_far % 4, 0);
1314        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1315        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1316        ([request0.into()], vec![])
1317    }
1318    /// Parse this request given its header, its body, and any fds that go along with it
1319    #[cfg(feature = "request-parsing")]
1320    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1321        if header.minor_opcode != PRINT_END_DOC_REQUEST {
1322            return Err(ParseError::InvalidValue);
1323        }
1324        let (cancel, remaining) = bool::try_parse(value)?;
1325        let _ = remaining;
1326        Ok(PrintEndDocRequest {
1327            cancel,
1328        })
1329    }
1330}
1331impl Request for PrintEndDocRequest {
1332    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1333
1334    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1335        let (bufs, fds) = self.serialize(major_opcode);
1336        // Flatten the buffers into a single vector
1337        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1338        (buf, fds)
1339    }
1340}
1341impl crate::x11_utils::VoidRequest for PrintEndDocRequest {
1342}
1343
1344/// Opcode for the PrintPutDocumentData request
1345pub const PRINT_PUT_DOCUMENT_DATA_REQUEST: u8 = 11;
1346#[derive(Clone, Default)]
1347#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1348#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1349pub struct PrintPutDocumentDataRequest<'input> {
1350    pub drawable: xproto::Drawable,
1351    pub data: Cow<'input, [u8]>,
1352    pub doc_format: Cow<'input, [String8]>,
1353    pub options: Cow<'input, [String8]>,
1354}
1355impl_debug_if_no_extra_traits!(PrintPutDocumentDataRequest<'_>, "PrintPutDocumentDataRequest");
1356impl<'input> PrintPutDocumentDataRequest<'input> {
1357    /// Serialize this request into bytes for the provided connection
1358    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 7]> {
1359        let length_so_far = 0;
1360        let drawable_bytes = self.drawable.serialize();
1361        let len_data = u32::try_from(self.data.len()).expect("`data` has too many elements");
1362        let len_data_bytes = len_data.serialize();
1363        let len_fmt = u16::try_from(self.doc_format.len()).expect("`doc_format` has too many elements");
1364        let len_fmt_bytes = len_fmt.serialize();
1365        let len_options = u16::try_from(self.options.len()).expect("`options` has too many elements");
1366        let len_options_bytes = len_options.serialize();
1367        let mut request0 = vec![
1368            major_opcode,
1369            PRINT_PUT_DOCUMENT_DATA_REQUEST,
1370            0,
1371            0,
1372            drawable_bytes[0],
1373            drawable_bytes[1],
1374            drawable_bytes[2],
1375            drawable_bytes[3],
1376            len_data_bytes[0],
1377            len_data_bytes[1],
1378            len_data_bytes[2],
1379            len_data_bytes[3],
1380            len_fmt_bytes[0],
1381            len_fmt_bytes[1],
1382            len_options_bytes[0],
1383            len_options_bytes[1],
1384        ];
1385        let length_so_far = length_so_far + request0.len();
1386        let length_so_far = length_so_far + self.data.len();
1387        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1388        let length_so_far = length_so_far + padding0.len();
1389        let length_so_far = length_so_far + self.doc_format.len();
1390        let padding1 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1391        let length_so_far = length_so_far + padding1.len();
1392        let length_so_far = length_so_far + self.options.len();
1393        let padding2 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1394        let length_so_far = length_so_far + padding2.len();
1395        assert_eq!(length_so_far % 4, 0);
1396        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1397        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1398        ([request0.into(), self.data, padding0.into(), self.doc_format, padding1.into(), self.options, padding2.into()], vec![])
1399    }
1400    /// Parse this request given its header, its body, and any fds that go along with it
1401    #[cfg(feature = "request-parsing")]
1402    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1403        if header.minor_opcode != PRINT_PUT_DOCUMENT_DATA_REQUEST {
1404            return Err(ParseError::InvalidValue);
1405        }
1406        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
1407        let (len_data, remaining) = u32::try_parse(remaining)?;
1408        let (len_fmt, remaining) = u16::try_parse(remaining)?;
1409        let (len_options, remaining) = u16::try_parse(remaining)?;
1410        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, len_data.try_to_usize()?)?;
1411        // Align offset to multiple of 4
1412        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
1413        let misalignment = (4 - (offset % 4)) % 4;
1414        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
1415        let (doc_format, remaining) = crate::x11_utils::parse_u8_list(remaining, len_fmt.try_to_usize()?)?;
1416        // Align offset to multiple of 4
1417        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
1418        let misalignment = (4 - (offset % 4)) % 4;
1419        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
1420        let (options, remaining) = crate::x11_utils::parse_u8_list(remaining, len_options.try_to_usize()?)?;
1421        let _ = remaining;
1422        Ok(PrintPutDocumentDataRequest {
1423            drawable,
1424            data: Cow::Borrowed(data),
1425            doc_format: Cow::Borrowed(doc_format),
1426            options: Cow::Borrowed(options),
1427        })
1428    }
1429    /// Clone all borrowed data in this PrintPutDocumentDataRequest.
1430    pub fn into_owned(self) -> PrintPutDocumentDataRequest<'static> {
1431        PrintPutDocumentDataRequest {
1432            drawable: self.drawable,
1433            data: Cow::Owned(self.data.into_owned()),
1434            doc_format: Cow::Owned(self.doc_format.into_owned()),
1435            options: Cow::Owned(self.options.into_owned()),
1436        }
1437    }
1438}
1439impl<'input> Request for PrintPutDocumentDataRequest<'input> {
1440    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1441
1442    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1443        let (bufs, fds) = self.serialize(major_opcode);
1444        // Flatten the buffers into a single vector
1445        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1446        (buf, fds)
1447    }
1448}
1449impl<'input> crate::x11_utils::VoidRequest for PrintPutDocumentDataRequest<'input> {
1450}
1451
1452/// Opcode for the PrintGetDocumentData request
1453pub const PRINT_GET_DOCUMENT_DATA_REQUEST: u8 = 12;
1454#[derive(Clone, Copy, Default)]
1455#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1456#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1457pub struct PrintGetDocumentDataRequest {
1458    pub context: Pcontext,
1459    pub max_bytes: u32,
1460}
1461impl_debug_if_no_extra_traits!(PrintGetDocumentDataRequest, "PrintGetDocumentDataRequest");
1462impl PrintGetDocumentDataRequest {
1463    /// Serialize this request into bytes for the provided connection
1464    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1465        let length_so_far = 0;
1466        let context_bytes = self.context.serialize();
1467        let max_bytes_bytes = self.max_bytes.serialize();
1468        let mut request0 = vec![
1469            major_opcode,
1470            PRINT_GET_DOCUMENT_DATA_REQUEST,
1471            0,
1472            0,
1473            context_bytes[0],
1474            context_bytes[1],
1475            context_bytes[2],
1476            context_bytes[3],
1477            max_bytes_bytes[0],
1478            max_bytes_bytes[1],
1479            max_bytes_bytes[2],
1480            max_bytes_bytes[3],
1481        ];
1482        let length_so_far = length_so_far + request0.len();
1483        assert_eq!(length_so_far % 4, 0);
1484        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1485        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1486        ([request0.into()], vec![])
1487    }
1488    /// Parse this request given its header, its body, and any fds that go along with it
1489    #[cfg(feature = "request-parsing")]
1490    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1491        if header.minor_opcode != PRINT_GET_DOCUMENT_DATA_REQUEST {
1492            return Err(ParseError::InvalidValue);
1493        }
1494        let (context, remaining) = Pcontext::try_parse(value)?;
1495        let (max_bytes, remaining) = u32::try_parse(remaining)?;
1496        let _ = remaining;
1497        Ok(PrintGetDocumentDataRequest {
1498            context,
1499            max_bytes,
1500        })
1501    }
1502}
1503impl Request for PrintGetDocumentDataRequest {
1504    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1505
1506    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1507        let (bufs, fds) = self.serialize(major_opcode);
1508        // Flatten the buffers into a single vector
1509        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1510        (buf, fds)
1511    }
1512}
1513impl crate::x11_utils::ReplyRequest for PrintGetDocumentDataRequest {
1514    type Reply = PrintGetDocumentDataReply;
1515}
1516
1517#[derive(Clone, Default)]
1518#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1519#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1520pub struct PrintGetDocumentDataReply {
1521    pub sequence: u16,
1522    pub length: u32,
1523    pub status_code: u32,
1524    pub finished_flag: u32,
1525    pub data: Vec<u8>,
1526}
1527impl_debug_if_no_extra_traits!(PrintGetDocumentDataReply, "PrintGetDocumentDataReply");
1528impl TryParse for PrintGetDocumentDataReply {
1529    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1530        let remaining = initial_value;
1531        let (response_type, remaining) = u8::try_parse(remaining)?;
1532        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1533        let (sequence, remaining) = u16::try_parse(remaining)?;
1534        let (length, remaining) = u32::try_parse(remaining)?;
1535        let (status_code, remaining) = u32::try_parse(remaining)?;
1536        let (finished_flag, remaining) = u32::try_parse(remaining)?;
1537        let (data_len, remaining) = u32::try_parse(remaining)?;
1538        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1539        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, data_len.try_to_usize()?)?;
1540        let data = data.to_vec();
1541        if response_type != 1 {
1542            return Err(ParseError::InvalidValue);
1543        }
1544        let result = PrintGetDocumentDataReply { sequence, length, status_code, finished_flag, data };
1545        let _ = remaining;
1546        let remaining = initial_value.get(32 + length as usize * 4..)
1547            .ok_or(ParseError::InsufficientData)?;
1548        Ok((result, remaining))
1549    }
1550}
1551impl Serialize for PrintGetDocumentDataReply {
1552    type Bytes = Vec<u8>;
1553    fn serialize(&self) -> Vec<u8> {
1554        let mut result = Vec::new();
1555        self.serialize_into(&mut result);
1556        result
1557    }
1558    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1559        bytes.reserve(32);
1560        let response_type_bytes = &[1];
1561        bytes.push(response_type_bytes[0]);
1562        bytes.extend_from_slice(&[0; 1]);
1563        self.sequence.serialize_into(bytes);
1564        self.length.serialize_into(bytes);
1565        self.status_code.serialize_into(bytes);
1566        self.finished_flag.serialize_into(bytes);
1567        let data_len = u32::try_from(self.data.len()).expect("`data` has too many elements");
1568        data_len.serialize_into(bytes);
1569        bytes.extend_from_slice(&[0; 12]);
1570        bytes.extend_from_slice(&self.data);
1571    }
1572}
1573impl PrintGetDocumentDataReply {
1574    /// Get the value of the `dataLen` field.
1575    ///
1576    /// The `dataLen` field is used as the length field of the `data` field.
1577    /// This function computes the field's value again based on the length of the list.
1578    ///
1579    /// # Panics
1580    ///
1581    /// Panics if the value cannot be represented in the target type. This
1582    /// cannot happen with values of the struct received from the X11 server.
1583    pub fn data_len(&self) -> u32 {
1584        self.data.len()
1585            .try_into().unwrap()
1586    }
1587}
1588
1589/// Opcode for the PrintStartPage request
1590pub const PRINT_START_PAGE_REQUEST: u8 = 13;
1591#[derive(Clone, Copy, Default)]
1592#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1593#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1594pub struct PrintStartPageRequest {
1595    pub window: xproto::Window,
1596}
1597impl_debug_if_no_extra_traits!(PrintStartPageRequest, "PrintStartPageRequest");
1598impl PrintStartPageRequest {
1599    /// Serialize this request into bytes for the provided connection
1600    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1601        let length_so_far = 0;
1602        let window_bytes = self.window.serialize();
1603        let mut request0 = vec![
1604            major_opcode,
1605            PRINT_START_PAGE_REQUEST,
1606            0,
1607            0,
1608            window_bytes[0],
1609            window_bytes[1],
1610            window_bytes[2],
1611            window_bytes[3],
1612        ];
1613        let length_so_far = length_so_far + request0.len();
1614        assert_eq!(length_so_far % 4, 0);
1615        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1616        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1617        ([request0.into()], vec![])
1618    }
1619    /// Parse this request given its header, its body, and any fds that go along with it
1620    #[cfg(feature = "request-parsing")]
1621    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1622        if header.minor_opcode != PRINT_START_PAGE_REQUEST {
1623            return Err(ParseError::InvalidValue);
1624        }
1625        let (window, remaining) = xproto::Window::try_parse(value)?;
1626        let _ = remaining;
1627        Ok(PrintStartPageRequest {
1628            window,
1629        })
1630    }
1631}
1632impl Request for PrintStartPageRequest {
1633    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1634
1635    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1636        let (bufs, fds) = self.serialize(major_opcode);
1637        // Flatten the buffers into a single vector
1638        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1639        (buf, fds)
1640    }
1641}
1642impl crate::x11_utils::VoidRequest for PrintStartPageRequest {
1643}
1644
1645/// Opcode for the PrintEndPage request
1646pub const PRINT_END_PAGE_REQUEST: u8 = 14;
1647#[derive(Clone, Copy, Default)]
1648#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1649#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1650pub struct PrintEndPageRequest {
1651    pub cancel: bool,
1652}
1653impl_debug_if_no_extra_traits!(PrintEndPageRequest, "PrintEndPageRequest");
1654impl PrintEndPageRequest {
1655    /// Serialize this request into bytes for the provided connection
1656    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1657        let length_so_far = 0;
1658        let cancel_bytes = self.cancel.serialize();
1659        let mut request0 = vec![
1660            major_opcode,
1661            PRINT_END_PAGE_REQUEST,
1662            0,
1663            0,
1664            cancel_bytes[0],
1665            0,
1666            0,
1667            0,
1668        ];
1669        let length_so_far = length_so_far + request0.len();
1670        assert_eq!(length_so_far % 4, 0);
1671        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1672        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1673        ([request0.into()], vec![])
1674    }
1675    /// Parse this request given its header, its body, and any fds that go along with it
1676    #[cfg(feature = "request-parsing")]
1677    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1678        if header.minor_opcode != PRINT_END_PAGE_REQUEST {
1679            return Err(ParseError::InvalidValue);
1680        }
1681        let (cancel, remaining) = bool::try_parse(value)?;
1682        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
1683        let _ = remaining;
1684        Ok(PrintEndPageRequest {
1685            cancel,
1686        })
1687    }
1688}
1689impl Request for PrintEndPageRequest {
1690    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1691
1692    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1693        let (bufs, fds) = self.serialize(major_opcode);
1694        // Flatten the buffers into a single vector
1695        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1696        (buf, fds)
1697    }
1698}
1699impl crate::x11_utils::VoidRequest for PrintEndPageRequest {
1700}
1701
1702/// Opcode for the PrintSelectInput request
1703pub const PRINT_SELECT_INPUT_REQUEST: u8 = 15;
1704#[derive(Clone, Copy, Default)]
1705#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1706#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1707pub struct PrintSelectInputRequest {
1708    pub context: Pcontext,
1709    pub event_mask: u32,
1710}
1711impl_debug_if_no_extra_traits!(PrintSelectInputRequest, "PrintSelectInputRequest");
1712impl PrintSelectInputRequest {
1713    /// Serialize this request into bytes for the provided connection
1714    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1715        let length_so_far = 0;
1716        let context_bytes = self.context.serialize();
1717        let event_mask_bytes = self.event_mask.serialize();
1718        let mut request0 = vec![
1719            major_opcode,
1720            PRINT_SELECT_INPUT_REQUEST,
1721            0,
1722            0,
1723            context_bytes[0],
1724            context_bytes[1],
1725            context_bytes[2],
1726            context_bytes[3],
1727            event_mask_bytes[0],
1728            event_mask_bytes[1],
1729            event_mask_bytes[2],
1730            event_mask_bytes[3],
1731        ];
1732        let length_so_far = length_so_far + request0.len();
1733        assert_eq!(length_so_far % 4, 0);
1734        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1735        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1736        ([request0.into()], vec![])
1737    }
1738    /// Parse this request given its header, its body, and any fds that go along with it
1739    #[cfg(feature = "request-parsing")]
1740    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1741        if header.minor_opcode != PRINT_SELECT_INPUT_REQUEST {
1742            return Err(ParseError::InvalidValue);
1743        }
1744        let (context, remaining) = Pcontext::try_parse(value)?;
1745        let (event_mask, remaining) = u32::try_parse(remaining)?;
1746        let _ = remaining;
1747        Ok(PrintSelectInputRequest {
1748            context,
1749            event_mask,
1750        })
1751    }
1752}
1753impl Request for PrintSelectInputRequest {
1754    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1755
1756    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1757        let (bufs, fds) = self.serialize(major_opcode);
1758        // Flatten the buffers into a single vector
1759        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1760        (buf, fds)
1761    }
1762}
1763impl crate::x11_utils::VoidRequest for PrintSelectInputRequest {
1764}
1765
1766/// Opcode for the PrintInputSelected request
1767pub const PRINT_INPUT_SELECTED_REQUEST: u8 = 16;
1768#[derive(Clone, Copy, Default)]
1769#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1770#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1771pub struct PrintInputSelectedRequest {
1772    pub context: Pcontext,
1773}
1774impl_debug_if_no_extra_traits!(PrintInputSelectedRequest, "PrintInputSelectedRequest");
1775impl PrintInputSelectedRequest {
1776    /// Serialize this request into bytes for the provided connection
1777    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1778        let length_so_far = 0;
1779        let context_bytes = self.context.serialize();
1780        let mut request0 = vec![
1781            major_opcode,
1782            PRINT_INPUT_SELECTED_REQUEST,
1783            0,
1784            0,
1785            context_bytes[0],
1786            context_bytes[1],
1787            context_bytes[2],
1788            context_bytes[3],
1789        ];
1790        let length_so_far = length_so_far + request0.len();
1791        assert_eq!(length_so_far % 4, 0);
1792        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1793        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1794        ([request0.into()], vec![])
1795    }
1796    /// Parse this request given its header, its body, and any fds that go along with it
1797    #[cfg(feature = "request-parsing")]
1798    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1799        if header.minor_opcode != PRINT_INPUT_SELECTED_REQUEST {
1800            return Err(ParseError::InvalidValue);
1801        }
1802        let (context, remaining) = Pcontext::try_parse(value)?;
1803        let _ = remaining;
1804        Ok(PrintInputSelectedRequest {
1805            context,
1806        })
1807    }
1808}
1809impl Request for PrintInputSelectedRequest {
1810    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1811
1812    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1813        let (bufs, fds) = self.serialize(major_opcode);
1814        // Flatten the buffers into a single vector
1815        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1816        (buf, fds)
1817    }
1818}
1819impl crate::x11_utils::ReplyRequest for PrintInputSelectedRequest {
1820    type Reply = PrintInputSelectedReply;
1821}
1822
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 PrintInputSelectedReply {
1827    pub sequence: u16,
1828    pub length: u32,
1829    pub event_mask: u32,
1830    pub all_events_mask: u32,
1831}
1832impl_debug_if_no_extra_traits!(PrintInputSelectedReply, "PrintInputSelectedReply");
1833impl TryParse for PrintInputSelectedReply {
1834    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1835        let remaining = initial_value;
1836        let (response_type, remaining) = u8::try_parse(remaining)?;
1837        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1838        let (sequence, remaining) = u16::try_parse(remaining)?;
1839        let (length, remaining) = u32::try_parse(remaining)?;
1840        let (event_mask, remaining) = u32::try_parse(remaining)?;
1841        let (all_events_mask, remaining) = u32::try_parse(remaining)?;
1842        if response_type != 1 {
1843            return Err(ParseError::InvalidValue);
1844        }
1845        let result = PrintInputSelectedReply { sequence, length, event_mask, all_events_mask };
1846        let _ = remaining;
1847        let remaining = initial_value.get(32 + length as usize * 4..)
1848            .ok_or(ParseError::InsufficientData)?;
1849        Ok((result, remaining))
1850    }
1851}
1852impl Serialize for PrintInputSelectedReply {
1853    type Bytes = [u8; 16];
1854    fn serialize(&self) -> [u8; 16] {
1855        let response_type_bytes = &[1];
1856        let sequence_bytes = self.sequence.serialize();
1857        let length_bytes = self.length.serialize();
1858        let event_mask_bytes = self.event_mask.serialize();
1859        let all_events_mask_bytes = self.all_events_mask.serialize();
1860        [
1861            response_type_bytes[0],
1862            0,
1863            sequence_bytes[0],
1864            sequence_bytes[1],
1865            length_bytes[0],
1866            length_bytes[1],
1867            length_bytes[2],
1868            length_bytes[3],
1869            event_mask_bytes[0],
1870            event_mask_bytes[1],
1871            event_mask_bytes[2],
1872            event_mask_bytes[3],
1873            all_events_mask_bytes[0],
1874            all_events_mask_bytes[1],
1875            all_events_mask_bytes[2],
1876            all_events_mask_bytes[3],
1877        ]
1878    }
1879    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1880        bytes.reserve(16);
1881        let response_type_bytes = &[1];
1882        bytes.push(response_type_bytes[0]);
1883        bytes.extend_from_slice(&[0; 1]);
1884        self.sequence.serialize_into(bytes);
1885        self.length.serialize_into(bytes);
1886        self.event_mask.serialize_into(bytes);
1887        self.all_events_mask.serialize_into(bytes);
1888    }
1889}
1890
1891/// Opcode for the PrintGetAttributes request
1892pub const PRINT_GET_ATTRIBUTES_REQUEST: u8 = 17;
1893#[derive(Clone, Copy, Default)]
1894#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1895#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1896pub struct PrintGetAttributesRequest {
1897    pub context: Pcontext,
1898    pub pool: u8,
1899}
1900impl_debug_if_no_extra_traits!(PrintGetAttributesRequest, "PrintGetAttributesRequest");
1901impl PrintGetAttributesRequest {
1902    /// Serialize this request into bytes for the provided connection
1903    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1904        let length_so_far = 0;
1905        let context_bytes = self.context.serialize();
1906        let pool_bytes = self.pool.serialize();
1907        let mut request0 = vec![
1908            major_opcode,
1909            PRINT_GET_ATTRIBUTES_REQUEST,
1910            0,
1911            0,
1912            context_bytes[0],
1913            context_bytes[1],
1914            context_bytes[2],
1915            context_bytes[3],
1916            pool_bytes[0],
1917            0,
1918            0,
1919            0,
1920        ];
1921        let length_so_far = length_so_far + request0.len();
1922        assert_eq!(length_so_far % 4, 0);
1923        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1924        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1925        ([request0.into()], vec![])
1926    }
1927    /// Parse this request given its header, its body, and any fds that go along with it
1928    #[cfg(feature = "request-parsing")]
1929    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1930        if header.minor_opcode != PRINT_GET_ATTRIBUTES_REQUEST {
1931            return Err(ParseError::InvalidValue);
1932        }
1933        let (context, remaining) = Pcontext::try_parse(value)?;
1934        let (pool, remaining) = u8::try_parse(remaining)?;
1935        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
1936        let _ = remaining;
1937        Ok(PrintGetAttributesRequest {
1938            context,
1939            pool,
1940        })
1941    }
1942}
1943impl Request for PrintGetAttributesRequest {
1944    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1945
1946    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1947        let (bufs, fds) = self.serialize(major_opcode);
1948        // Flatten the buffers into a single vector
1949        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1950        (buf, fds)
1951    }
1952}
1953impl crate::x11_utils::ReplyRequest for PrintGetAttributesRequest {
1954    type Reply = PrintGetAttributesReply;
1955}
1956
1957#[derive(Clone, Default)]
1958#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1959#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1960pub struct PrintGetAttributesReply {
1961    pub sequence: u16,
1962    pub length: u32,
1963    pub attributes: Vec<String8>,
1964}
1965impl_debug_if_no_extra_traits!(PrintGetAttributesReply, "PrintGetAttributesReply");
1966impl TryParse for PrintGetAttributesReply {
1967    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1968        let remaining = initial_value;
1969        let (response_type, remaining) = u8::try_parse(remaining)?;
1970        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1971        let (sequence, remaining) = u16::try_parse(remaining)?;
1972        let (length, remaining) = u32::try_parse(remaining)?;
1973        let (string_len, remaining) = u32::try_parse(remaining)?;
1974        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1975        let (attributes, remaining) = crate::x11_utils::parse_u8_list(remaining, string_len.try_to_usize()?)?;
1976        let attributes = attributes.to_vec();
1977        if response_type != 1 {
1978            return Err(ParseError::InvalidValue);
1979        }
1980        let result = PrintGetAttributesReply { sequence, length, attributes };
1981        let _ = remaining;
1982        let remaining = initial_value.get(32 + length as usize * 4..)
1983            .ok_or(ParseError::InsufficientData)?;
1984        Ok((result, remaining))
1985    }
1986}
1987impl Serialize for PrintGetAttributesReply {
1988    type Bytes = Vec<u8>;
1989    fn serialize(&self) -> Vec<u8> {
1990        let mut result = Vec::new();
1991        self.serialize_into(&mut result);
1992        result
1993    }
1994    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1995        bytes.reserve(32);
1996        let response_type_bytes = &[1];
1997        bytes.push(response_type_bytes[0]);
1998        bytes.extend_from_slice(&[0; 1]);
1999        self.sequence.serialize_into(bytes);
2000        self.length.serialize_into(bytes);
2001        let string_len = u32::try_from(self.attributes.len()).expect("`attributes` has too many elements");
2002        string_len.serialize_into(bytes);
2003        bytes.extend_from_slice(&[0; 20]);
2004        bytes.extend_from_slice(&self.attributes);
2005    }
2006}
2007impl PrintGetAttributesReply {
2008    /// Get the value of the `stringLen` field.
2009    ///
2010    /// The `stringLen` field is used as the length field of the `attributes` field.
2011    /// This function computes the field's value again based on the length of the list.
2012    ///
2013    /// # Panics
2014    ///
2015    /// Panics if the value cannot be represented in the target type. This
2016    /// cannot happen with values of the struct received from the X11 server.
2017    pub fn string_len(&self) -> u32 {
2018        self.attributes.len()
2019            .try_into().unwrap()
2020    }
2021}
2022
2023/// Opcode for the PrintGetOneAttributes request
2024pub const PRINT_GET_ONE_ATTRIBUTES_REQUEST: u8 = 19;
2025#[derive(Clone, Default)]
2026#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2027#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2028pub struct PrintGetOneAttributesRequest<'input> {
2029    pub context: Pcontext,
2030    pub pool: u8,
2031    pub name: Cow<'input, [String8]>,
2032}
2033impl_debug_if_no_extra_traits!(PrintGetOneAttributesRequest<'_>, "PrintGetOneAttributesRequest");
2034impl<'input> PrintGetOneAttributesRequest<'input> {
2035    /// Serialize this request into bytes for the provided connection
2036    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2037        let length_so_far = 0;
2038        let context_bytes = self.context.serialize();
2039        let name_len = u32::try_from(self.name.len()).expect("`name` has too many elements");
2040        let name_len_bytes = name_len.serialize();
2041        let pool_bytes = self.pool.serialize();
2042        let mut request0 = vec![
2043            major_opcode,
2044            PRINT_GET_ONE_ATTRIBUTES_REQUEST,
2045            0,
2046            0,
2047            context_bytes[0],
2048            context_bytes[1],
2049            context_bytes[2],
2050            context_bytes[3],
2051            name_len_bytes[0],
2052            name_len_bytes[1],
2053            name_len_bytes[2],
2054            name_len_bytes[3],
2055            pool_bytes[0],
2056            0,
2057            0,
2058            0,
2059        ];
2060        let length_so_far = length_so_far + request0.len();
2061        let length_so_far = length_so_far + self.name.len();
2062        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2063        let length_so_far = length_so_far + padding0.len();
2064        assert_eq!(length_so_far % 4, 0);
2065        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2066        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2067        ([request0.into(), self.name, padding0.into()], vec![])
2068    }
2069    /// Parse this request given its header, its body, and any fds that go along with it
2070    #[cfg(feature = "request-parsing")]
2071    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2072        if header.minor_opcode != PRINT_GET_ONE_ATTRIBUTES_REQUEST {
2073            return Err(ParseError::InvalidValue);
2074        }
2075        let (context, remaining) = Pcontext::try_parse(value)?;
2076        let (name_len, remaining) = u32::try_parse(remaining)?;
2077        let (pool, remaining) = u8::try_parse(remaining)?;
2078        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
2079        let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
2080        let _ = remaining;
2081        Ok(PrintGetOneAttributesRequest {
2082            context,
2083            pool,
2084            name: Cow::Borrowed(name),
2085        })
2086    }
2087    /// Clone all borrowed data in this PrintGetOneAttributesRequest.
2088    pub fn into_owned(self) -> PrintGetOneAttributesRequest<'static> {
2089        PrintGetOneAttributesRequest {
2090            context: self.context,
2091            pool: self.pool,
2092            name: Cow::Owned(self.name.into_owned()),
2093        }
2094    }
2095}
2096impl<'input> Request for PrintGetOneAttributesRequest<'input> {
2097    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2098
2099    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2100        let (bufs, fds) = self.serialize(major_opcode);
2101        // Flatten the buffers into a single vector
2102        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2103        (buf, fds)
2104    }
2105}
2106impl<'input> crate::x11_utils::ReplyRequest for PrintGetOneAttributesRequest<'input> {
2107    type Reply = PrintGetOneAttributesReply;
2108}
2109
2110#[derive(Clone, Default)]
2111#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2112#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2113pub struct PrintGetOneAttributesReply {
2114    pub sequence: u16,
2115    pub length: u32,
2116    pub value: Vec<String8>,
2117}
2118impl_debug_if_no_extra_traits!(PrintGetOneAttributesReply, "PrintGetOneAttributesReply");
2119impl TryParse for PrintGetOneAttributesReply {
2120    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2121        let remaining = initial_value;
2122        let (response_type, remaining) = u8::try_parse(remaining)?;
2123        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2124        let (sequence, remaining) = u16::try_parse(remaining)?;
2125        let (length, remaining) = u32::try_parse(remaining)?;
2126        let (value_len, remaining) = u32::try_parse(remaining)?;
2127        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2128        let (value, remaining) = crate::x11_utils::parse_u8_list(remaining, value_len.try_to_usize()?)?;
2129        let value = value.to_vec();
2130        if response_type != 1 {
2131            return Err(ParseError::InvalidValue);
2132        }
2133        let result = PrintGetOneAttributesReply { sequence, length, value };
2134        let _ = remaining;
2135        let remaining = initial_value.get(32 + length as usize * 4..)
2136            .ok_or(ParseError::InsufficientData)?;
2137        Ok((result, remaining))
2138    }
2139}
2140impl Serialize for PrintGetOneAttributesReply {
2141    type Bytes = Vec<u8>;
2142    fn serialize(&self) -> Vec<u8> {
2143        let mut result = Vec::new();
2144        self.serialize_into(&mut result);
2145        result
2146    }
2147    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2148        bytes.reserve(32);
2149        let response_type_bytes = &[1];
2150        bytes.push(response_type_bytes[0]);
2151        bytes.extend_from_slice(&[0; 1]);
2152        self.sequence.serialize_into(bytes);
2153        self.length.serialize_into(bytes);
2154        let value_len = u32::try_from(self.value.len()).expect("`value` has too many elements");
2155        value_len.serialize_into(bytes);
2156        bytes.extend_from_slice(&[0; 20]);
2157        bytes.extend_from_slice(&self.value);
2158    }
2159}
2160impl PrintGetOneAttributesReply {
2161    /// Get the value of the `valueLen` field.
2162    ///
2163    /// The `valueLen` field is used as the length field of the `value` field.
2164    /// This function computes the field's value again based on the length of the list.
2165    ///
2166    /// # Panics
2167    ///
2168    /// Panics if the value cannot be represented in the target type. This
2169    /// cannot happen with values of the struct received from the X11 server.
2170    pub fn value_len(&self) -> u32 {
2171        self.value.len()
2172            .try_into().unwrap()
2173    }
2174}
2175
2176/// Opcode for the PrintSetAttributes request
2177pub const PRINT_SET_ATTRIBUTES_REQUEST: u8 = 18;
2178#[derive(Clone, Default)]
2179#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2180#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2181pub struct PrintSetAttributesRequest<'input> {
2182    pub context: Pcontext,
2183    pub string_len: u32,
2184    pub pool: u8,
2185    pub rule: u8,
2186    pub attributes: Cow<'input, [String8]>,
2187}
2188impl_debug_if_no_extra_traits!(PrintSetAttributesRequest<'_>, "PrintSetAttributesRequest");
2189impl<'input> PrintSetAttributesRequest<'input> {
2190    /// Serialize this request into bytes for the provided connection
2191    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2192        let length_so_far = 0;
2193        let context_bytes = self.context.serialize();
2194        let string_len_bytes = self.string_len.serialize();
2195        let pool_bytes = self.pool.serialize();
2196        let rule_bytes = self.rule.serialize();
2197        let mut request0 = vec![
2198            major_opcode,
2199            PRINT_SET_ATTRIBUTES_REQUEST,
2200            0,
2201            0,
2202            context_bytes[0],
2203            context_bytes[1],
2204            context_bytes[2],
2205            context_bytes[3],
2206            string_len_bytes[0],
2207            string_len_bytes[1],
2208            string_len_bytes[2],
2209            string_len_bytes[3],
2210            pool_bytes[0],
2211            rule_bytes[0],
2212            0,
2213            0,
2214        ];
2215        let length_so_far = length_so_far + request0.len();
2216        let length_so_far = length_so_far + self.attributes.len();
2217        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2218        let length_so_far = length_so_far + padding0.len();
2219        assert_eq!(length_so_far % 4, 0);
2220        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2221        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2222        ([request0.into(), self.attributes, padding0.into()], vec![])
2223    }
2224    /// Parse this request given its header, its body, and any fds that go along with it
2225    #[cfg(feature = "request-parsing")]
2226    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2227        if header.minor_opcode != PRINT_SET_ATTRIBUTES_REQUEST {
2228            return Err(ParseError::InvalidValue);
2229        }
2230        let (context, remaining) = Pcontext::try_parse(value)?;
2231        let (string_len, remaining) = u32::try_parse(remaining)?;
2232        let (pool, remaining) = u8::try_parse(remaining)?;
2233        let (rule, remaining) = u8::try_parse(remaining)?;
2234        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2235        let (attributes, remaining) = remaining.split_at(remaining.len());
2236        let _ = remaining;
2237        Ok(PrintSetAttributesRequest {
2238            context,
2239            string_len,
2240            pool,
2241            rule,
2242            attributes: Cow::Borrowed(attributes),
2243        })
2244    }
2245    /// Clone all borrowed data in this PrintSetAttributesRequest.
2246    pub fn into_owned(self) -> PrintSetAttributesRequest<'static> {
2247        PrintSetAttributesRequest {
2248            context: self.context,
2249            string_len: self.string_len,
2250            pool: self.pool,
2251            rule: self.rule,
2252            attributes: Cow::Owned(self.attributes.into_owned()),
2253        }
2254    }
2255}
2256impl<'input> Request for PrintSetAttributesRequest<'input> {
2257    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2258
2259    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2260        let (bufs, fds) = self.serialize(major_opcode);
2261        // Flatten the buffers into a single vector
2262        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2263        (buf, fds)
2264    }
2265}
2266impl<'input> crate::x11_utils::VoidRequest for PrintSetAttributesRequest<'input> {
2267}
2268
2269/// Opcode for the PrintGetPageDimensions request
2270pub const PRINT_GET_PAGE_DIMENSIONS_REQUEST: u8 = 21;
2271#[derive(Clone, Copy, Default)]
2272#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2273#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2274pub struct PrintGetPageDimensionsRequest {
2275    pub context: Pcontext,
2276}
2277impl_debug_if_no_extra_traits!(PrintGetPageDimensionsRequest, "PrintGetPageDimensionsRequest");
2278impl PrintGetPageDimensionsRequest {
2279    /// Serialize this request into bytes for the provided connection
2280    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2281        let length_so_far = 0;
2282        let context_bytes = self.context.serialize();
2283        let mut request0 = vec![
2284            major_opcode,
2285            PRINT_GET_PAGE_DIMENSIONS_REQUEST,
2286            0,
2287            0,
2288            context_bytes[0],
2289            context_bytes[1],
2290            context_bytes[2],
2291            context_bytes[3],
2292        ];
2293        let length_so_far = length_so_far + request0.len();
2294        assert_eq!(length_so_far % 4, 0);
2295        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2296        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2297        ([request0.into()], vec![])
2298    }
2299    /// Parse this request given its header, its body, and any fds that go along with it
2300    #[cfg(feature = "request-parsing")]
2301    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2302        if header.minor_opcode != PRINT_GET_PAGE_DIMENSIONS_REQUEST {
2303            return Err(ParseError::InvalidValue);
2304        }
2305        let (context, remaining) = Pcontext::try_parse(value)?;
2306        let _ = remaining;
2307        Ok(PrintGetPageDimensionsRequest {
2308            context,
2309        })
2310    }
2311}
2312impl Request for PrintGetPageDimensionsRequest {
2313    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2314
2315    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2316        let (bufs, fds) = self.serialize(major_opcode);
2317        // Flatten the buffers into a single vector
2318        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2319        (buf, fds)
2320    }
2321}
2322impl crate::x11_utils::ReplyRequest for PrintGetPageDimensionsRequest {
2323    type Reply = PrintGetPageDimensionsReply;
2324}
2325
2326#[derive(Clone, Copy, Default)]
2327#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2328#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2329pub struct PrintGetPageDimensionsReply {
2330    pub sequence: u16,
2331    pub length: u32,
2332    pub width: u16,
2333    pub height: u16,
2334    pub offset_x: u16,
2335    pub offset_y: u16,
2336    pub reproducible_width: u16,
2337    pub reproducible_height: u16,
2338}
2339impl_debug_if_no_extra_traits!(PrintGetPageDimensionsReply, "PrintGetPageDimensionsReply");
2340impl TryParse for PrintGetPageDimensionsReply {
2341    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2342        let remaining = initial_value;
2343        let (response_type, remaining) = u8::try_parse(remaining)?;
2344        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2345        let (sequence, remaining) = u16::try_parse(remaining)?;
2346        let (length, remaining) = u32::try_parse(remaining)?;
2347        let (width, remaining) = u16::try_parse(remaining)?;
2348        let (height, remaining) = u16::try_parse(remaining)?;
2349        let (offset_x, remaining) = u16::try_parse(remaining)?;
2350        let (offset_y, remaining) = u16::try_parse(remaining)?;
2351        let (reproducible_width, remaining) = u16::try_parse(remaining)?;
2352        let (reproducible_height, remaining) = u16::try_parse(remaining)?;
2353        if response_type != 1 {
2354            return Err(ParseError::InvalidValue);
2355        }
2356        let result = PrintGetPageDimensionsReply { sequence, length, width, height, offset_x, offset_y, reproducible_width, reproducible_height };
2357        let _ = remaining;
2358        let remaining = initial_value.get(32 + length as usize * 4..)
2359            .ok_or(ParseError::InsufficientData)?;
2360        Ok((result, remaining))
2361    }
2362}
2363impl Serialize for PrintGetPageDimensionsReply {
2364    type Bytes = [u8; 20];
2365    fn serialize(&self) -> [u8; 20] {
2366        let response_type_bytes = &[1];
2367        let sequence_bytes = self.sequence.serialize();
2368        let length_bytes = self.length.serialize();
2369        let width_bytes = self.width.serialize();
2370        let height_bytes = self.height.serialize();
2371        let offset_x_bytes = self.offset_x.serialize();
2372        let offset_y_bytes = self.offset_y.serialize();
2373        let reproducible_width_bytes = self.reproducible_width.serialize();
2374        let reproducible_height_bytes = self.reproducible_height.serialize();
2375        [
2376            response_type_bytes[0],
2377            0,
2378            sequence_bytes[0],
2379            sequence_bytes[1],
2380            length_bytes[0],
2381            length_bytes[1],
2382            length_bytes[2],
2383            length_bytes[3],
2384            width_bytes[0],
2385            width_bytes[1],
2386            height_bytes[0],
2387            height_bytes[1],
2388            offset_x_bytes[0],
2389            offset_x_bytes[1],
2390            offset_y_bytes[0],
2391            offset_y_bytes[1],
2392            reproducible_width_bytes[0],
2393            reproducible_width_bytes[1],
2394            reproducible_height_bytes[0],
2395            reproducible_height_bytes[1],
2396        ]
2397    }
2398    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2399        bytes.reserve(20);
2400        let response_type_bytes = &[1];
2401        bytes.push(response_type_bytes[0]);
2402        bytes.extend_from_slice(&[0; 1]);
2403        self.sequence.serialize_into(bytes);
2404        self.length.serialize_into(bytes);
2405        self.width.serialize_into(bytes);
2406        self.height.serialize_into(bytes);
2407        self.offset_x.serialize_into(bytes);
2408        self.offset_y.serialize_into(bytes);
2409        self.reproducible_width.serialize_into(bytes);
2410        self.reproducible_height.serialize_into(bytes);
2411    }
2412}
2413
2414/// Opcode for the PrintQueryScreens request
2415pub const PRINT_QUERY_SCREENS_REQUEST: u8 = 22;
2416#[derive(Clone, Copy, Default)]
2417#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2418#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2419pub struct PrintQueryScreensRequest;
2420impl_debug_if_no_extra_traits!(PrintQueryScreensRequest, "PrintQueryScreensRequest");
2421impl PrintQueryScreensRequest {
2422    /// Serialize this request into bytes for the provided connection
2423    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2424        let length_so_far = 0;
2425        let mut request0 = vec![
2426            major_opcode,
2427            PRINT_QUERY_SCREENS_REQUEST,
2428            0,
2429            0,
2430        ];
2431        let length_so_far = length_so_far + request0.len();
2432        assert_eq!(length_so_far % 4, 0);
2433        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2434        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2435        ([request0.into()], vec![])
2436    }
2437    /// Parse this request given its header, its body, and any fds that go along with it
2438    #[cfg(feature = "request-parsing")]
2439    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2440        if header.minor_opcode != PRINT_QUERY_SCREENS_REQUEST {
2441            return Err(ParseError::InvalidValue);
2442        }
2443        let _ = value;
2444        Ok(PrintQueryScreensRequest
2445        )
2446    }
2447}
2448impl Request for PrintQueryScreensRequest {
2449    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2450
2451    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2452        let (bufs, fds) = self.serialize(major_opcode);
2453        // Flatten the buffers into a single vector
2454        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2455        (buf, fds)
2456    }
2457}
2458impl crate::x11_utils::ReplyRequest for PrintQueryScreensRequest {
2459    type Reply = PrintQueryScreensReply;
2460}
2461
2462#[derive(Clone, Default)]
2463#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2464#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2465pub struct PrintQueryScreensReply {
2466    pub sequence: u16,
2467    pub length: u32,
2468    pub roots: Vec<xproto::Window>,
2469}
2470impl_debug_if_no_extra_traits!(PrintQueryScreensReply, "PrintQueryScreensReply");
2471impl TryParse for PrintQueryScreensReply {
2472    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2473        let remaining = initial_value;
2474        let (response_type, remaining) = u8::try_parse(remaining)?;
2475        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2476        let (sequence, remaining) = u16::try_parse(remaining)?;
2477        let (length, remaining) = u32::try_parse(remaining)?;
2478        let (list_count, remaining) = u32::try_parse(remaining)?;
2479        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2480        let (roots, remaining) = crate::x11_utils::parse_list::<xproto::Window>(remaining, list_count.try_to_usize()?)?;
2481        if response_type != 1 {
2482            return Err(ParseError::InvalidValue);
2483        }
2484        let result = PrintQueryScreensReply { sequence, length, roots };
2485        let _ = remaining;
2486        let remaining = initial_value.get(32 + length as usize * 4..)
2487            .ok_or(ParseError::InsufficientData)?;
2488        Ok((result, remaining))
2489    }
2490}
2491impl Serialize for PrintQueryScreensReply {
2492    type Bytes = Vec<u8>;
2493    fn serialize(&self) -> Vec<u8> {
2494        let mut result = Vec::new();
2495        self.serialize_into(&mut result);
2496        result
2497    }
2498    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2499        bytes.reserve(32);
2500        let response_type_bytes = &[1];
2501        bytes.push(response_type_bytes[0]);
2502        bytes.extend_from_slice(&[0; 1]);
2503        self.sequence.serialize_into(bytes);
2504        self.length.serialize_into(bytes);
2505        let list_count = u32::try_from(self.roots.len()).expect("`roots` has too many elements");
2506        list_count.serialize_into(bytes);
2507        bytes.extend_from_slice(&[0; 20]);
2508        self.roots.serialize_into(bytes);
2509    }
2510}
2511impl PrintQueryScreensReply {
2512    /// Get the value of the `listCount` field.
2513    ///
2514    /// The `listCount` field is used as the length field of the `roots` field.
2515    /// This function computes the field's value again based on the length of the list.
2516    ///
2517    /// # Panics
2518    ///
2519    /// Panics if the value cannot be represented in the target type. This
2520    /// cannot happen with values of the struct received from the X11 server.
2521    pub fn list_count(&self) -> u32 {
2522        self.roots.len()
2523            .try_into().unwrap()
2524    }
2525}
2526
2527/// Opcode for the PrintSetImageResolution request
2528pub const PRINT_SET_IMAGE_RESOLUTION_REQUEST: u8 = 23;
2529#[derive(Clone, Copy, Default)]
2530#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2531#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2532pub struct PrintSetImageResolutionRequest {
2533    pub context: Pcontext,
2534    pub image_resolution: u16,
2535}
2536impl_debug_if_no_extra_traits!(PrintSetImageResolutionRequest, "PrintSetImageResolutionRequest");
2537impl PrintSetImageResolutionRequest {
2538    /// Serialize this request into bytes for the provided connection
2539    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2540        let length_so_far = 0;
2541        let context_bytes = self.context.serialize();
2542        let image_resolution_bytes = self.image_resolution.serialize();
2543        let mut request0 = vec![
2544            major_opcode,
2545            PRINT_SET_IMAGE_RESOLUTION_REQUEST,
2546            0,
2547            0,
2548            context_bytes[0],
2549            context_bytes[1],
2550            context_bytes[2],
2551            context_bytes[3],
2552            image_resolution_bytes[0],
2553            image_resolution_bytes[1],
2554            0,
2555            0,
2556        ];
2557        let length_so_far = length_so_far + request0.len();
2558        assert_eq!(length_so_far % 4, 0);
2559        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2560        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2561        ([request0.into()], vec![])
2562    }
2563    /// Parse this request given its header, its body, and any fds that go along with it
2564    #[cfg(feature = "request-parsing")]
2565    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2566        if header.minor_opcode != PRINT_SET_IMAGE_RESOLUTION_REQUEST {
2567            return Err(ParseError::InvalidValue);
2568        }
2569        let (context, remaining) = Pcontext::try_parse(value)?;
2570        let (image_resolution, remaining) = u16::try_parse(remaining)?;
2571        let _ = remaining;
2572        Ok(PrintSetImageResolutionRequest {
2573            context,
2574            image_resolution,
2575        })
2576    }
2577}
2578impl Request for PrintSetImageResolutionRequest {
2579    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2580
2581    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2582        let (bufs, fds) = self.serialize(major_opcode);
2583        // Flatten the buffers into a single vector
2584        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2585        (buf, fds)
2586    }
2587}
2588impl crate::x11_utils::ReplyRequest for PrintSetImageResolutionRequest {
2589    type Reply = PrintSetImageResolutionReply;
2590}
2591
2592#[derive(Clone, Copy, Default)]
2593#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2594#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2595pub struct PrintSetImageResolutionReply {
2596    pub status: bool,
2597    pub sequence: u16,
2598    pub length: u32,
2599    pub previous_resolutions: u16,
2600}
2601impl_debug_if_no_extra_traits!(PrintSetImageResolutionReply, "PrintSetImageResolutionReply");
2602impl TryParse for PrintSetImageResolutionReply {
2603    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2604        let remaining = initial_value;
2605        let (response_type, remaining) = u8::try_parse(remaining)?;
2606        let (status, remaining) = bool::try_parse(remaining)?;
2607        let (sequence, remaining) = u16::try_parse(remaining)?;
2608        let (length, remaining) = u32::try_parse(remaining)?;
2609        let (previous_resolutions, remaining) = u16::try_parse(remaining)?;
2610        if response_type != 1 {
2611            return Err(ParseError::InvalidValue);
2612        }
2613        let result = PrintSetImageResolutionReply { status, sequence, length, previous_resolutions };
2614        let _ = remaining;
2615        let remaining = initial_value.get(32 + length as usize * 4..)
2616            .ok_or(ParseError::InsufficientData)?;
2617        Ok((result, remaining))
2618    }
2619}
2620impl Serialize for PrintSetImageResolutionReply {
2621    type Bytes = [u8; 10];
2622    fn serialize(&self) -> [u8; 10] {
2623        let response_type_bytes = &[1];
2624        let status_bytes = self.status.serialize();
2625        let sequence_bytes = self.sequence.serialize();
2626        let length_bytes = self.length.serialize();
2627        let previous_resolutions_bytes = self.previous_resolutions.serialize();
2628        [
2629            response_type_bytes[0],
2630            status_bytes[0],
2631            sequence_bytes[0],
2632            sequence_bytes[1],
2633            length_bytes[0],
2634            length_bytes[1],
2635            length_bytes[2],
2636            length_bytes[3],
2637            previous_resolutions_bytes[0],
2638            previous_resolutions_bytes[1],
2639        ]
2640    }
2641    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2642        bytes.reserve(10);
2643        let response_type_bytes = &[1];
2644        bytes.push(response_type_bytes[0]);
2645        self.status.serialize_into(bytes);
2646        self.sequence.serialize_into(bytes);
2647        self.length.serialize_into(bytes);
2648        self.previous_resolutions.serialize_into(bytes);
2649    }
2650}
2651
2652/// Opcode for the PrintGetImageResolution request
2653pub const PRINT_GET_IMAGE_RESOLUTION_REQUEST: u8 = 24;
2654#[derive(Clone, Copy, Default)]
2655#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2656#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2657pub struct PrintGetImageResolutionRequest {
2658    pub context: Pcontext,
2659}
2660impl_debug_if_no_extra_traits!(PrintGetImageResolutionRequest, "PrintGetImageResolutionRequest");
2661impl PrintGetImageResolutionRequest {
2662    /// Serialize this request into bytes for the provided connection
2663    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2664        let length_so_far = 0;
2665        let context_bytes = self.context.serialize();
2666        let mut request0 = vec![
2667            major_opcode,
2668            PRINT_GET_IMAGE_RESOLUTION_REQUEST,
2669            0,
2670            0,
2671            context_bytes[0],
2672            context_bytes[1],
2673            context_bytes[2],
2674            context_bytes[3],
2675        ];
2676        let length_so_far = length_so_far + request0.len();
2677        assert_eq!(length_so_far % 4, 0);
2678        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2679        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2680        ([request0.into()], vec![])
2681    }
2682    /// Parse this request given its header, its body, and any fds that go along with it
2683    #[cfg(feature = "request-parsing")]
2684    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2685        if header.minor_opcode != PRINT_GET_IMAGE_RESOLUTION_REQUEST {
2686            return Err(ParseError::InvalidValue);
2687        }
2688        let (context, remaining) = Pcontext::try_parse(value)?;
2689        let _ = remaining;
2690        Ok(PrintGetImageResolutionRequest {
2691            context,
2692        })
2693    }
2694}
2695impl Request for PrintGetImageResolutionRequest {
2696    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2697
2698    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2699        let (bufs, fds) = self.serialize(major_opcode);
2700        // Flatten the buffers into a single vector
2701        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2702        (buf, fds)
2703    }
2704}
2705impl crate::x11_utils::ReplyRequest for PrintGetImageResolutionRequest {
2706    type Reply = PrintGetImageResolutionReply;
2707}
2708
2709#[derive(Clone, Copy, Default)]
2710#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2711#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2712pub struct PrintGetImageResolutionReply {
2713    pub sequence: u16,
2714    pub length: u32,
2715    pub image_resolution: u16,
2716}
2717impl_debug_if_no_extra_traits!(PrintGetImageResolutionReply, "PrintGetImageResolutionReply");
2718impl TryParse for PrintGetImageResolutionReply {
2719    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2720        let remaining = initial_value;
2721        let (response_type, remaining) = u8::try_parse(remaining)?;
2722        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2723        let (sequence, remaining) = u16::try_parse(remaining)?;
2724        let (length, remaining) = u32::try_parse(remaining)?;
2725        let (image_resolution, remaining) = u16::try_parse(remaining)?;
2726        if response_type != 1 {
2727            return Err(ParseError::InvalidValue);
2728        }
2729        let result = PrintGetImageResolutionReply { sequence, length, image_resolution };
2730        let _ = remaining;
2731        let remaining = initial_value.get(32 + length as usize * 4..)
2732            .ok_or(ParseError::InsufficientData)?;
2733        Ok((result, remaining))
2734    }
2735}
2736impl Serialize for PrintGetImageResolutionReply {
2737    type Bytes = [u8; 10];
2738    fn serialize(&self) -> [u8; 10] {
2739        let response_type_bytes = &[1];
2740        let sequence_bytes = self.sequence.serialize();
2741        let length_bytes = self.length.serialize();
2742        let image_resolution_bytes = self.image_resolution.serialize();
2743        [
2744            response_type_bytes[0],
2745            0,
2746            sequence_bytes[0],
2747            sequence_bytes[1],
2748            length_bytes[0],
2749            length_bytes[1],
2750            length_bytes[2],
2751            length_bytes[3],
2752            image_resolution_bytes[0],
2753            image_resolution_bytes[1],
2754        ]
2755    }
2756    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2757        bytes.reserve(10);
2758        let response_type_bytes = &[1];
2759        bytes.push(response_type_bytes[0]);
2760        bytes.extend_from_slice(&[0; 1]);
2761        self.sequence.serialize_into(bytes);
2762        self.length.serialize_into(bytes);
2763        self.image_resolution.serialize_into(bytes);
2764    }
2765}
2766
2767/// Opcode for the Notify event
2768pub const NOTIFY_EVENT: u8 = 0;
2769#[derive(Clone, Copy, Default)]
2770#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2771#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2772pub struct NotifyEvent {
2773    pub response_type: u8,
2774    pub detail: u8,
2775    pub sequence: u16,
2776    pub context: Pcontext,
2777    pub cancel: bool,
2778}
2779impl_debug_if_no_extra_traits!(NotifyEvent, "NotifyEvent");
2780impl TryParse for NotifyEvent {
2781    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2782        let remaining = initial_value;
2783        let (response_type, remaining) = u8::try_parse(remaining)?;
2784        let (detail, remaining) = u8::try_parse(remaining)?;
2785        let (sequence, remaining) = u16::try_parse(remaining)?;
2786        let (context, remaining) = Pcontext::try_parse(remaining)?;
2787        let (cancel, remaining) = bool::try_parse(remaining)?;
2788        let result = NotifyEvent { response_type, detail, sequence, context, cancel };
2789        let _ = remaining;
2790        let remaining = initial_value.get(32..)
2791            .ok_or(ParseError::InsufficientData)?;
2792        Ok((result, remaining))
2793    }
2794}
2795impl Serialize for NotifyEvent {
2796    type Bytes = [u8; 9];
2797    fn serialize(&self) -> [u8; 9] {
2798        let response_type_bytes = self.response_type.serialize();
2799        let detail_bytes = self.detail.serialize();
2800        let sequence_bytes = self.sequence.serialize();
2801        let context_bytes = self.context.serialize();
2802        let cancel_bytes = self.cancel.serialize();
2803        [
2804            response_type_bytes[0],
2805            detail_bytes[0],
2806            sequence_bytes[0],
2807            sequence_bytes[1],
2808            context_bytes[0],
2809            context_bytes[1],
2810            context_bytes[2],
2811            context_bytes[3],
2812            cancel_bytes[0],
2813        ]
2814    }
2815    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2816        bytes.reserve(9);
2817        self.response_type.serialize_into(bytes);
2818        self.detail.serialize_into(bytes);
2819        self.sequence.serialize_into(bytes);
2820        self.context.serialize_into(bytes);
2821        self.cancel.serialize_into(bytes);
2822    }
2823}
2824impl From<&NotifyEvent> for [u8; 32] {
2825    fn from(input: &NotifyEvent) -> Self {
2826        let response_type_bytes = input.response_type.serialize();
2827        let detail_bytes = input.detail.serialize();
2828        let sequence_bytes = input.sequence.serialize();
2829        let context_bytes = input.context.serialize();
2830        let cancel_bytes = input.cancel.serialize();
2831        [
2832            response_type_bytes[0],
2833            detail_bytes[0],
2834            sequence_bytes[0],
2835            sequence_bytes[1],
2836            context_bytes[0],
2837            context_bytes[1],
2838            context_bytes[2],
2839            context_bytes[3],
2840            cancel_bytes[0],
2841            // trailing padding
2842            0,
2843            0,
2844            0,
2845            0,
2846            0,
2847            0,
2848            0,
2849            0,
2850            0,
2851            0,
2852            0,
2853            0,
2854            0,
2855            0,
2856            0,
2857            0,
2858            0,
2859            0,
2860            0,
2861            0,
2862            0,
2863            0,
2864            0,
2865        ]
2866    }
2867}
2868impl From<NotifyEvent> for [u8; 32] {
2869    fn from(input: NotifyEvent) -> Self {
2870        Self::from(&input)
2871    }
2872}
2873
2874/// Opcode for the AttributNotify event
2875pub const ATTRIBUT_NOTIFY_EVENT: u8 = 1;
2876#[derive(Clone, Copy, Default)]
2877#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2878#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2879pub struct AttributNotifyEvent {
2880    pub response_type: u8,
2881    pub detail: u8,
2882    pub sequence: u16,
2883    pub context: Pcontext,
2884}
2885impl_debug_if_no_extra_traits!(AttributNotifyEvent, "AttributNotifyEvent");
2886impl TryParse for AttributNotifyEvent {
2887    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2888        let remaining = initial_value;
2889        let (response_type, remaining) = u8::try_parse(remaining)?;
2890        let (detail, remaining) = u8::try_parse(remaining)?;
2891        let (sequence, remaining) = u16::try_parse(remaining)?;
2892        let (context, remaining) = Pcontext::try_parse(remaining)?;
2893        let result = AttributNotifyEvent { response_type, detail, sequence, context };
2894        let _ = remaining;
2895        let remaining = initial_value.get(32..)
2896            .ok_or(ParseError::InsufficientData)?;
2897        Ok((result, remaining))
2898    }
2899}
2900impl Serialize for AttributNotifyEvent {
2901    type Bytes = [u8; 8];
2902    fn serialize(&self) -> [u8; 8] {
2903        let response_type_bytes = self.response_type.serialize();
2904        let detail_bytes = self.detail.serialize();
2905        let sequence_bytes = self.sequence.serialize();
2906        let context_bytes = self.context.serialize();
2907        [
2908            response_type_bytes[0],
2909            detail_bytes[0],
2910            sequence_bytes[0],
2911            sequence_bytes[1],
2912            context_bytes[0],
2913            context_bytes[1],
2914            context_bytes[2],
2915            context_bytes[3],
2916        ]
2917    }
2918    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2919        bytes.reserve(8);
2920        self.response_type.serialize_into(bytes);
2921        self.detail.serialize_into(bytes);
2922        self.sequence.serialize_into(bytes);
2923        self.context.serialize_into(bytes);
2924    }
2925}
2926impl From<&AttributNotifyEvent> for [u8; 32] {
2927    fn from(input: &AttributNotifyEvent) -> Self {
2928        let response_type_bytes = input.response_type.serialize();
2929        let detail_bytes = input.detail.serialize();
2930        let sequence_bytes = input.sequence.serialize();
2931        let context_bytes = input.context.serialize();
2932        [
2933            response_type_bytes[0],
2934            detail_bytes[0],
2935            sequence_bytes[0],
2936            sequence_bytes[1],
2937            context_bytes[0],
2938            context_bytes[1],
2939            context_bytes[2],
2940            context_bytes[3],
2941            // trailing padding
2942            0,
2943            0,
2944            0,
2945            0,
2946            0,
2947            0,
2948            0,
2949            0,
2950            0,
2951            0,
2952            0,
2953            0,
2954            0,
2955            0,
2956            0,
2957            0,
2958            0,
2959            0,
2960            0,
2961            0,
2962            0,
2963            0,
2964            0,
2965            0,
2966        ]
2967    }
2968}
2969impl From<AttributNotifyEvent> for [u8; 32] {
2970    fn from(input: AttributNotifyEvent) -> Self {
2971        Self::from(&input)
2972    }
2973}
2974
2975/// Opcode for the BadContext error
2976pub const BAD_CONTEXT_ERROR: u8 = 0;
2977
2978/// Opcode for the BadSequence error
2979pub const BAD_SEQUENCE_ERROR: u8 = 1;
2980