xcb-rust-protocol 0.3.0

Rust x11 connection interface layer
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
#[allow(unused_imports)]
use crate::util::FixedLengthFromBytes;
#[allow(unused_imports)]
use crate::util::FixedLengthSerialize;
#[allow(unused_imports)]
use crate::util::VariableLengthFromBytes;
#[allow(unused_imports)]
use crate::util::VariableLengthSerialize;
pub const EXTENSION_NAME: &str = "XFree86-VidModeExtension";
pub type Syncrange = u32;
pub type Dotclock = u32;
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct ModeFlag(pub u32);
impl ModeFlag {
    pub const POSITIVE_HSYNC: Self = Self(1 << 0);
    pub const NEGATIVE_HSYNC: Self = Self(1 << 1);
    pub const POSITIVE_VSYNC: Self = Self(1 << 2);
    pub const NEGATIVE_VSYNC: Self = Self(1 << 3);
    pub const INTERLACE: Self = Self(1 << 4);
    pub const COMPOSITE_SYNC: Self = Self(1 << 5);
    pub const POSITIVE_CSYNC: Self = Self(1 << 6);
    pub const NEGATIVE_CSYNC: Self = Self(1 << 7);
    pub const H_SKEW: Self = Self(1 << 8);
    pub const BROADCAST: Self = Self(1 << 9);
    pub const PIXMUX: Self = Self(1 << 10);
    pub const DOUBLE_CLOCK: Self = Self(1 << 11);
    pub const HALF_CLOCK: Self = Self(1 << 12);
}
impl FixedLengthSerialize<4> for ModeFlag {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for ModeFlag {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for ModeFlag {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for ModeFlag {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for ModeFlag {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
crate::implement_bit_ops!(ModeFlag);
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct ClockFlag(pub u32);
impl ClockFlag {
    pub const PROGRAMABLE: Self = Self(1 << 0);
}
impl FixedLengthSerialize<4> for ClockFlag {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for ClockFlag {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for ClockFlag {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for ClockFlag {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for ClockFlag {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
crate::implement_bit_ops!(ClockFlag);
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct Permission(pub u32);
impl Permission {
    pub const READ: Self = Self(1 << 0);
    pub const WRITE: Self = Self(1 << 1);
}
impl FixedLengthSerialize<4> for Permission {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for Permission {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for Permission {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for Permission {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for Permission {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
crate::implement_bit_ops!(Permission);
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct ModeInfo {
    pub dotclock: Dotclock,
    pub hdisplay: u16,
    pub hsyncstart: u16,
    pub hsyncend: u16,
    pub htotal: u16,
    pub hskew: u32,
    pub vdisplay: u16,
    pub vsyncstart: u16,
    pub vsyncend: u16,
    pub vtotal: u16,
    pub flags: ModeFlag,
    pub privsize: u32,
}
impl FixedLengthSerialize<48> for ModeInfo {
    #[inline]
    fn serialize_fixed(self) -> [u8; 48] {
        let dotclock_bytes = self.dotclock.serialize_fixed();
        let hdisplay_bytes = self.hdisplay.serialize_fixed();
        let hsyncstart_bytes = self.hsyncstart.serialize_fixed();
        let hsyncend_bytes = self.hsyncend.serialize_fixed();
        let htotal_bytes = self.htotal.serialize_fixed();
        let hskew_bytes = self.hskew.serialize_fixed();
        let vdisplay_bytes = self.vdisplay.serialize_fixed();
        let vsyncstart_bytes = self.vsyncstart.serialize_fixed();
        let vsyncend_bytes = self.vsyncend.serialize_fixed();
        let vtotal_bytes = self.vtotal.serialize_fixed();
        let flags_bytes = self.flags.serialize_fixed();
        let privsize_bytes = self.privsize.serialize_fixed();
        [
            dotclock_bytes[0],
            dotclock_bytes[1],
            dotclock_bytes[2],
            dotclock_bytes[3],
            hdisplay_bytes[0],
            hdisplay_bytes[1],
            hsyncstart_bytes[0],
            hsyncstart_bytes[1],
            hsyncend_bytes[0],
            hsyncend_bytes[1],
            htotal_bytes[0],
            htotal_bytes[1],
            hskew_bytes[0],
            hskew_bytes[1],
            hskew_bytes[2],
            hskew_bytes[3],
            vdisplay_bytes[0],
            vdisplay_bytes[1],
            vsyncstart_bytes[0],
            vsyncstart_bytes[1],
            vsyncend_bytes[0],
            vsyncend_bytes[1],
            vtotal_bytes[0],
            vtotal_bytes[1],
            0,
            0,
            0,
            0,
            flags_bytes[0],
            flags_bytes[1],
            flags_bytes[2],
            flags_bytes[3],
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            privsize_bytes[0],
            privsize_bytes[1],
            privsize_bytes[2],
            privsize_bytes[3],
        ]
    }
}
impl FixedLengthFromBytes<48> for ModeInfo {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            dotclock: Dotclock::from_bytes(bytes.get(0..4).ok_or(crate::error::Error::FromBytes)?)?,
            hdisplay: u16::from_bytes(bytes.get(4..6).ok_or(crate::error::Error::FromBytes)?)?,
            hsyncstart: u16::from_bytes(bytes.get(6..8).ok_or(crate::error::Error::FromBytes)?)?,
            hsyncend: u16::from_bytes(bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?)?,
            htotal: u16::from_bytes(bytes.get(10..12).ok_or(crate::error::Error::FromBytes)?)?,
            hskew: u32::from_bytes(bytes.get(12..16).ok_or(crate::error::Error::FromBytes)?)?,
            vdisplay: u16::from_bytes(bytes.get(16..18).ok_or(crate::error::Error::FromBytes)?)?,
            vsyncstart: u16::from_bytes(bytes.get(18..20).ok_or(crate::error::Error::FromBytes)?)?,
            vsyncend: u16::from_bytes(bytes.get(20..22).ok_or(crate::error::Error::FromBytes)?)?,
            vtotal: u16::from_bytes(bytes.get(22..24).ok_or(crate::error::Error::FromBytes)?)?,
            flags: u32::from_bytes(bytes.get(28..32).ok_or(crate::error::Error::FromBytes)?)?
                .into(),
            privsize: u32::from_bytes(bytes.get(44..48).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct QueryVersionReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub major_version: u16,
    pub minor_version: u16,
}
impl FixedLengthFromBytes<12> for QueryVersionReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            major_version: u16::from_bytes(
                bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?,
            )?,
            minor_version: u16::from_bytes(
                bytes.get(10..12).ok_or(crate::error::Error::FromBytes)?,
            )?,
        })
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetModeLineReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub dotclock: Dotclock,
    pub hdisplay: u16,
    pub hsyncstart: u16,
    pub hsyncend: u16,
    pub htotal: u16,
    pub hskew: u16,
    pub vdisplay: u16,
    pub vsyncstart: u16,
    pub vsyncend: u16,
    pub vtotal: u16,
    pub flags: ModeFlag,
    pub private: alloc::vec::Vec<u8>,
}
impl VariableLengthFromBytes for GetModeLineReply {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        // Padding 1 bytes
        // Padding 2 bytes
        // Padding 12 bytes
        let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
        let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
        let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
        let dotclock = Dotclock::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
        let hdisplay = u16::from_bytes(ptr.get(12..14).ok_or(crate::error::Error::FromBytes)?)?;
        let hsyncstart = u16::from_bytes(ptr.get(14..16).ok_or(crate::error::Error::FromBytes)?)?;
        let hsyncend = u16::from_bytes(ptr.get(16..18).ok_or(crate::error::Error::FromBytes)?)?;
        let htotal = u16::from_bytes(ptr.get(18..20).ok_or(crate::error::Error::FromBytes)?)?;
        let hskew = u16::from_bytes(ptr.get(20..22).ok_or(crate::error::Error::FromBytes)?)?;
        let vdisplay = u16::from_bytes(ptr.get(22..24).ok_or(crate::error::Error::FromBytes)?)?;
        let vsyncstart = u16::from_bytes(ptr.get(24..26).ok_or(crate::error::Error::FromBytes)?)?;
        let vsyncend = u16::from_bytes(ptr.get(26..28).ok_or(crate::error::Error::FromBytes)?)?;
        let vtotal = u16::from_bytes(ptr.get(28..30).ok_or(crate::error::Error::FromBytes)?)?;
        let flags = u32::from_bytes(ptr.get(32..36).ok_or(crate::error::Error::FromBytes)?)?;
        let privsize = u32::from_bytes(ptr.get(48..52).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = privsize as usize;
        let private: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
            ptr.get(52..).ok_or(crate::error::Error::FromBytes)?,
            length_expr,
        )?;
        let offset = length_expr + 52;
        Ok((
            Self {
                response_type,
                sequence,
                length,
                dotclock,
                hdisplay,
                hsyncstart,
                hsyncend,
                htotal,
                hskew,
                vdisplay,
                vsyncstart,
                vsyncend,
                vtotal,
                flags: flags.into(),
                private,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetMonitorReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub hsync: alloc::vec::Vec<Syncrange>,
    pub vsync: alloc::vec::Vec<Syncrange>,
    pub vendor: alloc::vec::Vec<u8>,
    pub alignment_pad: alloc::vec::Vec<u8>,
    pub model: alloc::vec::Vec<u8>,
}
impl VariableLengthFromBytes for GetMonitorReply {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        // Padding 1 bytes
        // Padding 20 bytes
        let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
        let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
        let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
        let vendor_length = u8::from_bytes(ptr.get(8..9).ok_or(crate::error::Error::FromBytes)?)?;
        let model_length = u8::from_bytes(ptr.get(9..10).ok_or(crate::error::Error::FromBytes)?)?;
        let num_hsync = u8::from_bytes(ptr.get(10..11).ok_or(crate::error::Error::FromBytes)?)?;
        let num_vsync = u8::from_bytes(ptr.get(11..12).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = num_hsync as usize;
        let hsync: alloc::vec::Vec<Syncrange> = crate::vec_from_bytes_fixed!(
            ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
            Syncrange,
            length_expr,
            4
        );
        let mut offset = length_expr * 4 + 32;
        let length_expr = num_vsync as usize;
        let vsync: alloc::vec::Vec<Syncrange> = crate::vec_from_bytes_fixed!(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            Syncrange,
            length_expr,
            4
        );
        offset += length_expr * 4;
        let length_expr = vendor_length as usize;
        let vendor: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            length_expr,
        )?;
        offset += length_expr;
        let length_expr = core::ops::Sub::sub(
            core::ops::BitAnd::bitand(
                core::ops::Add::add(vendor_length as u8, 3u8 as u8) as u8,
                core::ops::Not::not(3u8) as u8,
            ) as u8,
            vendor_length as u8,
        ) as usize;
        let alignment_pad: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            length_expr,
        )?;
        offset += length_expr;
        let length_expr = model_length as usize;
        let model: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            length_expr,
        )?;
        offset += length_expr;
        Ok((
            Self {
                response_type,
                sequence,
                length,
                hsync,
                vsync,
                vendor,
                alignment_pad,
                model,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetAllModeLinesReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub modeinfo: alloc::vec::Vec<ModeInfo>,
}
impl VariableLengthFromBytes for GetAllModeLinesReply {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        // Padding 1 bytes
        // Padding 20 bytes
        let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
        let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
        let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
        let modecount = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = modecount as usize;
        let modeinfo: alloc::vec::Vec<ModeInfo> = crate::vec_from_bytes_fixed!(
            ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
            ModeInfo,
            length_expr,
            48
        );
        let offset = length_expr * 48 + 32;
        Ok((
            Self {
                response_type,
                sequence,
                length,
                modeinfo,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct ValidateModeLineReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub status: u32,
}
impl FixedLengthFromBytes<32> for ValidateModeLineReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            status: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct GetViewPortReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub x: u32,
    pub y: u32,
}
impl FixedLengthFromBytes<32> for GetViewPortReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            x: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
            y: u32::from_bytes(bytes.get(12..16).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetDotClocksReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub flags: ClockFlag,
    pub clocks: u32,
    pub maxclocks: u32,
    pub clock: alloc::vec::Vec<u32>,
}
impl VariableLengthFromBytes for GetDotClocksReply {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        // Padding 1 bytes
        // Padding 12 bytes
        let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
        let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
        let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
        let flags = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
        let clocks = u32::from_bytes(ptr.get(12..16).ok_or(crate::error::Error::FromBytes)?)?;
        let maxclocks = u32::from_bytes(ptr.get(16..20).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = core::ops::Mul::mul(
            core::ops::Sub::sub(
                1u32 as u32,
                core::ops::BitAnd::bitand(flags as u32, 1u32 as u32) as u32,
            ) as u32,
            clocks as u32,
        ) as usize;
        let clock: alloc::vec::Vec<u32> = crate::vec_from_bytes_fixed!(
            ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
            u32,
            length_expr,
            4
        );
        let offset = length_expr * 4 + 32;
        Ok((
            Self {
                response_type,
                sequence,
                length,
                flags: flags.into(),
                clocks,
                maxclocks,
                clock,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct GetGammaReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub red: u32,
    pub green: u32,
    pub blue: u32,
}
impl FixedLengthFromBytes<32> for GetGammaReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            red: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
            green: u32::from_bytes(bytes.get(12..16).ok_or(crate::error::Error::FromBytes)?)?,
            blue: u32::from_bytes(bytes.get(16..20).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct GetGammaRampReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub red: alloc::vec::Vec<u16>,
    pub green: alloc::vec::Vec<u16>,
    pub blue: alloc::vec::Vec<u16>,
}
impl VariableLengthFromBytes for GetGammaRampReply {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        // Padding 1 bytes
        // Padding 22 bytes
        let response_type = u8::from_bytes(ptr.get(0..1).ok_or(crate::error::Error::FromBytes)?)?;
        let sequence = u16::from_bytes(ptr.get(2..4).ok_or(crate::error::Error::FromBytes)?)?;
        let length = u32::from_bytes(ptr.get(4..8).ok_or(crate::error::Error::FromBytes)?)?;
        let size = u16::from_bytes(ptr.get(8..10).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = core::ops::BitAnd::bitand(
            core::ops::Add::add(size as u16, 1u16 as u16) as u16,
            core::ops::Not::not(1u16) as u16,
        ) as usize;
        let red: alloc::vec::Vec<u16> = crate::vec_from_bytes_fixed!(
            ptr.get(32..).ok_or(crate::error::Error::FromBytes)?,
            u16,
            length_expr,
            2
        );
        let mut offset = length_expr * 2 + 32;
        let length_expr = core::ops::BitAnd::bitand(
            core::ops::Add::add(size as u16, 1u16 as u16) as u16,
            core::ops::Not::not(1u16) as u16,
        ) as usize;
        let green: alloc::vec::Vec<u16> = crate::vec_from_bytes_fixed!(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            u16,
            length_expr,
            2
        );
        offset += length_expr * 2;
        let length_expr = core::ops::BitAnd::bitand(
            core::ops::Add::add(size as u16, 1u16 as u16) as u16,
            core::ops::Not::not(1u16) as u16,
        ) as usize;
        let blue: alloc::vec::Vec<u16> = crate::vec_from_bytes_fixed!(
            ptr.get(offset..).ok_or(crate::error::Error::FromBytes)?,
            u16,
            length_expr,
            2
        );
        offset += length_expr * 2;
        Ok((
            Self {
                response_type,
                sequence,
                length,
                red,
                green,
                blue,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct GetGammaRampSizeReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub size: u16,
}
impl FixedLengthFromBytes<32> for GetGammaRampSizeReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            size: u16::from_bytes(bytes.get(8..10).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct GetPermissionsReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub permissions: Permission,
}
impl FixedLengthFromBytes<32> for GetPermissionsReply {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            response_type: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            length: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            permissions: u32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?
                .into(),
        })
    }
}
pub const BAD_CLOCK_ERROR: u8 = 0;
pub const BAD_H_TIMINGS_ERROR: u8 = 1;
pub const BAD_V_TIMINGS_ERROR: u8 = 2;
pub const MODE_UNSUITABLE_ERROR: u8 = 3;
pub const EXTENSION_DISABLED_ERROR: u8 = 4;
pub const CLIENT_NOT_LOCAL_ERROR: u8 = 5;
pub const ZOOM_LOCKED_ERROR: u8 = 6;