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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
#[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 = "SYNC";
pub type Alarm = u32;
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct AlarmstateEnum(pub u8);
impl AlarmstateEnum {
    pub const ACTIVE: Self = Self(0);
    pub const INACTIVE: Self = Self(1);
    pub const DESTROYED: Self = Self(2);
}
impl FixedLengthSerialize<1> for AlarmstateEnum {
    #[inline]
    fn serialize_fixed(self) -> [u8; 1] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<1> for AlarmstateEnum {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u8::from_bytes(bytes)?))
    }
}
impl From<u32> for AlarmstateEnum {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u8)
    }
}
impl From<u16> for AlarmstateEnum {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u8)
    }
}
impl From<u8> for AlarmstateEnum {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u8)
    }
}
pub type Counter = u32;
pub type Fence = u32;
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct TesttypeEnum(pub u32);
impl TesttypeEnum {
    pub const POSITIVE_TRANSITION: Self = Self(0);
    pub const NEGATIVE_TRANSITION: Self = Self(1);
    pub const POSITIVE_COMPARISON: Self = Self(2);
    pub const NEGATIVE_COMPARISON: Self = Self(3);
}
impl FixedLengthSerialize<4> for TesttypeEnum {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for TesttypeEnum {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for TesttypeEnum {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for TesttypeEnum {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for TesttypeEnum {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
#[derive(Debug, Default, Copy, Clone, PartialEq)]
pub struct ValuetypeEnum(pub u32);
impl ValuetypeEnum {
    pub const ABSOLUTE: Self = Self(0);
    pub const RELATIVE: Self = Self(1);
}
impl FixedLengthSerialize<4> for ValuetypeEnum {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for ValuetypeEnum {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for ValuetypeEnum {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for ValuetypeEnum {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for ValuetypeEnum {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
pub struct Ca(pub u32);
impl Ca {
    pub const COUNTER: Self = Self(1 << 0);
    pub const VALUE_TYPE: Self = Self(1 << 1);
    pub const VALUE: Self = Self(1 << 2);
    pub const TEST_TYPE: Self = Self(1 << 3);
    pub const DELTA: Self = Self(1 << 4);
    pub const EVENTS: Self = Self(1 << 5);
}
impl FixedLengthSerialize<4> for Ca {
    #[inline]
    fn serialize_fixed(self) -> [u8; 4] {
        self.0.serialize_fixed()
    }
}
impl FixedLengthFromBytes<4> for Ca {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self(u32::from_bytes(bytes)?))
    }
}
impl From<u32> for Ca {
    #[inline]
    fn from(val: u32) -> Self {
        Self(val as u32)
    }
}
impl From<u16> for Ca {
    #[inline]
    fn from(val: u16) -> Self {
        Self(val as u32)
    }
}
impl From<u8> for Ca {
    #[inline]
    fn from(val: u8) -> Self {
        Self(val as u32)
    }
}
crate::implement_bit_ops!(Ca);
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct Int64 {
    pub hi: i32,
    pub lo: u32,
}
impl FixedLengthSerialize<8> for Int64 {
    #[inline]
    fn serialize_fixed(self) -> [u8; 8] {
        let hi_bytes = self.hi.serialize_fixed();
        let lo_bytes = self.lo.serialize_fixed();
        [
            hi_bytes[0],
            hi_bytes[1],
            hi_bytes[2],
            hi_bytes[3],
            lo_bytes[0],
            lo_bytes[1],
            lo_bytes[2],
            lo_bytes[3],
        ]
    }
}
impl FixedLengthFromBytes<8> for Int64 {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            hi: i32::from_bytes(bytes.get(0..4).ok_or(crate::error::Error::FromBytes)?)?,
            lo: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct Systemcounter {
    pub counter: Counter,
    pub resolution: Int64,
    pub name: alloc::vec::Vec<u8>,
}
impl VariableLengthSerialize for Systemcounter {
    fn serialize_into(self, buf: &mut [u8]) -> crate::error::Result<usize> {
        let buf_ptr = buf;
        let name_len =
            u16::try_from(self.name.len()).map_err(|_| crate::error::Error::Serialize)?;
        buf_ptr
            .get_mut(0..4)
            .ok_or(crate::error::Error::Serialize)?
            .copy_from_slice(&self.counter.serialize_fixed());
        buf_ptr
            .get_mut(4..12)
            .ok_or(crate::error::Error::Serialize)?
            .copy_from_slice(&self.resolution.serialize_fixed());
        buf_ptr
            .get_mut(12..14)
            .ok_or(crate::error::Error::Serialize)?
            .copy_from_slice(
                &(u16::try_from(name_len).map_err(|_| crate::error::Error::Serialize)?)
                    .serialize_fixed(),
            );
        let list_len = self.name.len();
        crate::util::u8_vec_serialize_into(
            buf_ptr
                .get_mut(14..)
                .ok_or(crate::error::Error::Serialize)?,
            &self.name,
        )?;
        let mut offset = list_len + 14;
        // Align 4 bytes
        offset += (4 - (offset % 4)) % 4;
        Ok(offset)
    }
}
impl VariableLengthFromBytes for Systemcounter {
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<(Self, usize)> {
        let ptr = bytes;
        let counter = Counter::from_bytes(ptr.get(0..4).ok_or(crate::error::Error::FromBytes)?)?;
        let resolution = Int64::from_bytes(ptr.get(4..12).ok_or(crate::error::Error::FromBytes)?)?;
        let name_len = u16::from_bytes(ptr.get(12..14).ok_or(crate::error::Error::FromBytes)?)?;
        let length_expr = name_len as usize;
        let name: alloc::vec::Vec<u8> = crate::util::u8_vec_from_bytes(
            ptr.get(14..).ok_or(crate::error::Error::FromBytes)?,
            length_expr,
        )?;
        let mut offset = length_expr + 14;
        // Align 4 bytes
        offset += (4 - (offset % 4)) % 4;
        Ok((
            Self {
                counter,
                resolution,
                name,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct Trigger {
    pub counter: Counter,
    pub wait_type: ValuetypeEnum,
    pub wait_value: Int64,
    pub test_type: TesttypeEnum,
}
impl FixedLengthSerialize<20> for Trigger {
    #[inline]
    fn serialize_fixed(self) -> [u8; 20] {
        let counter_bytes = self.counter.serialize_fixed();
        let wait_type_bytes = self.wait_type.serialize_fixed();
        let wait_value_bytes = self.wait_value.serialize_fixed();
        let test_type_bytes = self.test_type.serialize_fixed();
        [
            counter_bytes[0],
            counter_bytes[1],
            counter_bytes[2],
            counter_bytes[3],
            wait_type_bytes[0],
            wait_type_bytes[1],
            wait_type_bytes[2],
            wait_type_bytes[3],
            wait_value_bytes[0],
            wait_value_bytes[1],
            wait_value_bytes[2],
            wait_value_bytes[3],
            wait_value_bytes[4],
            wait_value_bytes[5],
            wait_value_bytes[6],
            wait_value_bytes[7],
            test_type_bytes[0],
            test_type_bytes[1],
            test_type_bytes[2],
            test_type_bytes[3],
        ]
    }
}
impl FixedLengthFromBytes<20> for Trigger {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            counter: Counter::from_bytes(bytes.get(0..4).ok_or(crate::error::Error::FromBytes)?)?,
            wait_type: u32::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?
                .into(),
            wait_value: Int64::from_bytes(bytes.get(8..16).ok_or(crate::error::Error::FromBytes)?)?,
            test_type: u32::from_bytes(bytes.get(16..20).ok_or(crate::error::Error::FromBytes)?)?
                .into(),
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct Waitcondition {
    pub trigger: Trigger,
    pub event_threshold: Int64,
}
impl FixedLengthSerialize<28> for Waitcondition {
    #[inline]
    fn serialize_fixed(self) -> [u8; 28] {
        let trigger_bytes = self.trigger.serialize_fixed();
        let event_threshold_bytes = self.event_threshold.serialize_fixed();
        [
            trigger_bytes[0],
            trigger_bytes[1],
            trigger_bytes[2],
            trigger_bytes[3],
            trigger_bytes[4],
            trigger_bytes[5],
            trigger_bytes[6],
            trigger_bytes[7],
            trigger_bytes[8],
            trigger_bytes[9],
            trigger_bytes[10],
            trigger_bytes[11],
            trigger_bytes[12],
            trigger_bytes[13],
            trigger_bytes[14],
            trigger_bytes[15],
            trigger_bytes[16],
            trigger_bytes[17],
            trigger_bytes[18],
            trigger_bytes[19],
            event_threshold_bytes[0],
            event_threshold_bytes[1],
            event_threshold_bytes[2],
            event_threshold_bytes[3],
            event_threshold_bytes[4],
            event_threshold_bytes[5],
            event_threshold_bytes[6],
            event_threshold_bytes[7],
        ]
    }
}
impl FixedLengthFromBytes<28> for Waitcondition {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            trigger: Trigger::from_bytes(bytes.get(0..20).ok_or(crate::error::Error::FromBytes)?)?,
            event_threshold: Int64::from_bytes(
                bytes.get(20..28).ok_or(crate::error::Error::FromBytes)?,
            )?,
        })
    }
}
pub const COUNTER_ERROR: u8 = 0;
pub const ALARM_ERROR: u8 = 1;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct InitializeReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub major_version: u8,
    pub minor_version: u8,
}
impl FixedLengthFromBytes<32> for InitializeReply {
    #[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: u8::from_bytes(bytes.get(8..9).ok_or(crate::error::Error::FromBytes)?)?,
            minor_version: u8::from_bytes(bytes.get(9..10).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq)]
pub struct ListSystemCountersReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub counters: alloc::vec::Vec<Systemcounter>,
}
impl VariableLengthFromBytes for ListSystemCountersReply {
    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 counters_len = u32::from_bytes(ptr.get(8..12).ok_or(crate::error::Error::FromBytes)?)?;
        let counters_length = counters_len as usize;
        let mut offset = 32;
        let counters = crate::vec_from_bytes_var!(ptr, Systemcounter, offset, counters_length,);
        Ok((
            Self {
                response_type,
                sequence,
                length,
                counters,
            },
            offset,
        ))
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct QueryCounterReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub counter_value: Int64,
}
impl FixedLengthFromBytes<16> for QueryCounterReply {
    #[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)?)?,
            counter_value: Int64::from_bytes(
                bytes.get(8..16).ok_or(crate::error::Error::FromBytes)?,
            )?,
        })
    }
}
#[derive(Default, Debug, Clone, PartialEq, Copy)]
pub struct CreateAlarmValueList {
    pub counter: Option<Counter>,
    pub value_type: Option<ValuetypeEnum>,
    pub value: Option<Int64>,
    pub test_type: Option<TesttypeEnum>,
    pub delta: Option<Int64>,
    pub events: Option<u32>,
}
impl CreateAlarmValueList {
    #[inline]
    pub fn serialize_into(self, buf: &mut [u8]) -> crate::error::Result<usize> {
        let mut offset = 0;
        let buf_ptr = buf;
        if let Some(counter) = self.counter {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&counter.serialize_fixed());
            offset += 4;
        }
        if let Some(value_type) = self.value_type {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&value_type.serialize_fixed());
            offset += 4;
        }
        if let Some(value) = self.value {
            buf_ptr
                .get_mut(offset..offset + 8)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&value.serialize_fixed());
            offset += 8;
        }
        if let Some(test_type) = self.test_type {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&test_type.serialize_fixed());
            offset += 4;
        }
        if let Some(delta) = self.delta {
            buf_ptr
                .get_mut(offset..offset + 8)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&delta.serialize_fixed());
            offset += 8;
        }
        if let Some(events) = self.events {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&events.serialize_fixed());
            offset += 4;
        }
        Ok(offset)
    }

    #[inline]
    #[must_use]
    pub fn switch_expr(&self) -> Ca {
        let mut mask = Ca::default();
        if self.counter.is_some() {
            mask |= Ca::COUNTER;
        }
        if self.value_type.is_some() {
            mask |= Ca::VALUE_TYPE;
        }
        if self.value.is_some() {
            mask |= Ca::VALUE;
        }
        if self.test_type.is_some() {
            mask |= Ca::TEST_TYPE;
        }
        if self.delta.is_some() {
            mask |= Ca::DELTA;
        }
        if self.events.is_some() {
            mask |= Ca::EVENTS;
        }
        mask
    }

    #[inline]
    pub fn counter(mut self, counter: Counter) -> Self {
        self.counter = Some(counter);
        self
    }

    #[inline]
    pub fn value_type(mut self, value_type: ValuetypeEnum) -> Self {
        self.value_type = Some(value_type);
        self
    }

    #[inline]
    pub fn value(mut self, value: Int64) -> Self {
        self.value = Some(value);
        self
    }

    #[inline]
    pub fn test_type(mut self, test_type: TesttypeEnum) -> Self {
        self.test_type = Some(test_type);
        self
    }

    #[inline]
    pub fn delta(mut self, delta: Int64) -> Self {
        self.delta = Some(delta);
        self
    }

    #[inline]
    pub fn events(mut self, events: u32) -> Self {
        self.events = Some(events);
        self
    }
}
#[derive(Default, Debug, Clone, PartialEq, Copy)]
pub struct ChangeAlarmValueList {
    pub counter: Option<Counter>,
    pub value_type: Option<ValuetypeEnum>,
    pub value: Option<Int64>,
    pub test_type: Option<TesttypeEnum>,
    pub delta: Option<Int64>,
    pub events: Option<u32>,
}
impl ChangeAlarmValueList {
    #[inline]
    pub fn serialize_into(self, buf: &mut [u8]) -> crate::error::Result<usize> {
        let mut offset = 0;
        let buf_ptr = buf;
        if let Some(counter) = self.counter {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&counter.serialize_fixed());
            offset += 4;
        }
        if let Some(value_type) = self.value_type {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&value_type.serialize_fixed());
            offset += 4;
        }
        if let Some(value) = self.value {
            buf_ptr
                .get_mut(offset..offset + 8)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&value.serialize_fixed());
            offset += 8;
        }
        if let Some(test_type) = self.test_type {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&test_type.serialize_fixed());
            offset += 4;
        }
        if let Some(delta) = self.delta {
            buf_ptr
                .get_mut(offset..offset + 8)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&delta.serialize_fixed());
            offset += 8;
        }
        if let Some(events) = self.events {
            buf_ptr
                .get_mut(offset..offset + 4)
                .ok_or(crate::error::Error::Serialize)?
                .copy_from_slice(&events.serialize_fixed());
            offset += 4;
        }
        Ok(offset)
    }

    #[inline]
    #[must_use]
    pub fn switch_expr(&self) -> Ca {
        let mut mask = Ca::default();
        if self.counter.is_some() {
            mask |= Ca::COUNTER;
        }
        if self.value_type.is_some() {
            mask |= Ca::VALUE_TYPE;
        }
        if self.value.is_some() {
            mask |= Ca::VALUE;
        }
        if self.test_type.is_some() {
            mask |= Ca::TEST_TYPE;
        }
        if self.delta.is_some() {
            mask |= Ca::DELTA;
        }
        if self.events.is_some() {
            mask |= Ca::EVENTS;
        }
        mask
    }

    #[inline]
    pub fn counter(mut self, counter: Counter) -> Self {
        self.counter = Some(counter);
        self
    }

    #[inline]
    pub fn value_type(mut self, value_type: ValuetypeEnum) -> Self {
        self.value_type = Some(value_type);
        self
    }

    #[inline]
    pub fn value(mut self, value: Int64) -> Self {
        self.value = Some(value);
        self
    }

    #[inline]
    pub fn test_type(mut self, test_type: TesttypeEnum) -> Self {
        self.test_type = Some(test_type);
        self
    }

    #[inline]
    pub fn delta(mut self, delta: Int64) -> Self {
        self.delta = Some(delta);
        self
    }

    #[inline]
    pub fn events(mut self, events: u32) -> Self {
        self.events = Some(events);
        self
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct QueryAlarmReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub trigger: Trigger,
    pub delta: Int64,
    pub events: u8,
    pub state: AlarmstateEnum,
}
impl FixedLengthFromBytes<40> for QueryAlarmReply {
    #[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)?)?,
            trigger: Trigger::from_bytes(bytes.get(8..28).ok_or(crate::error::Error::FromBytes)?)?,
            delta: Int64::from_bytes(bytes.get(28..36).ok_or(crate::error::Error::FromBytes)?)?,
            events: u8::from_bytes(bytes.get(36..37).ok_or(crate::error::Error::FromBytes)?)?,
            state: u8::from_bytes(bytes.get(37..38).ok_or(crate::error::Error::FromBytes)?)?.into(),
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct GetPriorityReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub priority: i32,
}
impl FixedLengthFromBytes<12> for GetPriorityReply {
    #[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)?)?,
            priority: i32::from_bytes(bytes.get(8..12).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct QueryFenceReply {
    pub response_type: u8,
    pub sequence: u16,
    pub length: u32,
    pub triggered: u8,
}
impl FixedLengthFromBytes<32> for QueryFenceReply {
    #[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)?)?,
            triggered: u8::from_bytes(bytes.get(8..9).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
pub const COUNTER_NOTIFY_EVENT: u8 = 0;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct CounterNotifyEvent {
    pub opcode: u8,
    pub kind: u8,
    pub sequence: u16,
    pub counter: Counter,
    pub wait_value: Int64,
    pub counter_value: Int64,
    pub timestamp: crate::proto::xproto::Timestamp,
    pub count: u16,
    pub destroyed: u8,
}
impl FixedLengthFromBytes<32> for CounterNotifyEvent {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            opcode: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            kind: u8::from_bytes(bytes.get(1..2).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            counter: Counter::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            wait_value: Int64::from_bytes(bytes.get(8..16).ok_or(crate::error::Error::FromBytes)?)?,
            counter_value: Int64::from_bytes(
                bytes.get(16..24).ok_or(crate::error::Error::FromBytes)?,
            )?,
            timestamp: crate::proto::xproto::Timestamp::from_bytes(
                bytes.get(24..28).ok_or(crate::error::Error::FromBytes)?,
            )?,
            count: u16::from_bytes(bytes.get(28..30).ok_or(crate::error::Error::FromBytes)?)?,
            destroyed: u8::from_bytes(bytes.get(30..31).ok_or(crate::error::Error::FromBytes)?)?,
        })
    }
}
pub const ALARM_NOTIFY_EVENT: u8 = 1;
#[derive(Debug, Clone, PartialEq, Copy)]
pub struct AlarmNotifyEvent {
    pub opcode: u8,
    pub kind: u8,
    pub sequence: u16,
    pub alarm: Alarm,
    pub counter_value: Int64,
    pub alarm_value: Int64,
    pub timestamp: crate::proto::xproto::Timestamp,
    pub state: AlarmstateEnum,
}
impl FixedLengthFromBytes<32> for AlarmNotifyEvent {
    #[inline]
    fn from_bytes(bytes: &[u8]) -> crate::error::Result<Self> {
        Ok(Self {
            opcode: u8::from_bytes(bytes.get(0..1).ok_or(crate::error::Error::FromBytes)?)?,
            kind: u8::from_bytes(bytes.get(1..2).ok_or(crate::error::Error::FromBytes)?)?,
            sequence: u16::from_bytes(bytes.get(2..4).ok_or(crate::error::Error::FromBytes)?)?,
            alarm: Alarm::from_bytes(bytes.get(4..8).ok_or(crate::error::Error::FromBytes)?)?,
            counter_value: Int64::from_bytes(
                bytes.get(8..16).ok_or(crate::error::Error::FromBytes)?,
            )?,
            alarm_value: Int64::from_bytes(
                bytes.get(16..24).ok_or(crate::error::Error::FromBytes)?,
            )?,
            timestamp: crate::proto::xproto::Timestamp::from_bytes(
                bytes.get(24..28).ok_or(crate::error::Error::FromBytes)?,
            )?,
            state: u8::from_bytes(bytes.get(28..29).ok_or(crate::error::Error::FromBytes)?)?.into(),
        })
    }
}