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