x11rb_protocol/protocol/
xvmc.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `XvMC` 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::xv;
27
28/// The X11 name of the extension for QueryExtension
29pub const X11_EXTENSION_NAME: &str = "XVideo-MotionCompensation";
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, 1);
38
39pub type Context = u32;
40
41pub type Surface = u32;
42
43pub type Subpicture = u32;
44
45#[derive(Clone, Copy, Default)]
46#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
47#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
48pub struct SurfaceInfo {
49    pub id: Surface,
50    pub chroma_format: u16,
51    pub pad0: u16,
52    pub max_width: u16,
53    pub max_height: u16,
54    pub subpicture_max_width: u16,
55    pub subpicture_max_height: u16,
56    pub mc_type: u32,
57    pub flags: u32,
58}
59impl_debug_if_no_extra_traits!(SurfaceInfo, "SurfaceInfo");
60impl TryParse for SurfaceInfo {
61    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
62        let (id, remaining) = Surface::try_parse(remaining)?;
63        let (chroma_format, remaining) = u16::try_parse(remaining)?;
64        let (pad0, remaining) = u16::try_parse(remaining)?;
65        let (max_width, remaining) = u16::try_parse(remaining)?;
66        let (max_height, remaining) = u16::try_parse(remaining)?;
67        let (subpicture_max_width, remaining) = u16::try_parse(remaining)?;
68        let (subpicture_max_height, remaining) = u16::try_parse(remaining)?;
69        let (mc_type, remaining) = u32::try_parse(remaining)?;
70        let (flags, remaining) = u32::try_parse(remaining)?;
71        let result = SurfaceInfo { id, chroma_format, pad0, max_width, max_height, subpicture_max_width, subpicture_max_height, mc_type, flags };
72        Ok((result, remaining))
73    }
74}
75impl Serialize for SurfaceInfo {
76    type Bytes = [u8; 24];
77    fn serialize(&self) -> [u8; 24] {
78        let id_bytes = self.id.serialize();
79        let chroma_format_bytes = self.chroma_format.serialize();
80        let pad0_bytes = self.pad0.serialize();
81        let max_width_bytes = self.max_width.serialize();
82        let max_height_bytes = self.max_height.serialize();
83        let subpicture_max_width_bytes = self.subpicture_max_width.serialize();
84        let subpicture_max_height_bytes = self.subpicture_max_height.serialize();
85        let mc_type_bytes = self.mc_type.serialize();
86        let flags_bytes = self.flags.serialize();
87        [
88            id_bytes[0],
89            id_bytes[1],
90            id_bytes[2],
91            id_bytes[3],
92            chroma_format_bytes[0],
93            chroma_format_bytes[1],
94            pad0_bytes[0],
95            pad0_bytes[1],
96            max_width_bytes[0],
97            max_width_bytes[1],
98            max_height_bytes[0],
99            max_height_bytes[1],
100            subpicture_max_width_bytes[0],
101            subpicture_max_width_bytes[1],
102            subpicture_max_height_bytes[0],
103            subpicture_max_height_bytes[1],
104            mc_type_bytes[0],
105            mc_type_bytes[1],
106            mc_type_bytes[2],
107            mc_type_bytes[3],
108            flags_bytes[0],
109            flags_bytes[1],
110            flags_bytes[2],
111            flags_bytes[3],
112        ]
113    }
114    fn serialize_into(&self, bytes: &mut Vec<u8>) {
115        bytes.reserve(24);
116        self.id.serialize_into(bytes);
117        self.chroma_format.serialize_into(bytes);
118        self.pad0.serialize_into(bytes);
119        self.max_width.serialize_into(bytes);
120        self.max_height.serialize_into(bytes);
121        self.subpicture_max_width.serialize_into(bytes);
122        self.subpicture_max_height.serialize_into(bytes);
123        self.mc_type.serialize_into(bytes);
124        self.flags.serialize_into(bytes);
125    }
126}
127
128/// Opcode for the QueryVersion request
129pub const QUERY_VERSION_REQUEST: u8 = 0;
130#[derive(Clone, Copy, Default)]
131#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
132#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
133pub struct QueryVersionRequest;
134impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
135impl QueryVersionRequest {
136    /// Serialize this request into bytes for the provided connection
137    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
138        let length_so_far = 0;
139        let mut request0 = vec![
140            major_opcode,
141            QUERY_VERSION_REQUEST,
142            0,
143            0,
144        ];
145        let length_so_far = length_so_far + request0.len();
146        assert_eq!(length_so_far % 4, 0);
147        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
148        request0[2..4].copy_from_slice(&length.to_ne_bytes());
149        ([request0.into()], vec![])
150    }
151    /// Parse this request given its header, its body, and any fds that go along with it
152    #[cfg(feature = "request-parsing")]
153    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
154        if header.minor_opcode != QUERY_VERSION_REQUEST {
155            return Err(ParseError::InvalidValue);
156        }
157        let _ = value;
158        Ok(QueryVersionRequest
159        )
160    }
161}
162impl Request for QueryVersionRequest {
163    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
164
165    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
166        let (bufs, fds) = self.serialize(major_opcode);
167        // Flatten the buffers into a single vector
168        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
169        (buf, fds)
170    }
171}
172impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
173    type Reply = QueryVersionReply;
174}
175
176#[derive(Clone, Copy, Default)]
177#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
178#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
179pub struct QueryVersionReply {
180    pub sequence: u16,
181    pub length: u32,
182    pub major: u32,
183    pub minor: u32,
184}
185impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
186impl TryParse for QueryVersionReply {
187    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
188        let remaining = initial_value;
189        let (response_type, remaining) = u8::try_parse(remaining)?;
190        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
191        let (sequence, remaining) = u16::try_parse(remaining)?;
192        let (length, remaining) = u32::try_parse(remaining)?;
193        let (major, remaining) = u32::try_parse(remaining)?;
194        let (minor, remaining) = u32::try_parse(remaining)?;
195        if response_type != 1 {
196            return Err(ParseError::InvalidValue);
197        }
198        let result = QueryVersionReply { sequence, length, major, minor };
199        let _ = remaining;
200        let remaining = initial_value.get(32 + length as usize * 4..)
201            .ok_or(ParseError::InsufficientData)?;
202        Ok((result, remaining))
203    }
204}
205impl Serialize for QueryVersionReply {
206    type Bytes = [u8; 16];
207    fn serialize(&self) -> [u8; 16] {
208        let response_type_bytes = &[1];
209        let sequence_bytes = self.sequence.serialize();
210        let length_bytes = self.length.serialize();
211        let major_bytes = self.major.serialize();
212        let minor_bytes = self.minor.serialize();
213        [
214            response_type_bytes[0],
215            0,
216            sequence_bytes[0],
217            sequence_bytes[1],
218            length_bytes[0],
219            length_bytes[1],
220            length_bytes[2],
221            length_bytes[3],
222            major_bytes[0],
223            major_bytes[1],
224            major_bytes[2],
225            major_bytes[3],
226            minor_bytes[0],
227            minor_bytes[1],
228            minor_bytes[2],
229            minor_bytes[3],
230        ]
231    }
232    fn serialize_into(&self, bytes: &mut Vec<u8>) {
233        bytes.reserve(16);
234        let response_type_bytes = &[1];
235        bytes.push(response_type_bytes[0]);
236        bytes.extend_from_slice(&[0; 1]);
237        self.sequence.serialize_into(bytes);
238        self.length.serialize_into(bytes);
239        self.major.serialize_into(bytes);
240        self.minor.serialize_into(bytes);
241    }
242}
243
244/// Opcode for the ListSurfaceTypes request
245pub const LIST_SURFACE_TYPES_REQUEST: u8 = 1;
246#[derive(Clone, Copy, Default)]
247#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
248#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
249pub struct ListSurfaceTypesRequest {
250    pub port_id: xv::Port,
251}
252impl_debug_if_no_extra_traits!(ListSurfaceTypesRequest, "ListSurfaceTypesRequest");
253impl ListSurfaceTypesRequest {
254    /// Serialize this request into bytes for the provided connection
255    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
256        let length_so_far = 0;
257        let port_id_bytes = self.port_id.serialize();
258        let mut request0 = vec![
259            major_opcode,
260            LIST_SURFACE_TYPES_REQUEST,
261            0,
262            0,
263            port_id_bytes[0],
264            port_id_bytes[1],
265            port_id_bytes[2],
266            port_id_bytes[3],
267        ];
268        let length_so_far = length_so_far + request0.len();
269        assert_eq!(length_so_far % 4, 0);
270        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
271        request0[2..4].copy_from_slice(&length.to_ne_bytes());
272        ([request0.into()], vec![])
273    }
274    /// Parse this request given its header, its body, and any fds that go along with it
275    #[cfg(feature = "request-parsing")]
276    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
277        if header.minor_opcode != LIST_SURFACE_TYPES_REQUEST {
278            return Err(ParseError::InvalidValue);
279        }
280        let (port_id, remaining) = xv::Port::try_parse(value)?;
281        let _ = remaining;
282        Ok(ListSurfaceTypesRequest {
283            port_id,
284        })
285    }
286}
287impl Request for ListSurfaceTypesRequest {
288    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
289
290    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
291        let (bufs, fds) = self.serialize(major_opcode);
292        // Flatten the buffers into a single vector
293        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
294        (buf, fds)
295    }
296}
297impl crate::x11_utils::ReplyRequest for ListSurfaceTypesRequest {
298    type Reply = ListSurfaceTypesReply;
299}
300
301#[derive(Clone, Default)]
302#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
303#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
304pub struct ListSurfaceTypesReply {
305    pub sequence: u16,
306    pub length: u32,
307    pub surfaces: Vec<SurfaceInfo>,
308}
309impl_debug_if_no_extra_traits!(ListSurfaceTypesReply, "ListSurfaceTypesReply");
310impl TryParse for ListSurfaceTypesReply {
311    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
312        let remaining = initial_value;
313        let (response_type, remaining) = u8::try_parse(remaining)?;
314        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
315        let (sequence, remaining) = u16::try_parse(remaining)?;
316        let (length, remaining) = u32::try_parse(remaining)?;
317        let (num, remaining) = u32::try_parse(remaining)?;
318        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
319        let (surfaces, remaining) = crate::x11_utils::parse_list::<SurfaceInfo>(remaining, num.try_to_usize()?)?;
320        if response_type != 1 {
321            return Err(ParseError::InvalidValue);
322        }
323        let result = ListSurfaceTypesReply { sequence, length, surfaces };
324        let _ = remaining;
325        let remaining = initial_value.get(32 + length as usize * 4..)
326            .ok_or(ParseError::InsufficientData)?;
327        Ok((result, remaining))
328    }
329}
330impl Serialize for ListSurfaceTypesReply {
331    type Bytes = Vec<u8>;
332    fn serialize(&self) -> Vec<u8> {
333        let mut result = Vec::new();
334        self.serialize_into(&mut result);
335        result
336    }
337    fn serialize_into(&self, bytes: &mut Vec<u8>) {
338        bytes.reserve(32);
339        let response_type_bytes = &[1];
340        bytes.push(response_type_bytes[0]);
341        bytes.extend_from_slice(&[0; 1]);
342        self.sequence.serialize_into(bytes);
343        self.length.serialize_into(bytes);
344        let num = u32::try_from(self.surfaces.len()).expect("`surfaces` has too many elements");
345        num.serialize_into(bytes);
346        bytes.extend_from_slice(&[0; 20]);
347        self.surfaces.serialize_into(bytes);
348    }
349}
350impl ListSurfaceTypesReply {
351    /// Get the value of the `num` field.
352    ///
353    /// The `num` field is used as the length field of the `surfaces` field.
354    /// This function computes the field's value again based on the length of the list.
355    ///
356    /// # Panics
357    ///
358    /// Panics if the value cannot be represented in the target type. This
359    /// cannot happen with values of the struct received from the X11 server.
360    pub fn num(&self) -> u32 {
361        self.surfaces.len()
362            .try_into().unwrap()
363    }
364}
365
366/// Opcode for the CreateContext request
367pub const CREATE_CONTEXT_REQUEST: u8 = 2;
368#[derive(Clone, Copy, Default)]
369#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
370#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
371pub struct CreateContextRequest {
372    pub context_id: Context,
373    pub port_id: xv::Port,
374    pub surface_id: Surface,
375    pub width: u16,
376    pub height: u16,
377    pub flags: u32,
378}
379impl_debug_if_no_extra_traits!(CreateContextRequest, "CreateContextRequest");
380impl CreateContextRequest {
381    /// Serialize this request into bytes for the provided connection
382    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
383        let length_so_far = 0;
384        let context_id_bytes = self.context_id.serialize();
385        let port_id_bytes = self.port_id.serialize();
386        let surface_id_bytes = self.surface_id.serialize();
387        let width_bytes = self.width.serialize();
388        let height_bytes = self.height.serialize();
389        let flags_bytes = self.flags.serialize();
390        let mut request0 = vec![
391            major_opcode,
392            CREATE_CONTEXT_REQUEST,
393            0,
394            0,
395            context_id_bytes[0],
396            context_id_bytes[1],
397            context_id_bytes[2],
398            context_id_bytes[3],
399            port_id_bytes[0],
400            port_id_bytes[1],
401            port_id_bytes[2],
402            port_id_bytes[3],
403            surface_id_bytes[0],
404            surface_id_bytes[1],
405            surface_id_bytes[2],
406            surface_id_bytes[3],
407            width_bytes[0],
408            width_bytes[1],
409            height_bytes[0],
410            height_bytes[1],
411            flags_bytes[0],
412            flags_bytes[1],
413            flags_bytes[2],
414            flags_bytes[3],
415        ];
416        let length_so_far = length_so_far + request0.len();
417        assert_eq!(length_so_far % 4, 0);
418        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
419        request0[2..4].copy_from_slice(&length.to_ne_bytes());
420        ([request0.into()], vec![])
421    }
422    /// Parse this request given its header, its body, and any fds that go along with it
423    #[cfg(feature = "request-parsing")]
424    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
425        if header.minor_opcode != CREATE_CONTEXT_REQUEST {
426            return Err(ParseError::InvalidValue);
427        }
428        let (context_id, remaining) = Context::try_parse(value)?;
429        let (port_id, remaining) = xv::Port::try_parse(remaining)?;
430        let (surface_id, remaining) = Surface::try_parse(remaining)?;
431        let (width, remaining) = u16::try_parse(remaining)?;
432        let (height, remaining) = u16::try_parse(remaining)?;
433        let (flags, remaining) = u32::try_parse(remaining)?;
434        let _ = remaining;
435        Ok(CreateContextRequest {
436            context_id,
437            port_id,
438            surface_id,
439            width,
440            height,
441            flags,
442        })
443    }
444}
445impl Request for CreateContextRequest {
446    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
447
448    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
449        let (bufs, fds) = self.serialize(major_opcode);
450        // Flatten the buffers into a single vector
451        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
452        (buf, fds)
453    }
454}
455impl crate::x11_utils::ReplyRequest for CreateContextRequest {
456    type Reply = CreateContextReply;
457}
458
459#[derive(Clone, Default)]
460#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
461#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
462pub struct CreateContextReply {
463    pub sequence: u16,
464    pub width_actual: u16,
465    pub height_actual: u16,
466    pub flags_return: u32,
467    pub priv_data: Vec<u32>,
468}
469impl_debug_if_no_extra_traits!(CreateContextReply, "CreateContextReply");
470impl TryParse for CreateContextReply {
471    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
472        let remaining = initial_value;
473        let (response_type, remaining) = u8::try_parse(remaining)?;
474        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
475        let (sequence, remaining) = u16::try_parse(remaining)?;
476        let (length, remaining) = u32::try_parse(remaining)?;
477        let (width_actual, remaining) = u16::try_parse(remaining)?;
478        let (height_actual, remaining) = u16::try_parse(remaining)?;
479        let (flags_return, remaining) = u32::try_parse(remaining)?;
480        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
481        let (priv_data, remaining) = crate::x11_utils::parse_list::<u32>(remaining, length.try_to_usize()?)?;
482        if response_type != 1 {
483            return Err(ParseError::InvalidValue);
484        }
485        let result = CreateContextReply { sequence, width_actual, height_actual, flags_return, priv_data };
486        let _ = remaining;
487        let remaining = initial_value.get(32 + length as usize * 4..)
488            .ok_or(ParseError::InsufficientData)?;
489        Ok((result, remaining))
490    }
491}
492impl Serialize for CreateContextReply {
493    type Bytes = Vec<u8>;
494    fn serialize(&self) -> Vec<u8> {
495        let mut result = Vec::new();
496        self.serialize_into(&mut result);
497        result
498    }
499    fn serialize_into(&self, bytes: &mut Vec<u8>) {
500        bytes.reserve(36);
501        let response_type_bytes = &[1];
502        bytes.push(response_type_bytes[0]);
503        bytes.extend_from_slice(&[0; 1]);
504        self.sequence.serialize_into(bytes);
505        let length = u32::try_from(self.priv_data.len()).expect("`priv_data` has too many elements");
506        length.serialize_into(bytes);
507        self.width_actual.serialize_into(bytes);
508        self.height_actual.serialize_into(bytes);
509        self.flags_return.serialize_into(bytes);
510        bytes.extend_from_slice(&[0; 20]);
511        self.priv_data.serialize_into(bytes);
512    }
513}
514impl CreateContextReply {
515    /// Get the value of the `length` field.
516    ///
517    /// The `length` field is used as the length field of the `priv_data` field.
518    /// This function computes the field's value again based on the length of the list.
519    ///
520    /// # Panics
521    ///
522    /// Panics if the value cannot be represented in the target type. This
523    /// cannot happen with values of the struct received from the X11 server.
524    pub fn length(&self) -> u32 {
525        self.priv_data.len()
526            .try_into().unwrap()
527    }
528}
529
530/// Opcode for the DestroyContext request
531pub const DESTROY_CONTEXT_REQUEST: u8 = 3;
532#[derive(Clone, Copy, Default)]
533#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
534#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
535pub struct DestroyContextRequest {
536    pub context_id: Context,
537}
538impl_debug_if_no_extra_traits!(DestroyContextRequest, "DestroyContextRequest");
539impl DestroyContextRequest {
540    /// Serialize this request into bytes for the provided connection
541    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
542        let length_so_far = 0;
543        let context_id_bytes = self.context_id.serialize();
544        let mut request0 = vec![
545            major_opcode,
546            DESTROY_CONTEXT_REQUEST,
547            0,
548            0,
549            context_id_bytes[0],
550            context_id_bytes[1],
551            context_id_bytes[2],
552            context_id_bytes[3],
553        ];
554        let length_so_far = length_so_far + request0.len();
555        assert_eq!(length_so_far % 4, 0);
556        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
557        request0[2..4].copy_from_slice(&length.to_ne_bytes());
558        ([request0.into()], vec![])
559    }
560    /// Parse this request given its header, its body, and any fds that go along with it
561    #[cfg(feature = "request-parsing")]
562    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
563        if header.minor_opcode != DESTROY_CONTEXT_REQUEST {
564            return Err(ParseError::InvalidValue);
565        }
566        let (context_id, remaining) = Context::try_parse(value)?;
567        let _ = remaining;
568        Ok(DestroyContextRequest {
569            context_id,
570        })
571    }
572}
573impl Request for DestroyContextRequest {
574    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
575
576    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
577        let (bufs, fds) = self.serialize(major_opcode);
578        // Flatten the buffers into a single vector
579        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
580        (buf, fds)
581    }
582}
583impl crate::x11_utils::VoidRequest for DestroyContextRequest {
584}
585
586/// Opcode for the CreateSurface request
587pub const CREATE_SURFACE_REQUEST: u8 = 4;
588#[derive(Clone, Copy, Default)]
589#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
590#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
591pub struct CreateSurfaceRequest {
592    pub surface_id: Surface,
593    pub context_id: Context,
594}
595impl_debug_if_no_extra_traits!(CreateSurfaceRequest, "CreateSurfaceRequest");
596impl CreateSurfaceRequest {
597    /// Serialize this request into bytes for the provided connection
598    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
599        let length_so_far = 0;
600        let surface_id_bytes = self.surface_id.serialize();
601        let context_id_bytes = self.context_id.serialize();
602        let mut request0 = vec![
603            major_opcode,
604            CREATE_SURFACE_REQUEST,
605            0,
606            0,
607            surface_id_bytes[0],
608            surface_id_bytes[1],
609            surface_id_bytes[2],
610            surface_id_bytes[3],
611            context_id_bytes[0],
612            context_id_bytes[1],
613            context_id_bytes[2],
614            context_id_bytes[3],
615        ];
616        let length_so_far = length_so_far + request0.len();
617        assert_eq!(length_so_far % 4, 0);
618        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
619        request0[2..4].copy_from_slice(&length.to_ne_bytes());
620        ([request0.into()], vec![])
621    }
622    /// Parse this request given its header, its body, and any fds that go along with it
623    #[cfg(feature = "request-parsing")]
624    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
625        if header.minor_opcode != CREATE_SURFACE_REQUEST {
626            return Err(ParseError::InvalidValue);
627        }
628        let (surface_id, remaining) = Surface::try_parse(value)?;
629        let (context_id, remaining) = Context::try_parse(remaining)?;
630        let _ = remaining;
631        Ok(CreateSurfaceRequest {
632            surface_id,
633            context_id,
634        })
635    }
636}
637impl Request for CreateSurfaceRequest {
638    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
639
640    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
641        let (bufs, fds) = self.serialize(major_opcode);
642        // Flatten the buffers into a single vector
643        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
644        (buf, fds)
645    }
646}
647impl crate::x11_utils::ReplyRequest for CreateSurfaceRequest {
648    type Reply = CreateSurfaceReply;
649}
650
651#[derive(Clone, Default)]
652#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
653#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
654pub struct CreateSurfaceReply {
655    pub sequence: u16,
656    pub priv_data: Vec<u32>,
657}
658impl_debug_if_no_extra_traits!(CreateSurfaceReply, "CreateSurfaceReply");
659impl TryParse for CreateSurfaceReply {
660    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
661        let remaining = initial_value;
662        let (response_type, remaining) = u8::try_parse(remaining)?;
663        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
664        let (sequence, remaining) = u16::try_parse(remaining)?;
665        let (length, remaining) = u32::try_parse(remaining)?;
666        let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?;
667        let (priv_data, remaining) = crate::x11_utils::parse_list::<u32>(remaining, length.try_to_usize()?)?;
668        if response_type != 1 {
669            return Err(ParseError::InvalidValue);
670        }
671        let result = CreateSurfaceReply { sequence, priv_data };
672        let _ = remaining;
673        let remaining = initial_value.get(32 + length as usize * 4..)
674            .ok_or(ParseError::InsufficientData)?;
675        Ok((result, remaining))
676    }
677}
678impl Serialize for CreateSurfaceReply {
679    type Bytes = Vec<u8>;
680    fn serialize(&self) -> Vec<u8> {
681        let mut result = Vec::new();
682        self.serialize_into(&mut result);
683        result
684    }
685    fn serialize_into(&self, bytes: &mut Vec<u8>) {
686        bytes.reserve(32);
687        let response_type_bytes = &[1];
688        bytes.push(response_type_bytes[0]);
689        bytes.extend_from_slice(&[0; 1]);
690        self.sequence.serialize_into(bytes);
691        let length = u32::try_from(self.priv_data.len()).expect("`priv_data` has too many elements");
692        length.serialize_into(bytes);
693        bytes.extend_from_slice(&[0; 24]);
694        self.priv_data.serialize_into(bytes);
695    }
696}
697impl CreateSurfaceReply {
698    /// Get the value of the `length` field.
699    ///
700    /// The `length` field is used as the length field of the `priv_data` field.
701    /// This function computes the field's value again based on the length of the list.
702    ///
703    /// # Panics
704    ///
705    /// Panics if the value cannot be represented in the target type. This
706    /// cannot happen with values of the struct received from the X11 server.
707    pub fn length(&self) -> u32 {
708        self.priv_data.len()
709            .try_into().unwrap()
710    }
711}
712
713/// Opcode for the DestroySurface request
714pub const DESTROY_SURFACE_REQUEST: u8 = 5;
715#[derive(Clone, Copy, Default)]
716#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
717#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
718pub struct DestroySurfaceRequest {
719    pub surface_id: Surface,
720}
721impl_debug_if_no_extra_traits!(DestroySurfaceRequest, "DestroySurfaceRequest");
722impl DestroySurfaceRequest {
723    /// Serialize this request into bytes for the provided connection
724    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
725        let length_so_far = 0;
726        let surface_id_bytes = self.surface_id.serialize();
727        let mut request0 = vec![
728            major_opcode,
729            DESTROY_SURFACE_REQUEST,
730            0,
731            0,
732            surface_id_bytes[0],
733            surface_id_bytes[1],
734            surface_id_bytes[2],
735            surface_id_bytes[3],
736        ];
737        let length_so_far = length_so_far + request0.len();
738        assert_eq!(length_so_far % 4, 0);
739        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
740        request0[2..4].copy_from_slice(&length.to_ne_bytes());
741        ([request0.into()], vec![])
742    }
743    /// Parse this request given its header, its body, and any fds that go along with it
744    #[cfg(feature = "request-parsing")]
745    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
746        if header.minor_opcode != DESTROY_SURFACE_REQUEST {
747            return Err(ParseError::InvalidValue);
748        }
749        let (surface_id, remaining) = Surface::try_parse(value)?;
750        let _ = remaining;
751        Ok(DestroySurfaceRequest {
752            surface_id,
753        })
754    }
755}
756impl Request for DestroySurfaceRequest {
757    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
758
759    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
760        let (bufs, fds) = self.serialize(major_opcode);
761        // Flatten the buffers into a single vector
762        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
763        (buf, fds)
764    }
765}
766impl crate::x11_utils::VoidRequest for DestroySurfaceRequest {
767}
768
769/// Opcode for the CreateSubpicture request
770pub const CREATE_SUBPICTURE_REQUEST: u8 = 6;
771#[derive(Clone, Copy, Default)]
772#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
773#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
774pub struct CreateSubpictureRequest {
775    pub subpicture_id: Subpicture,
776    pub context: Context,
777    pub xvimage_id: u32,
778    pub width: u16,
779    pub height: u16,
780}
781impl_debug_if_no_extra_traits!(CreateSubpictureRequest, "CreateSubpictureRequest");
782impl CreateSubpictureRequest {
783    /// Serialize this request into bytes for the provided connection
784    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
785        let length_so_far = 0;
786        let subpicture_id_bytes = self.subpicture_id.serialize();
787        let context_bytes = self.context.serialize();
788        let xvimage_id_bytes = self.xvimage_id.serialize();
789        let width_bytes = self.width.serialize();
790        let height_bytes = self.height.serialize();
791        let mut request0 = vec![
792            major_opcode,
793            CREATE_SUBPICTURE_REQUEST,
794            0,
795            0,
796            subpicture_id_bytes[0],
797            subpicture_id_bytes[1],
798            subpicture_id_bytes[2],
799            subpicture_id_bytes[3],
800            context_bytes[0],
801            context_bytes[1],
802            context_bytes[2],
803            context_bytes[3],
804            xvimage_id_bytes[0],
805            xvimage_id_bytes[1],
806            xvimage_id_bytes[2],
807            xvimage_id_bytes[3],
808            width_bytes[0],
809            width_bytes[1],
810            height_bytes[0],
811            height_bytes[1],
812        ];
813        let length_so_far = length_so_far + request0.len();
814        assert_eq!(length_so_far % 4, 0);
815        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
816        request0[2..4].copy_from_slice(&length.to_ne_bytes());
817        ([request0.into()], vec![])
818    }
819    /// Parse this request given its header, its body, and any fds that go along with it
820    #[cfg(feature = "request-parsing")]
821    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
822        if header.minor_opcode != CREATE_SUBPICTURE_REQUEST {
823            return Err(ParseError::InvalidValue);
824        }
825        let (subpicture_id, remaining) = Subpicture::try_parse(value)?;
826        let (context, remaining) = Context::try_parse(remaining)?;
827        let (xvimage_id, remaining) = u32::try_parse(remaining)?;
828        let (width, remaining) = u16::try_parse(remaining)?;
829        let (height, remaining) = u16::try_parse(remaining)?;
830        let _ = remaining;
831        Ok(CreateSubpictureRequest {
832            subpicture_id,
833            context,
834            xvimage_id,
835            width,
836            height,
837        })
838    }
839}
840impl Request for CreateSubpictureRequest {
841    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
842
843    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
844        let (bufs, fds) = self.serialize(major_opcode);
845        // Flatten the buffers into a single vector
846        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
847        (buf, fds)
848    }
849}
850impl crate::x11_utils::ReplyRequest for CreateSubpictureRequest {
851    type Reply = CreateSubpictureReply;
852}
853
854#[derive(Clone, Default)]
855#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
856#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
857pub struct CreateSubpictureReply {
858    pub sequence: u16,
859    pub width_actual: u16,
860    pub height_actual: u16,
861    pub num_palette_entries: u16,
862    pub entry_bytes: u16,
863    pub component_order: [u8; 4],
864    pub priv_data: Vec<u32>,
865}
866impl_debug_if_no_extra_traits!(CreateSubpictureReply, "CreateSubpictureReply");
867impl TryParse for CreateSubpictureReply {
868    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
869        let remaining = initial_value;
870        let (response_type, remaining) = u8::try_parse(remaining)?;
871        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
872        let (sequence, remaining) = u16::try_parse(remaining)?;
873        let (length, remaining) = u32::try_parse(remaining)?;
874        let (width_actual, remaining) = u16::try_parse(remaining)?;
875        let (height_actual, remaining) = u16::try_parse(remaining)?;
876        let (num_palette_entries, remaining) = u16::try_parse(remaining)?;
877        let (entry_bytes, remaining) = u16::try_parse(remaining)?;
878        let (component_order, remaining) = crate::x11_utils::parse_u8_array::<4>(remaining)?;
879        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
880        let (priv_data, remaining) = crate::x11_utils::parse_list::<u32>(remaining, length.try_to_usize()?)?;
881        if response_type != 1 {
882            return Err(ParseError::InvalidValue);
883        }
884        let result = CreateSubpictureReply { sequence, width_actual, height_actual, num_palette_entries, entry_bytes, component_order, priv_data };
885        let _ = remaining;
886        let remaining = initial_value.get(32 + length as usize * 4..)
887            .ok_or(ParseError::InsufficientData)?;
888        Ok((result, remaining))
889    }
890}
891impl Serialize for CreateSubpictureReply {
892    type Bytes = Vec<u8>;
893    fn serialize(&self) -> Vec<u8> {
894        let mut result = Vec::new();
895        self.serialize_into(&mut result);
896        result
897    }
898    fn serialize_into(&self, bytes: &mut Vec<u8>) {
899        bytes.reserve(32);
900        let response_type_bytes = &[1];
901        bytes.push(response_type_bytes[0]);
902        bytes.extend_from_slice(&[0; 1]);
903        self.sequence.serialize_into(bytes);
904        let length = u32::try_from(self.priv_data.len()).expect("`priv_data` has too many elements");
905        length.serialize_into(bytes);
906        self.width_actual.serialize_into(bytes);
907        self.height_actual.serialize_into(bytes);
908        self.num_palette_entries.serialize_into(bytes);
909        self.entry_bytes.serialize_into(bytes);
910        bytes.extend_from_slice(&self.component_order);
911        bytes.extend_from_slice(&[0; 12]);
912        self.priv_data.serialize_into(bytes);
913    }
914}
915impl CreateSubpictureReply {
916    /// Get the value of the `length` field.
917    ///
918    /// The `length` field is used as the length field of the `priv_data` field.
919    /// This function computes the field's value again based on the length of the list.
920    ///
921    /// # Panics
922    ///
923    /// Panics if the value cannot be represented in the target type. This
924    /// cannot happen with values of the struct received from the X11 server.
925    pub fn length(&self) -> u32 {
926        self.priv_data.len()
927            .try_into().unwrap()
928    }
929}
930
931/// Opcode for the DestroySubpicture request
932pub const DESTROY_SUBPICTURE_REQUEST: u8 = 7;
933#[derive(Clone, Copy, Default)]
934#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
935#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
936pub struct DestroySubpictureRequest {
937    pub subpicture_id: Subpicture,
938}
939impl_debug_if_no_extra_traits!(DestroySubpictureRequest, "DestroySubpictureRequest");
940impl DestroySubpictureRequest {
941    /// Serialize this request into bytes for the provided connection
942    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
943        let length_so_far = 0;
944        let subpicture_id_bytes = self.subpicture_id.serialize();
945        let mut request0 = vec![
946            major_opcode,
947            DESTROY_SUBPICTURE_REQUEST,
948            0,
949            0,
950            subpicture_id_bytes[0],
951            subpicture_id_bytes[1],
952            subpicture_id_bytes[2],
953            subpicture_id_bytes[3],
954        ];
955        let length_so_far = length_so_far + request0.len();
956        assert_eq!(length_so_far % 4, 0);
957        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
958        request0[2..4].copy_from_slice(&length.to_ne_bytes());
959        ([request0.into()], vec![])
960    }
961    /// Parse this request given its header, its body, and any fds that go along with it
962    #[cfg(feature = "request-parsing")]
963    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
964        if header.minor_opcode != DESTROY_SUBPICTURE_REQUEST {
965            return Err(ParseError::InvalidValue);
966        }
967        let (subpicture_id, remaining) = Subpicture::try_parse(value)?;
968        let _ = remaining;
969        Ok(DestroySubpictureRequest {
970            subpicture_id,
971        })
972    }
973}
974impl Request for DestroySubpictureRequest {
975    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
976
977    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
978        let (bufs, fds) = self.serialize(major_opcode);
979        // Flatten the buffers into a single vector
980        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
981        (buf, fds)
982    }
983}
984impl crate::x11_utils::VoidRequest for DestroySubpictureRequest {
985}
986
987/// Opcode for the ListSubpictureTypes request
988pub const LIST_SUBPICTURE_TYPES_REQUEST: u8 = 8;
989#[derive(Clone, Copy, Default)]
990#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
991#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
992pub struct ListSubpictureTypesRequest {
993    pub port_id: xv::Port,
994    pub surface_id: Surface,
995}
996impl_debug_if_no_extra_traits!(ListSubpictureTypesRequest, "ListSubpictureTypesRequest");
997impl ListSubpictureTypesRequest {
998    /// Serialize this request into bytes for the provided connection
999    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1000        let length_so_far = 0;
1001        let port_id_bytes = self.port_id.serialize();
1002        let surface_id_bytes = self.surface_id.serialize();
1003        let mut request0 = vec![
1004            major_opcode,
1005            LIST_SUBPICTURE_TYPES_REQUEST,
1006            0,
1007            0,
1008            port_id_bytes[0],
1009            port_id_bytes[1],
1010            port_id_bytes[2],
1011            port_id_bytes[3],
1012            surface_id_bytes[0],
1013            surface_id_bytes[1],
1014            surface_id_bytes[2],
1015            surface_id_bytes[3],
1016        ];
1017        let length_so_far = length_so_far + request0.len();
1018        assert_eq!(length_so_far % 4, 0);
1019        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1020        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1021        ([request0.into()], vec![])
1022    }
1023    /// Parse this request given its header, its body, and any fds that go along with it
1024    #[cfg(feature = "request-parsing")]
1025    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1026        if header.minor_opcode != LIST_SUBPICTURE_TYPES_REQUEST {
1027            return Err(ParseError::InvalidValue);
1028        }
1029        let (port_id, remaining) = xv::Port::try_parse(value)?;
1030        let (surface_id, remaining) = Surface::try_parse(remaining)?;
1031        let _ = remaining;
1032        Ok(ListSubpictureTypesRequest {
1033            port_id,
1034            surface_id,
1035        })
1036    }
1037}
1038impl Request for ListSubpictureTypesRequest {
1039    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1040
1041    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1042        let (bufs, fds) = self.serialize(major_opcode);
1043        // Flatten the buffers into a single vector
1044        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1045        (buf, fds)
1046    }
1047}
1048impl crate::x11_utils::ReplyRequest for ListSubpictureTypesRequest {
1049    type Reply = ListSubpictureTypesReply;
1050}
1051
1052#[derive(Clone, Default)]
1053#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1054#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1055pub struct ListSubpictureTypesReply {
1056    pub sequence: u16,
1057    pub length: u32,
1058    pub types: Vec<xv::ImageFormatInfo>,
1059}
1060impl_debug_if_no_extra_traits!(ListSubpictureTypesReply, "ListSubpictureTypesReply");
1061impl TryParse for ListSubpictureTypesReply {
1062    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1063        let remaining = initial_value;
1064        let (response_type, remaining) = u8::try_parse(remaining)?;
1065        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1066        let (sequence, remaining) = u16::try_parse(remaining)?;
1067        let (length, remaining) = u32::try_parse(remaining)?;
1068        let (num, remaining) = u32::try_parse(remaining)?;
1069        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1070        let (types, remaining) = crate::x11_utils::parse_list::<xv::ImageFormatInfo>(remaining, num.try_to_usize()?)?;
1071        if response_type != 1 {
1072            return Err(ParseError::InvalidValue);
1073        }
1074        let result = ListSubpictureTypesReply { sequence, length, types };
1075        let _ = remaining;
1076        let remaining = initial_value.get(32 + length as usize * 4..)
1077            .ok_or(ParseError::InsufficientData)?;
1078        Ok((result, remaining))
1079    }
1080}
1081impl Serialize for ListSubpictureTypesReply {
1082    type Bytes = Vec<u8>;
1083    fn serialize(&self) -> Vec<u8> {
1084        let mut result = Vec::new();
1085        self.serialize_into(&mut result);
1086        result
1087    }
1088    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1089        bytes.reserve(32);
1090        let response_type_bytes = &[1];
1091        bytes.push(response_type_bytes[0]);
1092        bytes.extend_from_slice(&[0; 1]);
1093        self.sequence.serialize_into(bytes);
1094        self.length.serialize_into(bytes);
1095        let num = u32::try_from(self.types.len()).expect("`types` has too many elements");
1096        num.serialize_into(bytes);
1097        bytes.extend_from_slice(&[0; 20]);
1098        self.types.serialize_into(bytes);
1099    }
1100}
1101impl ListSubpictureTypesReply {
1102    /// Get the value of the `num` field.
1103    ///
1104    /// The `num` field is used as the length field of the `types` field.
1105    /// This function computes the field's value again based on the length of the list.
1106    ///
1107    /// # Panics
1108    ///
1109    /// Panics if the value cannot be represented in the target type. This
1110    /// cannot happen with values of the struct received from the X11 server.
1111    pub fn num(&self) -> u32 {
1112        self.types.len()
1113            .try_into().unwrap()
1114    }
1115}
1116