1 // Written in the D programming language.
2 
3 /**
4 Module for various type representation and conversions between types.
5 Mainly for service use, however, the module contains two useful helpers for working with messages and their objects: fromStyxObject and toStyxObject. 
6 The module is not automatically connected with the import of the protoconst package, so manual connection is required to use it. 
7 
8 Copyright: LightHouse Software, 2021
9 License:   $(HTTP https://github.com/aquaratixc/ESL-License, Experimental Software License 1.0).
10 Authors:   Oleg Bakharev,
11 		   Ilya Pertsev
12 */
13 module styx2000.protomsg.typeconv;
14 
15 private {
16 	import styx2000.protobj;
17 }
18 
19 /// Alias for type tuple
20 template Tuple(E...)
21 {
22 	alias E Tuple;
23 }
24 
25 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
26 /// `size[4] Tversion tag[2] msize[4] version[s]`
27 alias Tversion = Tuple!(Size, Type, Tag, Msize, Version);
28 
29 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
30 /// `size[4] Rversion tag[2] msize[4] version[s]`
31 alias Rversion = Tuple!(Size, Type, Tag, Msize, Version);
32 
33 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
34 /// `size[4] Tauth tag[2] afid[4] uname[s] aname[s]`
35 alias Tauth = Tuple!(Size, Type, Tag, Afid, Uname, Aname);
36 
37 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
38 /// `size[4] Rauth tag[2] aqid[13]`
39 alias Rauth = Tuple!(Size, Type, Tag, Aqid);
40 
41 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
42 /// `size[4] Rerror tag[2] ename[s]`
43 alias Rerror = Tuple!(Size, Type, Tag, Ename);
44 
45 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
46 /// `size[4] Tflush tag[2] oldtag[2]`
47 alias Tflush = Tuple!(Size, Type, Tag, Tag);
48 
49 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
50 /// `size[4] Rflush tag[2]`
51 alias Rflush = Tuple!(Size, Type, Tag);
52 
53 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
54 /// `size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s]`
55 alias Tattach = Tuple!(Size, Type, Tag, Fid, Afid, Uname, Aname);
56 
57 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
58 /// `size[4] Rattach tag[2] qid[13]`
59 alias Rattach = Tuple!(Size, Type, Tag, Qid);
60 
61 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
62 /// `size[4] Twalk tag[2] fid[4] newfid[4] nwname[2] nwname*(wname[s])`
63 alias Twalk = Tuple!(Size, Type, Tag, Fid, Fid, Nwname);
64 
65 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
66 /// `size[4] Rwalk tag[2] nwqid[2] nwqid*(wqid[13])`
67 alias Rwalk = Tuple!(Size, Type, Tag, Nwqid);
68 
69 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
70 /// `size[4] Topen tag[2] fid[4] mode[1]`
71 alias Topen = Tuple!(Size, Type, Tag, Fid, Mode);
72 
73 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
74 /// `size[4] Ropen tag[2] qid[13] iounit[4]`
75 alias Ropen = Tuple!(Size, Type, Tag, Qid, Iounit);
76 
77 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
78 /// `size[4] Tcreate tag[2] fid[4] name[s] perm[4] mode[1]`
79 alias Tcreate = Tuple!(Size, Type, Tag, Fid, Name, Perm, Mode);
80 
81 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
82 /// `size[4] Rcreate tag[2] qid[13] iounit[4]`
83 alias Rcreate = Tuple!(Size, Type, Tag, Qid, Iounit);
84 
85 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
86 /// `size[4] Tread tag[2] fid[4] offset[8] count[4]`
87 alias Tread = Tuple!(Size, Type, Tag, Fid, Offset, Count);
88 
89 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
90 /// `size[4] Rread tag[2] count[4] data[count]`
91 alias Rread = Tuple!(Size, Type, Tag, Count, Data);
92 
93 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
94 /// `size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count]`
95 alias Twrite = Tuple!(Size, Type, Tag, Fid, Offset, Count, Data);
96 
97 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
98 /// `size[4] Rwrite tag[2] count[4]`
99 alias Rwrite = Tuple!(Size, Type, Tag, Count);
100 
101 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
102 /// `size[4] Tclunk tag[2] fid[4]`
103 alias Tclunk = Tuple!(Size, Type, Tag, Fid);
104 
105 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
106 /// `size[4] Rclunk tag[2]`
107 alias Rclunk = Tuple!(Size, Type, Tag);
108 
109 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
110 /// `size[4] Tremove tag[2] fid[4]`
111 alias Tremove = Tuple!(Size, Type, Tag, Fid);
112 
113 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
114 /// `size[4] Rremove tag[2]`
115 alias Rremove = Tuple!(Size, Type, Tag);
116 
117 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
118 /// `size[4] Tstat tag[2] fid[4]`
119 alias Tstat = Tuple!(Size, Type, Tag, Fid);
120 
121 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
122 /// `size[4] Rstat tag[2] stat[n]`
123 alias Rstat = Tuple!(Size, Type, Tag, Stat);
124 
125 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
126 /// `size[4] Twstat tag[2] fid[4] stat[n]`
127 alias Twstat = Tuple!(Size, Type, Tag, Fid, Stat);
128 
129 /// This tuple of types mimics the structure of the corresponding message, which looks like this:
130 /// `size[4] Rwstat tag[2]`
131 alias Rwstat = Tuple!(Size, Type, Tag);
132 
133 /// Is one of StyxObject class ?
134 template isStyxObject(T)
135 {
136 	enum bool isStyxObject = is(T == Afid) || is(T : Qid) || is(T == Count)|| is(T == Data) || is(T : Name) || is(T : Fid) || is(T == Iounit) || 
137 							 is(T == Mode) || is(T == Msize) || is(T == Nwname) || is(T == Nwqid) || is(T == Offset) || is(T == Perm) || 
138 							 is(T == Size) || is(T == Stat) || is(T == Tag) || is(T == Type) || is(T == Version); 
139 }
140 
141 /// Casts from StyxObject class
142 auto fromStyxObject(T)(StyxObject obj) if (isStyxObject!T)
143 {
144 	return cast(T) obj;
145 }
146 
147 /// Casts to StyxObject class
148 auto toStyxObject(T)(T obj) if (isStyxObject!T)
149 {
150 	return cast(StyxObject) obj;
151 }
152 
153