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
pub mod data_kind {
use crate::core::ZInt;
pub const PUT: ZInt = 0;
pub const PATCH: ZInt = 1;
pub const DELETE: ZInt = 2;
pub const DEFAULT: ZInt = PUT;
pub fn to_string(i: ZInt) -> String {
match i {
0 => "PUT".to_string(),
1 => "PATCH".to_string(),
2 => "DELETE".to_string(),
i => i.to_string(),
}
}
}
pub mod encoding {
use crate::core::ZInt;
use http_types::Mime;
use std::str::FromStr;
use zenoh_util::core::{ZError, ZErrorKind, ZResult};
use zenoh_util::zerror;
lazy_static! {
static ref MIMES: [Mime; 20] = [
Mime::from_str("application/octet-stream").unwrap(),
Mime::from_str("application/custom").unwrap(),
Mime::from_str("text/plain").unwrap(),
Mime::from_str("application/properties").unwrap(),
Mime::from_str("application/json").unwrap(),
Mime::from_str("application/sql").unwrap(),
Mime::from_str("application/integer").unwrap(),
Mime::from_str("application/float").unwrap(),
Mime::from_str("application/xml").unwrap(),
Mime::from_str("application/xhtml+xml").unwrap(),
Mime::from_str("application/x-www-form-urlencoded").unwrap(),
Mime::from_str("text/json").unwrap(),
Mime::from_str("text/htlm").unwrap(),
Mime::from_str("text/xml").unwrap(),
Mime::from_str("text/css").unwrap(),
Mime::from_str("text/csv").unwrap(),
Mime::from_str("text/javascript").unwrap(),
Mime::from_str("image/jpeg").unwrap(),
Mime::from_str("image/png").unwrap(),
Mime::from_str("image/gif").unwrap(),
];
}
pub fn to_mime(i: ZInt) -> ZResult<Mime> {
if i < MIMES.len() as ZInt {
Ok(MIMES[i as usize].clone())
} else {
zerror!(ZErrorKind::Other {
descr: format!("Unknown encoding id {}", i)
})
}
}
pub fn to_string(i: ZInt) -> String {
match to_mime(i) {
Ok(mime) => mime.essence().to_string(),
_ => i.to_string(),
}
}
pub fn from_str(string: &str) -> ZResult<ZInt> {
let string = string.split(';').next().unwrap();
match string {
"application/octet-stream" => Ok(0),
"application/custom" => Ok(1),
"text/plain" => Ok(2),
"application/properties" => Ok(3),
"application/json" => Ok(4),
"application/sql" => Ok(5),
"application/integer" => Ok(6),
"application/float" => Ok(7),
"application/xml" => Ok(8),
"application/xhtml+xml" => Ok(9),
"application/x-www-form-urlencoded" => Ok(10),
"text/json" => Ok(11),
"text/htlm" => Ok(12),
"text/xml" => Ok(13),
"text/css" => Ok(14),
"text/csv" => Ok(15),
"text/javascript" => Ok(16),
"image/jpeg" => Ok(17),
"image/png" => Ok(18),
"image/gif" => Ok(19),
s => zerror!(ZErrorKind::Other {
descr: format!("Unknown encoding '{}'", s)
}),
}
}
pub const APP_OCTET_STREAM: ZInt = 0;
pub const NONE: ZInt = APP_OCTET_STREAM;
pub const APP_CUSTOM: ZInt = 1;
pub const TEXT_PLAIN: ZInt = 2;
pub const STRING: ZInt = TEXT_PLAIN;
pub const APP_PROPERTIES: ZInt = 3;
pub const APP_JSON: ZInt = 4;
pub const APP_SQL: ZInt = 5;
pub const APP_INTEGER: ZInt = 6;
pub const APP_FLOAT: ZInt = 7;
pub const APP_XML: ZInt = 8;
pub const APP_XHTML_XML: ZInt = 9;
pub const APP_X_WWW_FORM_URLENCODED: ZInt = 10;
pub const TEXT_JSON: ZInt = 11;
pub const TEXT_HTML: ZInt = 12;
pub const TEXT_XML: ZInt = 13;
pub const TEXT_CSS: ZInt = 14;
pub const TEXT_CSV: ZInt = 15;
pub const TEXT_JAVASCRIPT: ZInt = 16;
pub const IMG_JPG: ZInt = 17;
pub const IMG_PNG: ZInt = 18;
pub const IMG_GIF: ZInt = 19;
pub const DEFAULT: ZInt = APP_OCTET_STREAM;
}