1 // Written in the D programming language.
2 
3 /**
4 The module provides tools for convenient cast to some objects of 9P / Styx protocol.
5 
6 Copyright: LightHouse Software, 2021
7 License:   $(HTTP https://github.com/aquaratixc/ESL-License, Experimental Software License 1.0).
8 Authors:   Oleg Bakharev,
9 		   Ilya Pertsev
10 */
11 module styx2000.extrautil.casts;
12 
13 private {
14 	import styx2000.protoconst.messages;
15 	
16 	import styx2000.protomsg.typeconv;
17 	
18 	import styx2000.protobj;
19 }
20 
21 /// Transform to R-message type
22 /// Throws: Exception if passed type is not T-type or type is R-error
23 auto toRtype(Type type)
24 {		
25 	auto rtype = new Type;	
26 	
27 	with (STYX_MESSAGE_TYPE)
28 	{
29 		switch(type.getType) 
30 		{
31 			// version
32 			case T_VERSION:
33 				rtype.setType(R_VERSION);
34 				break;
35 			// auth
36 			case T_AUTH:
37 				rtype.setType(R_AUTH);
38 				break;
39 			// flush
40 			case T_FLUSH:
41 				rtype.setType(R_FLUSH);
42 				break;
43 			// attach
44 			case T_ATTACH:
45 				rtype.setType(R_ATTACH);
46 				break;
47 			// walk
48 			case T_WALK:
49 				rtype.setType(R_WALK);
50 				break;
51 			case T_OPEN:
52 				rtype.setType(R_OPEN);
53 				break;
54 			// create
55 			case T_CREATE:
56 				rtype.setType(R_CREATE);
57 				break;
58 			// read
59 			case T_READ:
60 				rtype.setType(R_READ);
61 				break;
62 			// write
63 			case T_WRITE:
64 				rtype.setType(R_WRITE);
65 				break;
66 			// clunk
67 			case T_CLUNK:
68 				rtype.setType(R_CLUNK);
69 				break;
70 			// remove
71 			case T_REMOVE:
72 				rtype.setType(R_REMOVE);
73 				break;
74 			// stat
75 			case T_STAT:
76 				rtype.setType(R_STAT);
77 				break;
78 			// wstat
79 			case T_WSTAT:
80 				rtype.setType(R_WSTAT);
81 				break;
82 			default:
83 				throw new Exception("Wrong message type used to get R-message type");
84 		}
85 	}
86 	
87 	return rtype;
88 }
89 
90 /// Transform to T-message type
91 /// Throws: Exception if passed type is not R-type or type is R-error
92 auto toTtype(Type type)
93 {		
94 	auto ttype = new Type;	
95 	
96 	with (STYX_MESSAGE_TYPE)
97 	{
98 		switch(type.getType) 
99 		{
100 			// version
101 			case R_VERSION:
102 				ttype.setType(T_VERSION);
103 				break;
104 			// auth
105 			case R_AUTH:
106 				ttype.setType(T_AUTH);
107 				break;
108 			// flush
109 			case R_FLUSH:
110 				ttype.setType(T_FLUSH);
111 				break;
112 			// attach
113 			case R_ATTACH:
114 				ttype.setType(T_ATTACH);
115 				break;
116 			// walk
117 			case R_WALK:
118 				ttype.setType(T_WALK);
119 				break;
120 			case R_OPEN:
121 				ttype.setType(T_OPEN);
122 				break;
123 			// create
124 			case R_CREATE:
125 				ttype.setType(T_CREATE);
126 				break;
127 			// read
128 			case R_READ:
129 				ttype.setType(T_READ);
130 				break;
131 			// write
132 			case R_WRITE:
133 				ttype.setType(T_WRITE);
134 				break;
135 			// clunk
136 			case R_CLUNK:
137 				ttype.setType(T_CLUNK);
138 				break;
139 			// remove
140 			case R_REMOVE:
141 				ttype.setType(T_REMOVE);
142 				break;
143 			// stat
144 			case R_STAT:
145 				ttype.setType(T_STAT);
146 				break;
147 			// wstat
148 			case R_WSTAT:
149 				ttype.setType(T_WSTAT);
150 				break;
151 			default:
152 				throw new Exception("Wrong message type used to get T-message type");
153 		}
154 	}
155 	
156 	return ttype;
157 }
158 
159 /// Conversion from StyxObject to Afid type
160 alias toAfid = fromStyxObject!Afid;
161 
162 /// Conversion from StyxObject to Aname type
163 alias toAname = fromStyxObject!Aname;
164 
165 /// Conversion from StyxObject to Aqid type
166 alias toAqid = fromStyxObject!Aqid;
167 
168 /// Conversion from StyxObject to Count type
169 alias toCount = fromStyxObject!Count;
170 
171 /// Conversion from StyxObject to Data type
172 alias toData = fromStyxObject!Data;
173 
174 /// Conversion from StyxObject to Ename type
175 alias toEname = fromStyxObject!Ename;
176 
177 /// Conversion from StyxObject to Fid type
178 alias toFid = fromStyxObject!Fid;
179 
180 /// Conversion from StyxObject to Iounit type
181 alias toIounit = fromStyxObject!Iounit;
182 
183 /// Conversion from StyxObject to Mode type
184 alias toMode = fromStyxObject!Mode;
185 
186 /// Conversion from StyxObject to Msize type
187 alias toMsize = fromStyxObject!Msize;
188 
189 /// Conversion from StyxObject to Name type
190 alias toName = fromStyxObject!Name;
191 
192 /// Conversion from StyxObject to NewFid type
193 alias toNewFid = fromStyxObject!NewFid;
194 
195 /// Conversion from StyxObject to Nwname type
196 alias toNwname = fromStyxObject!Nwname;
197 
198 /// Conversion from StyxObject to Nwqid type
199 alias toNwqid = fromStyxObject!Nwqid;
200 
201 /// Conversion from StyxObject to Offset type
202 alias toOffset = fromStyxObject!Offset;
203 
204 /// Conversion from StyxObject to OldTag type
205 alias toOldTag = fromStyxObject!OldTag;
206 
207 /// Conversion from StyxObject to Perm type
208 alias toPerm = fromStyxObject!Perm;
209 
210 /// Conversion from StyxObject to Qid type
211 alias toQid = fromStyxObject!Qid;
212 
213 /// Conversion from StyxObject to Size type
214 alias toSize = fromStyxObject!Size;
215 
216 /// Conversion from StyxObject to Stat type
217 alias toStat = fromStyxObject!Stat;
218 
219 /// Conversion from StyxObject to Version type
220 alias toVersion = fromStyxObject!Version;
221 
222 /// Conversion from StyxObject to Tag type
223 alias toTag = fromStyxObject!Tag;
224 
225 /// Conversion from StyxObject to Type type
226 alias toType = fromStyxObject!Type;
227 
228 /// Conversion from StyxObject to Uname type
229 alias toUname = fromStyxObject!Uname;