test_protocol_server_protocol/
test_protocol_server_protocol.rs

1// GENERATED FILE -- DO NOT EDIT
2
3#![allow(warnings)]
4#![allow(clippy::all)]
5use anyhow;
6#[allow(unused_imports)]
7use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
8use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
9                            MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
10                            ObjectId, EncodeError, DecodeError, Interface};
11pub mod test_interface {
12use super::*;
13#[derive(Debug)]
14pub struct TestInterface;
15
16impl Interface for TestInterface {
17    const NAME: &'static str = "test_interface";
18    const VERSION: u32 = 1;
19    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
20        // uint
21        MessageSpec(&[
22            ArgKind::Uint,
23        ]),
24        // int
25        MessageSpec(&[
26            ArgKind::Int,
27        ]),
28        // fixed
29        MessageSpec(&[
30            ArgKind::Fixed,
31        ]),
32        // string
33        MessageSpec(&[
34            ArgKind::String,
35        ]),
36        // object
37        MessageSpec(&[
38            ArgKind::Object,
39        ]),
40        // new_id
41        MessageSpec(&[
42            ArgKind::NewId,
43        ]),
44        // array
45        MessageSpec(&[
46            ArgKind::Array,
47        ]),
48        // handle
49        MessageSpec(&[
50            ArgKind::Handle,
51        ]),
52        // complex
53        MessageSpec(&[
54            ArgKind::Uint,
55            ArgKind::Int,
56            ArgKind::Handle,
57            ArgKind::Object,
58            ArgKind::Handle,
59            ArgKind::String,
60            ArgKind::Array,
61        ]),
62        // untyped_new_id
63        MessageSpec(&[
64            ArgKind::String,
65            ArgKind::Uint,
66            ArgKind::NewId,
67        ]),
68        // test_int_enum
69        MessageSpec(&[
70            ArgKind::Uint,
71        ]),
72        // test_uint_enum
73        MessageSpec(&[
74            ArgKind::Uint,
75        ]),
76        // test_summary
77        MessageSpec(&[
78            ArgKind::Int,
79            ArgKind::Int,
80        ]),
81    ]);
82    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
83        // uint
84        MessageSpec(&[
85            ArgKind::Uint,
86        ]),
87        // int
88        MessageSpec(&[
89            ArgKind::Int,
90        ]),
91        // fixed
92        MessageSpec(&[
93            ArgKind::Fixed,
94        ]),
95        // string
96        MessageSpec(&[
97            ArgKind::String,
98        ]),
99        // object
100        MessageSpec(&[
101            ArgKind::Object,
102        ]),
103        // new_id
104        MessageSpec(&[
105            ArgKind::NewId,
106        ]),
107        // array
108        MessageSpec(&[
109            ArgKind::Array,
110        ]),
111        // handle
112        MessageSpec(&[
113            ArgKind::Handle,
114        ]),
115        // complex
116        MessageSpec(&[
117            ArgKind::Uint,
118            ArgKind::Int,
119            ArgKind::Handle,
120            ArgKind::Object,
121            ArgKind::Handle,
122            ArgKind::String,
123            ArgKind::Array,
124        ]),
125        // untyped_new_id
126        MessageSpec(&[
127            ArgKind::String,
128            ArgKind::Uint,
129            ArgKind::NewId,
130        ]),
131        // test_int_enum
132        MessageSpec(&[
133            ArgKind::Uint,
134        ]),
135        // test_uint_enum
136        MessageSpec(&[
137            ArgKind::Uint,
138        ]),
139    ]);
140    type Incoming = Request;
141    type Outgoing = Event;
142}
143
144#[derive(Debug)]
145pub enum Request {
146    Uint {
147        arg: u32,
148    },
149    Int {
150        arg: i32,
151    },
152    Fixed {
153        arg: Fixed,
154    },
155    String {
156        arg: String,
157    },
158    Object {
159        arg: ObjectId,
160    },
161    NewId {
162        arg: NewObject<TestInterface>,
163    },
164    Array {
165        arg: Array,
166    },
167    Handle {
168        arg: zx::Handle,
169    },
170    Complex {
171        uint_arg: u32,
172        int_arg: i32,
173        handle_arg1: zx::Handle,
174        object_arg: ObjectId,
175        handle_arg2: zx::Handle,
176        string_arg: String,
177        array_arg: Array,
178    },
179    UntypedNewId {
180        arg_interface_name: String,
181        arg_interface_version: u32,
182        arg: ObjectId,
183    },
184    TestIntEnum {
185        arg: Enum<TestEnum>,
186    },
187    TestUintEnum {
188        arg: Enum<TestEnum>,
189    },
190
191    /// multi-line
192    /// summary
193    ///
194    /// This request takes two arguments, one with a single-line summary, and
195    /// another with a multi-line summary.
196    TestSummary {
197        /// simple summary
198        arg1: i32,
199        /// complex summary that span
200        /// multiple lines
201        arg2: i32,
202    },
203}
204
205impl MessageType for Request {
206    fn log(&self, this: ObjectId) -> String {
207        match *self {
208            Request::Uint {
209                ref arg,
210            } => {
211                format!("test_interface@{:?}::uint(arg: {:?})", this, arg)
212            }
213            Request::Int {
214                ref arg,
215            } => {
216                format!("test_interface@{:?}::int(arg: {:?})", this, arg)
217            }
218            Request::Fixed {
219                ref arg,
220            } => {
221                format!("test_interface@{:?}::fixed(arg: {:?})", this, arg)
222            }
223            Request::String {
224                ref arg,
225            } => {
226                format!("test_interface@{:?}::string(arg: {:?})", this, arg)
227            }
228            Request::Object {
229                ref arg,
230            } => {
231                format!("test_interface@{:?}::object(arg: {:?})", this, arg)
232            }
233            Request::NewId {
234                ref arg,
235            } => {
236                format!("test_interface@{:?}::new_id(arg: {:?})", this, arg)
237            }
238            Request::Array {
239                ref arg,
240            } => {
241                format!("test_interface@{:?}::array(arg: Array[{}])", this, arg.len())
242            }
243            Request::Handle {
244                ref arg,
245            } => {
246                format!("test_interface@{:?}::handle(arg: <handle>)", this)
247            }
248            Request::Complex {
249                ref uint_arg,
250                ref int_arg,
251                ref handle_arg1,
252                ref object_arg,
253                ref handle_arg2,
254                ref string_arg,
255                ref array_arg,
256            } => {
257                format!("test_interface@{:?}::complex(uint_arg: {:?}, int_arg: {:?}, handle_arg1: <handle>, object_arg: {:?}, handle_arg2: <handle>, string_arg: {:?}, array_arg: Array[{}])", this, uint_arg, int_arg, object_arg, string_arg, array_arg.len())
258            }
259            Request::UntypedNewId {
260                ref arg_interface_name,
261                ref arg_interface_version,
262                ref arg,
263            } => {
264                format!("test_interface@{:?}::untyped_new_id(arg_interface_name: {:?}, arg_interface_version: {:?}, arg: {:?})", this, arg_interface_name, arg_interface_version, arg)
265            }
266            Request::TestIntEnum {
267                ref arg,
268            } => {
269                format!("test_interface@{:?}::test_int_enum(arg: {:?})", this, arg)
270            }
271            Request::TestUintEnum {
272                ref arg,
273            } => {
274                format!("test_interface@{:?}::test_uint_enum(arg: {:?})", this, arg)
275            }
276            Request::TestSummary {
277                ref arg1,
278                ref arg2,
279            } => {
280                format!("test_interface@{:?}::test_summary(arg1: {:?}, arg2: {:?})", this, arg1, arg2)
281            }
282        }
283    }
284    fn message_name(&self) -> &'static std::ffi::CStr{
285        match *self {
286            Request::Uint { .. } => c"test_interface::uint",
287            Request::Int { .. } => c"test_interface::int",
288            Request::Fixed { .. } => c"test_interface::fixed",
289            Request::String { .. } => c"test_interface::string",
290            Request::Object { .. } => c"test_interface::object",
291            Request::NewId { .. } => c"test_interface::new_id",
292            Request::Array { .. } => c"test_interface::array",
293            Request::Handle { .. } => c"test_interface::handle",
294            Request::Complex { .. } => c"test_interface::complex",
295            Request::UntypedNewId { .. } => c"test_interface::untyped_new_id",
296            Request::TestIntEnum { .. } => c"test_interface::test_int_enum",
297            Request::TestUintEnum { .. } => c"test_interface::test_uint_enum",
298            Request::TestSummary { .. } => c"test_interface::test_summary",
299        }
300    }
301}
302#[derive(Debug)]
303pub enum Event {
304    Uint {
305        arg: u32,
306    },
307    Int {
308        arg: i32,
309    },
310    Fixed {
311        arg: Fixed,
312    },
313    String {
314        arg: String,
315    },
316    Object {
317        arg: ObjectId,
318    },
319    NewId {
320        arg: NewId,
321    },
322    Array {
323        arg: Array,
324    },
325    Handle {
326        arg: zx::Handle,
327    },
328    Complex {
329        uint_arg: u32,
330        int_arg: i32,
331        handle_arg1: zx::Handle,
332        object_arg: ObjectId,
333        handle_arg2: zx::Handle,
334        string_arg: String,
335        array_arg: Array,
336    },
337    UntypedNewId {
338        arg_interface_name: String,
339        arg_interface_version: u32,
340        arg: NewId,
341    },
342    TestIntEnum {
343        arg: TestEnum,
344    },
345    TestUintEnum {
346        arg: TestEnum,
347    },
348}
349
350impl MessageType for Event {
351    fn log(&self, this: ObjectId) -> String {
352        match *self {
353            Event::Uint {
354                ref arg,
355            } => {
356                format!("test_interface@{:?}::uint(arg: {:?})", this, arg)
357            }
358            Event::Int {
359                ref arg,
360            } => {
361                format!("test_interface@{:?}::int(arg: {:?})", this, arg)
362            }
363            Event::Fixed {
364                ref arg,
365            } => {
366                format!("test_interface@{:?}::fixed(arg: {:?})", this, arg)
367            }
368            Event::String {
369                ref arg,
370            } => {
371                format!("test_interface@{:?}::string(arg: {:?})", this, arg)
372            }
373            Event::Object {
374                ref arg,
375            } => {
376                format!("test_interface@{:?}::object(arg: {:?})", this, arg)
377            }
378            Event::NewId {
379                ref arg,
380            } => {
381                format!("test_interface@{:?}::new_id(arg: {:?})", this, arg)
382            }
383            Event::Array {
384                ref arg,
385            } => {
386                format!("test_interface@{:?}::array(arg: Array[{}])", this, arg.len())
387            }
388            Event::Handle {
389                ref arg,
390            } => {
391                format!("test_interface@{:?}::handle(arg: <handle>)", this)
392            }
393            Event::Complex {
394                ref uint_arg,
395                ref int_arg,
396                ref handle_arg1,
397                ref object_arg,
398                ref handle_arg2,
399                ref string_arg,
400                ref array_arg,
401            } => {
402                format!("test_interface@{:?}::complex(uint_arg: {:?}, int_arg: {:?}, handle_arg1: <handle>, object_arg: {:?}, handle_arg2: <handle>, string_arg: {:?}, array_arg: Array[{}])", this, uint_arg, int_arg, object_arg, string_arg, array_arg.len())
403            }
404            Event::UntypedNewId {
405                ref arg_interface_name,
406                ref arg_interface_version,
407                ref arg,
408            } => {
409                format!("test_interface@{:?}::untyped_new_id(arg_interface_name: {:?}, arg_interface_version: {:?}, arg: {:?})", this, arg_interface_name, arg_interface_version, arg)
410            }
411            Event::TestIntEnum {
412                ref arg,
413            } => {
414                format!("test_interface@{:?}::test_int_enum(arg: {:?})", this, arg)
415            }
416            Event::TestUintEnum {
417                ref arg,
418            } => {
419                format!("test_interface@{:?}::test_uint_enum(arg: {:?})", this, arg)
420            }
421        }
422    }
423    fn message_name(&self) -> &'static std::ffi::CStr{
424        match *self {
425            Event::Uint { .. } => c"test_interface::uint",
426            Event::Int { .. } => c"test_interface::int",
427            Event::Fixed { .. } => c"test_interface::fixed",
428            Event::String { .. } => c"test_interface::string",
429            Event::Object { .. } => c"test_interface::object",
430            Event::NewId { .. } => c"test_interface::new_id",
431            Event::Array { .. } => c"test_interface::array",
432            Event::Handle { .. } => c"test_interface::handle",
433            Event::Complex { .. } => c"test_interface::complex",
434            Event::UntypedNewId { .. } => c"test_interface::untyped_new_id",
435            Event::TestIntEnum { .. } => c"test_interface::test_int_enum",
436            Event::TestUintEnum { .. } => c"test_interface::test_uint_enum",
437        }
438    }
439}
440impl IntoMessage for Event {
441    type Error = EncodeError;
442    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
443        let mut header = MessageHeader {
444            sender: id,
445            opcode: 0,
446            length: 0,
447        };
448        let mut msg = Message::new();
449        msg.write_header(&header)?;
450        match self {
451        Event::Uint {
452            arg,
453        } => {
454            msg.write_arg(Arg::Uint(arg))?;
455            header.opcode = 0;
456        },
457        Event::Int {
458            arg,
459        } => {
460            msg.write_arg(Arg::Int(arg))?;
461            header.opcode = 1;
462        },
463        Event::Fixed {
464            arg,
465        } => {
466            msg.write_arg(Arg::Fixed(arg))?;
467            header.opcode = 2;
468        },
469        Event::String {
470            arg,
471        } => {
472            msg.write_arg(Arg::String(arg))?;
473            header.opcode = 3;
474        },
475        Event::Object {
476            arg,
477        } => {
478            msg.write_arg(Arg::Object(arg))?;
479            header.opcode = 4;
480        },
481        Event::NewId {
482            arg,
483        } => {
484            msg.write_arg(Arg::NewId(arg))?;
485            header.opcode = 5;
486        },
487        Event::Array {
488            arg,
489        } => {
490            msg.write_arg(Arg::Array(arg))?;
491            header.opcode = 6;
492        },
493        Event::Handle {
494            arg,
495        } => {
496            msg.write_arg(Arg::Handle(arg))?;
497            header.opcode = 7;
498        },
499        Event::Complex {
500            uint_arg,
501            int_arg,
502            handle_arg1,
503            object_arg,
504            handle_arg2,
505            string_arg,
506            array_arg,
507        } => {
508            msg.write_arg(Arg::Uint(uint_arg))?;
509            msg.write_arg(Arg::Int(int_arg))?;
510            msg.write_arg(Arg::Handle(handle_arg1))?;
511            msg.write_arg(Arg::Object(object_arg))?;
512            msg.write_arg(Arg::Handle(handle_arg2))?;
513            msg.write_arg(Arg::String(string_arg))?;
514            msg.write_arg(Arg::Array(array_arg))?;
515            header.opcode = 8;
516        },
517        Event::UntypedNewId {
518            arg_interface_name,
519            arg_interface_version,
520            arg,
521        } => {
522            msg.write_arg(Arg::String(arg_interface_name))?;
523            msg.write_arg(Arg::Uint(arg_interface_version))?;
524            msg.write_arg(Arg::NewId(arg))?;
525            header.opcode = 9;
526        },
527        Event::TestIntEnum {
528            arg,
529        } => {
530            msg.write_arg(Arg::Uint(arg.bits()))?;
531            header.opcode = 10;
532        },
533        Event::TestUintEnum {
534            arg,
535        } => {
536            msg.write_arg(Arg::Uint(arg.bits()))?;
537            header.opcode = 11;
538        },
539        }
540        header.length = msg.bytes().len() as u16;
541        msg.rewind();
542        msg.write_header(&header)?;
543        Ok(msg)
544    }
545}
546impl FromArgs for Request {
547    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
548        match op {
549        0 /* uint */ => {
550            let mut iter = args.into_iter();
551            Ok(Request::Uint {
552                arg: iter.next()
553                                             .ok_or(DecodeError::InsufficientArgs)?
554                                             .as_uint()?,
555
556            })
557        },
558        1 /* int */ => {
559            let mut iter = args.into_iter();
560            Ok(Request::Int {
561                arg: iter.next()
562                                             .ok_or(DecodeError::InsufficientArgs)?
563                                             .as_int()?,
564
565            })
566        },
567        2 /* fixed */ => {
568            let mut iter = args.into_iter();
569            Ok(Request::Fixed {
570                arg: iter.next()
571                                             .ok_or(DecodeError::InsufficientArgs)?
572                                             .as_fixed()?.into(),
573
574            })
575        },
576        3 /* string */ => {
577            let mut iter = args.into_iter();
578            Ok(Request::String {
579                arg: iter.next()
580                                             .ok_or(DecodeError::InsufficientArgs)?
581                                             .as_string()?,
582
583            })
584        },
585        4 /* object */ => {
586            let mut iter = args.into_iter();
587            Ok(Request::Object {
588                arg: iter.next()
589                                             .ok_or(DecodeError::InsufficientArgs)?
590                                             .as_object()?,
591
592            })
593        },
594        5 /* new_id */ => {
595            let mut iter = args.into_iter();
596            Ok(Request::NewId {
597                arg: iter.next()
598                                             .ok_or(DecodeError::InsufficientArgs)?
599                                             .as_new_id()?.into(),
600
601            })
602        },
603        6 /* array */ => {
604            let mut iter = args.into_iter();
605            Ok(Request::Array {
606                arg: iter.next()
607                                             .ok_or(DecodeError::InsufficientArgs)?
608                                             .as_array()?,
609
610            })
611        },
612        7 /* handle */ => {
613            let mut iter = args.into_iter();
614            Ok(Request::Handle {
615                arg: iter.next()
616                                             .ok_or(DecodeError::InsufficientArgs)?
617                                             .as_handle()?,
618
619            })
620        },
621        8 /* complex */ => {
622            let mut iter = args.into_iter();
623            Ok(Request::Complex {
624                uint_arg: iter.next()
625                                             .ok_or(DecodeError::InsufficientArgs)?
626                                             .as_uint()?,
627                int_arg: iter.next()
628                                             .ok_or(DecodeError::InsufficientArgs)?
629                                             .as_int()?,
630                handle_arg1: iter.next()
631                                             .ok_or(DecodeError::InsufficientArgs)?
632                                             .as_handle()?,
633                object_arg: iter.next()
634                                             .ok_or(DecodeError::InsufficientArgs)?
635                                             .as_object()?,
636                handle_arg2: iter.next()
637                                             .ok_or(DecodeError::InsufficientArgs)?
638                                             .as_handle()?,
639                string_arg: iter.next()
640                                             .ok_or(DecodeError::InsufficientArgs)?
641                                             .as_string()?,
642                array_arg: iter.next()
643                                             .ok_or(DecodeError::InsufficientArgs)?
644                                             .as_array()?,
645
646            })
647        },
648        9 /* untyped_new_id */ => {
649            let mut iter = args.into_iter();
650            Ok(Request::UntypedNewId {
651                arg_interface_name: iter.next()
652                                             .ok_or(DecodeError::InsufficientArgs)?
653                                             .as_string()?,
654                arg_interface_version: iter.next()
655                                             .ok_or(DecodeError::InsufficientArgs)?
656                                             .as_uint()?,
657                arg: iter.next()
658                                             .ok_or(DecodeError::InsufficientArgs)?
659                                             .as_new_id()?.into(),
660
661            })
662        },
663        10 /* test_int_enum */ => {
664            let mut iter = args.into_iter();
665            Ok(Request::TestIntEnum {
666                arg: iter.next()
667                                             .ok_or(DecodeError::InsufficientArgs)?
668                                             .as_uint().map(|i| match TestEnum::from_bits(i) {
669                                      Some(e) => Enum::Recognized(e),
670                                      None => Enum::Unrecognized(i),
671                                 })?,
672
673            })
674        },
675        11 /* test_uint_enum */ => {
676            let mut iter = args.into_iter();
677            Ok(Request::TestUintEnum {
678                arg: iter.next()
679                                             .ok_or(DecodeError::InsufficientArgs)?
680                                             .as_uint().map(|i| match TestEnum::from_bits(i) {
681                                      Some(e) => Enum::Recognized(e),
682                                      None => Enum::Unrecognized(i),
683                                 })?,
684
685            })
686        },
687        12 /* test_summary */ => {
688            let mut iter = args.into_iter();
689            Ok(Request::TestSummary {
690                arg1: iter.next()
691                                             .ok_or(DecodeError::InsufficientArgs)?
692                                             .as_int()?,
693                arg2: iter.next()
694                                             .ok_or(DecodeError::InsufficientArgs)?
695                                             .as_int()?,
696
697            })
698        },
699        _ => {
700            Err(DecodeError::InvalidOpcode(op).into())
701        },
702        }
703    }
704}
705#[derive(Copy, Clone, Debug, Eq, PartialEq)]
706#[repr(u32)]
707pub enum TestEnum {
708    DoesntStartAt0 = 111,
709    Entry1 = 0,
710    Entry2 = 1,
711    _0StartsWithNumber = 2,
712}
713
714impl TestEnum {
715    pub fn from_bits(v: u32) -> Option<Self> {
716        match v {
717        111 => Some(TestEnum::DoesntStartAt0),
718        0 => Some(TestEnum::Entry1),
719        1 => Some(TestEnum::Entry2),
720        2 => Some(TestEnum::_0StartsWithNumber),
721        _ => None,
722        }
723    }
724
725    pub fn bits(&self) -> u32 {
726        *self as u32
727    }
728}
729impl Into<Arg> for TestEnum {
730    fn into(self) -> Arg {
731        Arg::Uint(self.bits())
732    }
733}
734::bitflags::bitflags! {
735    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
736    pub struct TestBitfield: u32 {
737        const Entry1 = 1;
738        const Entry2 = 2;
739        const _0StartsWithNumber = 4;
740    }
741}
742impl Into<Arg> for TestBitfield {
743    fn into(self) -> Arg {
744        Arg::Uint(self.bits())
745    }
746}
747} // mod test_interface
748
749pub use crate::test_interface::TestInterface;
750pub use crate::test_interface::Request as TestInterfaceRequest;
751pub use crate::test_interface::Event as TestInterfaceEvent;