#![allow(warnings)]
#![allow(clippy::all)]
use anyhow;
#[allow(unused_imports)]
use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
ObjectId, EncodeError, DecodeError, Interface};
pub mod test_interface {
use super::*;
#[derive(Debug)]
pub struct TestInterface;
impl Interface for TestInterface {
const NAME: &'static str = "test_interface";
const VERSION: u32 = 1;
const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
MessageSpec(&[
ArgKind::Uint,
]),
MessageSpec(&[
ArgKind::Int,
]),
MessageSpec(&[
ArgKind::Fixed,
]),
MessageSpec(&[
ArgKind::String,
]),
MessageSpec(&[
ArgKind::Object,
]),
MessageSpec(&[
ArgKind::NewId,
]),
MessageSpec(&[
ArgKind::Array,
]),
MessageSpec(&[
ArgKind::Handle,
]),
MessageSpec(&[
ArgKind::Uint,
ArgKind::Int,
ArgKind::Handle,
ArgKind::Object,
ArgKind::Handle,
ArgKind::String,
ArgKind::Array,
]),
MessageSpec(&[
ArgKind::String,
ArgKind::Uint,
ArgKind::NewId,
]),
MessageSpec(&[
ArgKind::Uint,
]),
MessageSpec(&[
ArgKind::Uint,
]),
MessageSpec(&[
ArgKind::Int,
ArgKind::Int,
]),
]);
const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
MessageSpec(&[
ArgKind::Uint,
]),
MessageSpec(&[
ArgKind::Int,
]),
MessageSpec(&[
ArgKind::Fixed,
]),
MessageSpec(&[
ArgKind::String,
]),
MessageSpec(&[
ArgKind::Object,
]),
MessageSpec(&[
ArgKind::NewId,
]),
MessageSpec(&[
ArgKind::Array,
]),
MessageSpec(&[
ArgKind::Handle,
]),
MessageSpec(&[
ArgKind::Uint,
ArgKind::Int,
ArgKind::Handle,
ArgKind::Object,
ArgKind::Handle,
ArgKind::String,
ArgKind::Array,
]),
MessageSpec(&[
ArgKind::String,
ArgKind::Uint,
ArgKind::NewId,
]),
MessageSpec(&[
ArgKind::Uint,
]),
MessageSpec(&[
ArgKind::Uint,
]),
]);
type Incoming = Request;
type Outgoing = Event;
}
#[derive(Debug)]
pub enum Request {
Uint {
arg: u32,
},
Int {
arg: i32,
},
Fixed {
arg: Fixed,
},
String {
arg: String,
},
Object {
arg: ObjectId,
},
NewId {
arg: NewObject<TestInterface>,
},
Array {
arg: Array,
},
Handle {
arg: zx::Handle,
},
Complex {
uint_arg: u32,
int_arg: i32,
handle_arg1: zx::Handle,
object_arg: ObjectId,
handle_arg2: zx::Handle,
string_arg: String,
array_arg: Array,
},
UntypedNewId {
arg_interface_name: String,
arg_interface_version: u32,
arg: ObjectId,
},
TestIntEnum {
arg: Enum<TestEnum>,
},
TestUintEnum {
arg: Enum<TestEnum>,
},
TestSummary {
arg1: i32,
arg2: i32,
},
}
impl MessageType for Request {
fn log(&self, this: ObjectId) -> String {
match *self {
Request::Uint {
ref arg,
} => {
format!("test_interface@{:?}::uint(arg: {:?})", this, arg)
}
Request::Int {
ref arg,
} => {
format!("test_interface@{:?}::int(arg: {:?})", this, arg)
}
Request::Fixed {
ref arg,
} => {
format!("test_interface@{:?}::fixed(arg: {:?})", this, arg)
}
Request::String {
ref arg,
} => {
format!("test_interface@{:?}::string(arg: {:?})", this, arg)
}
Request::Object {
ref arg,
} => {
format!("test_interface@{:?}::object(arg: {:?})", this, arg)
}
Request::NewId {
ref arg,
} => {
format!("test_interface@{:?}::new_id(arg: {:?})", this, arg)
}
Request::Array {
ref arg,
} => {
format!("test_interface@{:?}::array(arg: Array[{}])", this, arg.len())
}
Request::Handle {
ref arg,
} => {
format!("test_interface@{:?}::handle(arg: <handle>)", this)
}
Request::Complex {
ref uint_arg,
ref int_arg,
ref handle_arg1,
ref object_arg,
ref handle_arg2,
ref string_arg,
ref array_arg,
} => {
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())
}
Request::UntypedNewId {
ref arg_interface_name,
ref arg_interface_version,
ref arg,
} => {
format!("test_interface@{:?}::untyped_new_id(arg_interface_name: {:?}, arg_interface_version: {:?}, arg: {:?})", this, arg_interface_name, arg_interface_version, arg)
}
Request::TestIntEnum {
ref arg,
} => {
format!("test_interface@{:?}::test_int_enum(arg: {:?})", this, arg)
}
Request::TestUintEnum {
ref arg,
} => {
format!("test_interface@{:?}::test_uint_enum(arg: {:?})", this, arg)
}
Request::TestSummary {
ref arg1,
ref arg2,
} => {
format!("test_interface@{:?}::test_summary(arg1: {:?}, arg2: {:?})", this, arg1, arg2)
}
}
}
fn message_name(&self) -> &'static std::ffi::CStr{
match *self {
Request::Uint { .. } => c"test_interface::uint",
Request::Int { .. } => c"test_interface::int",
Request::Fixed { .. } => c"test_interface::fixed",
Request::String { .. } => c"test_interface::string",
Request::Object { .. } => c"test_interface::object",
Request::NewId { .. } => c"test_interface::new_id",
Request::Array { .. } => c"test_interface::array",
Request::Handle { .. } => c"test_interface::handle",
Request::Complex { .. } => c"test_interface::complex",
Request::UntypedNewId { .. } => c"test_interface::untyped_new_id",
Request::TestIntEnum { .. } => c"test_interface::test_int_enum",
Request::TestUintEnum { .. } => c"test_interface::test_uint_enum",
Request::TestSummary { .. } => c"test_interface::test_summary",
}
}
}
#[derive(Debug)]
pub enum Event {
Uint {
arg: u32,
},
Int {
arg: i32,
},
Fixed {
arg: Fixed,
},
String {
arg: String,
},
Object {
arg: ObjectId,
},
NewId {
arg: NewId,
},
Array {
arg: Array,
},
Handle {
arg: zx::Handle,
},
Complex {
uint_arg: u32,
int_arg: i32,
handle_arg1: zx::Handle,
object_arg: ObjectId,
handle_arg2: zx::Handle,
string_arg: String,
array_arg: Array,
},
UntypedNewId {
arg_interface_name: String,
arg_interface_version: u32,
arg: NewId,
},
TestIntEnum {
arg: TestEnum,
},
TestUintEnum {
arg: TestEnum,
},
}
impl MessageType for Event {
fn log(&self, this: ObjectId) -> String {
match *self {
Event::Uint {
ref arg,
} => {
format!("test_interface@{:?}::uint(arg: {:?})", this, arg)
}
Event::Int {
ref arg,
} => {
format!("test_interface@{:?}::int(arg: {:?})", this, arg)
}
Event::Fixed {
ref arg,
} => {
format!("test_interface@{:?}::fixed(arg: {:?})", this, arg)
}
Event::String {
ref arg,
} => {
format!("test_interface@{:?}::string(arg: {:?})", this, arg)
}
Event::Object {
ref arg,
} => {
format!("test_interface@{:?}::object(arg: {:?})", this, arg)
}
Event::NewId {
ref arg,
} => {
format!("test_interface@{:?}::new_id(arg: {:?})", this, arg)
}
Event::Array {
ref arg,
} => {
format!("test_interface@{:?}::array(arg: Array[{}])", this, arg.len())
}
Event::Handle {
ref arg,
} => {
format!("test_interface@{:?}::handle(arg: <handle>)", this)
}
Event::Complex {
ref uint_arg,
ref int_arg,
ref handle_arg1,
ref object_arg,
ref handle_arg2,
ref string_arg,
ref array_arg,
} => {
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())
}
Event::UntypedNewId {
ref arg_interface_name,
ref arg_interface_version,
ref arg,
} => {
format!("test_interface@{:?}::untyped_new_id(arg_interface_name: {:?}, arg_interface_version: {:?}, arg: {:?})", this, arg_interface_name, arg_interface_version, arg)
}
Event::TestIntEnum {
ref arg,
} => {
format!("test_interface@{:?}::test_int_enum(arg: {:?})", this, arg)
}
Event::TestUintEnum {
ref arg,
} => {
format!("test_interface@{:?}::test_uint_enum(arg: {:?})", this, arg)
}
}
}
fn message_name(&self) -> &'static std::ffi::CStr{
match *self {
Event::Uint { .. } => c"test_interface::uint",
Event::Int { .. } => c"test_interface::int",
Event::Fixed { .. } => c"test_interface::fixed",
Event::String { .. } => c"test_interface::string",
Event::Object { .. } => c"test_interface::object",
Event::NewId { .. } => c"test_interface::new_id",
Event::Array { .. } => c"test_interface::array",
Event::Handle { .. } => c"test_interface::handle",
Event::Complex { .. } => c"test_interface::complex",
Event::UntypedNewId { .. } => c"test_interface::untyped_new_id",
Event::TestIntEnum { .. } => c"test_interface::test_int_enum",
Event::TestUintEnum { .. } => c"test_interface::test_uint_enum",
}
}
}
impl IntoMessage for Event {
type Error = EncodeError;
fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
let mut header = MessageHeader {
sender: id,
opcode: 0,
length: 0,
};
let mut msg = Message::new();
msg.write_header(&header)?;
match self {
Event::Uint {
arg,
} => {
msg.write_arg(Arg::Uint(arg))?;
header.opcode = 0;
},
Event::Int {
arg,
} => {
msg.write_arg(Arg::Int(arg))?;
header.opcode = 1;
},
Event::Fixed {
arg,
} => {
msg.write_arg(Arg::Fixed(arg))?;
header.opcode = 2;
},
Event::String {
arg,
} => {
msg.write_arg(Arg::String(arg))?;
header.opcode = 3;
},
Event::Object {
arg,
} => {
msg.write_arg(Arg::Object(arg))?;
header.opcode = 4;
},
Event::NewId {
arg,
} => {
msg.write_arg(Arg::NewId(arg))?;
header.opcode = 5;
},
Event::Array {
arg,
} => {
msg.write_arg(Arg::Array(arg))?;
header.opcode = 6;
},
Event::Handle {
arg,
} => {
msg.write_arg(Arg::Handle(arg))?;
header.opcode = 7;
},
Event::Complex {
uint_arg,
int_arg,
handle_arg1,
object_arg,
handle_arg2,
string_arg,
array_arg,
} => {
msg.write_arg(Arg::Uint(uint_arg))?;
msg.write_arg(Arg::Int(int_arg))?;
msg.write_arg(Arg::Handle(handle_arg1))?;
msg.write_arg(Arg::Object(object_arg))?;
msg.write_arg(Arg::Handle(handle_arg2))?;
msg.write_arg(Arg::String(string_arg))?;
msg.write_arg(Arg::Array(array_arg))?;
header.opcode = 8;
},
Event::UntypedNewId {
arg_interface_name,
arg_interface_version,
arg,
} => {
msg.write_arg(Arg::String(arg_interface_name))?;
msg.write_arg(Arg::Uint(arg_interface_version))?;
msg.write_arg(Arg::NewId(arg))?;
header.opcode = 9;
},
Event::TestIntEnum {
arg,
} => {
msg.write_arg(Arg::Uint(arg.bits()))?;
header.opcode = 10;
},
Event::TestUintEnum {
arg,
} => {
msg.write_arg(Arg::Uint(arg.bits()))?;
header.opcode = 11;
},
}
header.length = msg.bytes().len() as u16;
msg.rewind();
msg.write_header(&header)?;
Ok(msg)
}
}
impl FromArgs for Request {
fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
match op {
0 => {
let mut iter = args.into_iter();
Ok(Request::Uint {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_uint()?,
})
},
1 => {
let mut iter = args.into_iter();
Ok(Request::Int {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_int()?,
})
},
2 => {
let mut iter = args.into_iter();
Ok(Request::Fixed {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_fixed()?.into(),
})
},
3 => {
let mut iter = args.into_iter();
Ok(Request::String {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_string()?,
})
},
4 => {
let mut iter = args.into_iter();
Ok(Request::Object {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_object()?,
})
},
5 => {
let mut iter = args.into_iter();
Ok(Request::NewId {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_new_id()?.into(),
})
},
6 => {
let mut iter = args.into_iter();
Ok(Request::Array {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_array()?,
})
},
7 => {
let mut iter = args.into_iter();
Ok(Request::Handle {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_handle()?,
})
},
8 => {
let mut iter = args.into_iter();
Ok(Request::Complex {
uint_arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_uint()?,
int_arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_int()?,
handle_arg1: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_handle()?,
object_arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_object()?,
handle_arg2: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_handle()?,
string_arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_string()?,
array_arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_array()?,
})
},
9 => {
let mut iter = args.into_iter();
Ok(Request::UntypedNewId {
arg_interface_name: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_string()?,
arg_interface_version: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_uint()?,
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_new_id()?.into(),
})
},
10 => {
let mut iter = args.into_iter();
Ok(Request::TestIntEnum {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_uint().map(|i| match TestEnum::from_bits(i) {
Some(e) => Enum::Recognized(e),
None => Enum::Unrecognized(i),
})?,
})
},
11 => {
let mut iter = args.into_iter();
Ok(Request::TestUintEnum {
arg: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_uint().map(|i| match TestEnum::from_bits(i) {
Some(e) => Enum::Recognized(e),
None => Enum::Unrecognized(i),
})?,
})
},
12 => {
let mut iter = args.into_iter();
Ok(Request::TestSummary {
arg1: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_int()?,
arg2: iter.next()
.ok_or(DecodeError::InsufficientArgs)?
.as_int()?,
})
},
_ => {
Err(DecodeError::InvalidOpcode(op).into())
},
}
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum TestEnum {
DoesntStartAt0 = 111,
Entry1 = 0,
Entry2 = 1,
_0StartsWithNumber = 2,
}
impl TestEnum {
pub fn from_bits(v: u32) -> Option<Self> {
match v {
111 => Some(TestEnum::DoesntStartAt0),
0 => Some(TestEnum::Entry1),
1 => Some(TestEnum::Entry2),
2 => Some(TestEnum::_0StartsWithNumber),
_ => None,
}
}
pub fn bits(&self) -> u32 {
*self as u32
}
}
impl Into<Arg> for TestEnum {
fn into(self) -> Arg {
Arg::Uint(self.bits())
}
}
::bitflags::bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TestBitfield: u32 {
const Entry1 = 1;
const Entry2 = 2;
const _0StartsWithNumber = 4;
}
}
impl Into<Arg> for TestBitfield {
fn into(self) -> Arg {
Arg::Uint(self.bits())
}
}
} pub use crate::test_interface::TestInterface;
pub use crate::test_interface::Request as TestInterfaceRequest;
pub use crate::test_interface::Event as TestInterfaceEvent;