1#[macro_export]
2macro_rules! proto {
3 ($s : expr) => { ::std::borrow::Cow::Borrowed($s) }
4}
5
6#[macro_export]
7macro_rules! unwrap_ret {
8 ($res : expr, $err : expr) => {
9 match $res {
10 Ok(i) => i,
11 Err(e) => return Err($err(e))
12 }
13 }
14}
15
16#[macro_export]
17macro_rules! to_bytes {
18 ($e : expr, $v : expr) => { quick_protobuf::Writer::new($v).write_message($e) };
19 (varint, $e : expr, $v : expr) => { quick_protobuf::Writer::new($v).write_varint($e) }
20}
21
22#[macro_export]
23macro_rules! from_bytes {
24 (varint32, $v : expr) => { quick_protobuf::BytesReader::from_bytes($v).read_varint32($v) };
25 ($t : tt, $v : expr) => { $t::from_reader(&mut quick_protobuf::BytesReader::from_bytes($v), $v) }
26}
27
28#[macro_export]
29macro_rules! make_request {
30 ($service : expr, $procedure : expr, $args : expr) => {{
31 let mut request : Request = Request::new();
32 request.set_service($service);
33 request.set_procedure($procedure);
34 for i in 0 .. $args.len() {
35 let mut arg = Argument::new();
36 arg.set_position(i as u32);
37 arg.set_value($args[i].clone());
38 request.arguments.push(arg);
39 }
40 request
41 }}
42}
43
44#[macro_export]
45macro_rules! unwrap_response {
46 ($response : expr) => {{
47 if $response.has_error { Err(TransceiverError::ResponseHasError($response.error)) }
48 else if $response.has_return_value { Ok(Some($response.return_value)) }
49 else { Ok(None) }
50 }}
51}