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
extern crate byteorder;
extern crate hyper;
#[macro_use]
extern crate log;
use std::result;
use std::convert::From;
use std::io::{self, Read};
const IPP_VERSION: u16 = 0x0101;
#[derive(Debug)]
pub enum IppError {
HttpError(hyper::Error),
IOError(::std::io::Error),
RequestError(String),
AttributeError(String),
StatusError(u16),
TagError(u8)
}
impl From<io::Error> for IppError {
fn from(error: io::Error) -> IppError {
IppError::IOError(error)
}
}
impl From<hyper::Error> for IppError {
fn from(error: hyper::Error) -> IppError {
IppError::HttpError(error)
}
}
pub type Result<T> = result::Result<T, IppError>;
pub trait ReadIppExt: Read {
fn read_string(&mut self, len: usize) -> std::io::Result<String> {
Ok(String::from_utf8_lossy(&try!(self.read_vec(len))).to_string())
}
fn read_vec(&mut self, len: usize) -> std::io::Result<Vec<u8>> {
let mut namebuf: Vec<u8> = Vec::with_capacity(len);
unsafe { namebuf.set_len(len) };
try!(self.read_exact(&mut namebuf[..]));
Ok(namebuf)
}
}
impl<R: io::Read + ?Sized> ReadIppExt for R {}
pub mod consts {
pub mod tag;
pub mod statuscode;
pub mod operation;
pub mod attribute;
}
pub mod value;
pub mod parser;
pub mod request;
pub mod response;
pub mod attribute;
pub mod client;
pub mod server;
pub mod operation;