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
#[derive(Debug)] pub struct Protocol { pub name: String, pub copyright: Option<String>, pub description: Option<(String, String)>, pub interfaces: Vec<Interface>, } impl Protocol { pub fn new(name: String) -> Protocol { Protocol { name: name, copyright: None, description: None, interfaces: Vec::new(), } } } #[derive(Debug)] pub struct Interface { pub name: String, pub version: u32, pub description: Option<(String, String)>, pub requests: Vec<Message>, pub events: Vec<Message>, pub enums: Vec<Enum>, } impl Interface { pub fn new() -> Interface { Interface { name: String::new(), version: 1, description: None, requests: Vec::new(), events: Vec::new(), enums: Vec::new(), } } } #[derive(Debug)] pub struct Message { pub name: String, pub typ: Option<Type>, pub since: u16, pub description: Option<(String, String)>, pub args: Vec<Arg>, pub type_index: usize, } impl Message { pub fn new() -> Message { Message { name: String::new(), typ: None, since: 1, description: None, args: Vec::new(), type_index: 0, } } pub fn all_null(&self) -> bool { self.args .iter() .all(|a| !((a.typ == Type::Object || a.typ == Type::NewId) && a.interface.is_some())) } } #[derive(Debug)] pub struct Arg { pub name: String, pub typ: Type, pub interface: Option<String>, pub summary: Option<String>, pub description: Option<(String, String)>, pub allow_null: bool, pub enum_: Option<String>, } impl Arg { pub fn new() -> Arg { Arg { name: String::new(), typ: Type::Object, interface: None, summary: None, description: None, allow_null: false, enum_: None, } } } #[derive(Debug)] pub struct Enum { pub name: String, pub since: u16, pub description: Option<(String, String)>, pub entries: Vec<Entry>, pub bitfield: bool, } impl Enum { pub fn new() -> Enum { Enum { name: String::new(), since: 1, description: None, entries: Vec::new(), bitfield: false, } } } #[derive(Debug)] pub struct Entry { pub name: String, pub value: String, pub since: u16, pub description: Option<(String, String)>, pub summary: Option<String>, } impl Entry { pub fn new() -> Entry { Entry { name: String::new(), value: "0".to_owned(), since: 1, description: None, summary: None, } } } #[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum Type { Int, Uint, Fixed, String, Object, NewId, Array, Fd, Destructor, } impl Type { pub fn nullable(&self) -> bool { match *self { Type::String | Type::Object | Type::NewId | Type::Array => true, _ => false, } } pub fn rust_type(&self) -> &'static str { match *self { Type::Int => "i32", Type::Uint => "u32", Type::Fixed => "f64", Type::Array => "Vec<u8>", Type::Fd => "::std::os::unix::io::RawFd", Type::String => "String", Type::Object => "ProxyId", _ => "()", } } }