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