1use std::collections::HashMap;
2use crate::encoding::*;
3
4#[derive(Debug)]
5pub enum MessageType {
6 Reply(Header, ReplyData),
9 ValidateConnection(Header),
10 }
12
13#[derive(Debug)]
14pub struct Header {
15 pub magic: String,
16 pub protocol_major: u8,
17 pub protocol_minor: u8,
18 pub encoding_major: u8,
19 pub encoding_minor: u8,
20 pub message_type: u8,
21 pub compression_status: u8,
22 pub message_size: i32
23}
24
25#[derive(Debug, IceDerive)]
26pub struct Identity {
27 pub name: String,
28 pub category: String
29}
30
31impl Identity {
32 pub fn new(ident: &str) -> Identity {
33 match ident.find("/") {
34 Some(_) => {
35 let split = ident.split("/").collect::<Vec<&str>>();
36 Identity {
37 name: String::from(split[1]),
38 category: String::from(split[0])
39 }
40 }
41 None => Identity {
42 name: String::from(ident),
43 category: String::new()
44 }
45 }
46 }
47}
48
49#[derive(Debug, Clone)]
50pub struct Encapsulation {
51 pub size: i32,
52 pub major: u8,
53 pub minor: u8,
54 pub data: Vec<u8>
55}
56
57#[derive(Debug, IceDerive)]
58pub struct RequestData {
59 pub request_id: i32,
60 pub id: Identity,
61 pub facet: Vec<String>,
62 pub operation: String,
63 pub mode: u8,
64 pub context: HashMap<String, String>,
65 pub params: Encapsulation
66}
67
68#[derive(Debug, IceEncode)]
69pub struct ReplyData {
70 pub request_id: i32,
71 pub status: u8,
72 pub body: Encapsulation
73}
74
75#[derive(Debug, IceDerive)]
76pub struct Version
77{
78 pub major: u8,
79 pub minor: u8
80}
81
82#[derive(Debug, IceDerive)]
83pub struct ProxyData {
84 pub id: String,
85 pub facet: Vec<String>,
86 pub mode: u8,
87 pub secure: bool,
88 pub protocol: Version,
89 pub encoding: Version
90}
91
92#[derive(Debug)]
93pub enum EndPointType {
94 WellKnownObject(String),
95 TCP(EndpointData),
96 SSL(EndpointData),
97}
98
99#[derive(Debug)]
100pub struct LocatorResult {
101 pub proxy_data: ProxyData,
102 pub size: IceSize,
103 pub endpoint: EndPointType
104}
105
106#[derive(Debug, IceDerive)]
107pub struct EndpointData
108{
109 pub host: String,
110 pub port: i32,
111 pub timeout: i32,
112 pub compress: bool
113}
114
115impl Header {
116 pub fn new(message_type: u8, message_size: i32) -> Header {
117 Header {
118 magic: String::from("IceP"),
119 protocol_major: 1,
120 protocol_minor: 0,
121 encoding_major: 1,
122 encoding_minor: 0,
123 message_type: message_type,
124 compression_status: 0,
125 message_size: message_size
126 }
127 }
128}
129
130impl Encapsulation {
131 pub fn empty() -> Encapsulation {
132 Encapsulation {
133 size: 6,
134 major: 1,
135 minor: 1,
136 data: vec![]
137 }
138 }
139
140 pub fn from(bytes: Vec<u8>) -> Encapsulation {
141 Encapsulation {
142 size: 6 + bytes.len() as i32,
143 major: 1,
144 minor: 1,
145 data: bytes
146 }
147 }
148}