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 import styx2000.protobj; 16 17 /// Alias for type tuple 18 alias Tuple(E...) = E; 19 20 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 21 /// `size[4] Tversion tag[2] msize[4] version[s]` 22 alias Tversion = Tuple!(Size, Type, Tag, Msize, Version); 23 24 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 25 /// `size[4] Rversion tag[2] msize[4] version[s]` 26 alias Rversion = Tuple!(Size, Type, Tag, Msize, Version); 27 28 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 29 /// `size[4] Tauth tag[2] afid[4] uname[s] aname[s]` 30 alias Tauth = Tuple!(Size, Type, Tag, Afid, Uname, Aname); 31 32 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 33 /// `size[4] Rauth tag[2] aqid[13]` 34 alias Rauth = Tuple!(Size, Type, Tag, Aqid); 35 36 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 37 /// `size[4] Rerror tag[2] ename[s]` 38 alias Rerror = Tuple!(Size, Type, Tag, Ename); 39 40 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 41 /// `size[4] Tflush tag[2] oldtag[2]` 42 alias Tflush = Tuple!(Size, Type, Tag, Tag); 43 44 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 45 /// `size[4] Rflush tag[2]` 46 alias Rflush = Tuple!(Size, Type, Tag); 47 48 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 49 /// `size[4] Tattach tag[2] fid[4] afid[4] uname[s] aname[s]` 50 alias Tattach = Tuple!(Size, Type, Tag, Fid, Afid, Uname, Aname); 51 52 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 53 /// `size[4] Rattach tag[2] qid[13]` 54 alias Rattach = Tuple!(Size, Type, Tag, Qid); 55 56 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 57 /// `size[4] Twalk tag[2] fid[4] newfid[4] nwname[2] nwname*(wname[s])` 58 alias Twalk = Tuple!(Size, Type, Tag, Fid, Fid, Nwname); 59 60 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 61 /// `size[4] Rwalk tag[2] nwqid[2] nwqid*(wqid[13])` 62 alias Rwalk = Tuple!(Size, Type, Tag, Nwqid); 63 64 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 65 /// `size[4] Topen tag[2] fid[4] mode[1]` 66 alias Topen = Tuple!(Size, Type, Tag, Fid, Mode); 67 68 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 69 /// `size[4] Ropen tag[2] qid[13] iounit[4]` 70 alias Ropen = Tuple!(Size, Type, Tag, Qid, Iounit); 71 72 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 73 /// `size[4] Tcreate tag[2] fid[4] name[s] perm[4] mode[1]` 74 alias Tcreate = Tuple!(Size, Type, Tag, Fid, Name, Perm, Mode); 75 76 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 77 /// `size[4] Rcreate tag[2] qid[13] iounit[4]` 78 alias Rcreate = Tuple!(Size, Type, Tag, Qid, Iounit); 79 80 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 81 /// `size[4] Tread tag[2] fid[4] offset[8] count[4]` 82 alias Tread = Tuple!(Size, Type, Tag, Fid, Offset, Count); 83 84 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 85 /// `size[4] Rread tag[2] count[4] data[count]` 86 alias Rread = Tuple!(Size, Type, Tag, Count, Data); 87 88 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 89 /// `size[4] Twrite tag[2] fid[4] offset[8] count[4] data[count]` 90 alias Twrite = Tuple!(Size, Type, Tag, Fid, Offset, Count, Data); 91 92 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 93 /// `size[4] Rwrite tag[2] count[4]` 94 alias Rwrite = Tuple!(Size, Type, Tag, Count); 95 96 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 97 /// `size[4] Tclunk tag[2] fid[4]` 98 alias Tclunk = Tuple!(Size, Type, Tag, Fid); 99 100 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 101 /// `size[4] Rclunk tag[2]` 102 alias Rclunk = Tuple!(Size, Type, Tag); 103 104 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 105 /// `size[4] Tremove tag[2] fid[4]` 106 alias Tremove = Tuple!(Size, Type, Tag, Fid); 107 108 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 109 /// `size[4] Rremove tag[2]` 110 alias Rremove = Tuple!(Size, Type, Tag); 111 112 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 113 /// `size[4] Tstat tag[2] fid[4]` 114 alias Tstat = Tuple!(Size, Type, Tag, Fid); 115 116 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 117 /// `size[4] Rstat tag[2] stat[n]` 118 alias Rstat = Tuple!(Size, Type, Tag, Stat); 119 120 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 121 /// `size[4] Twstat tag[2] fid[4] stat[n]` 122 alias Twstat = Tuple!(Size, Type, Tag, Fid, Stat); 123 124 /// This tuple of types mimics the structure of the corresponding message, which looks like this: 125 /// `size[4] Rwstat tag[2]` 126 alias Rwstat = Tuple!(Size, Type, Tag); 127 128 /// Is one of StyxObject class ? 129 template isStyxObject(T) 130 { 131 enum bool isStyxObject = is(T == Afid) || is(T : Qid) || is(T == Count)|| is(T == Data) || is(T : Name) || is(T : Fid) || is(T == Iounit) || 132 is(T == Mode) || is(T == Msize) || is(T == Nwname) || is(T == Nwqid) || is(T == Offset) || is(T == Perm) || 133 is(T == Size) || is(T == Stat) || is(T == Tag) || is(T == Type) || is(T == Version); 134 } 135 136 /// Casts from StyxObject class 137 auto fromStyxObject(T)(StyxObject obj) if (isStyxObject!T) 138 { 139 return cast(T) obj; 140 } 141 142 /// Casts to StyxObject class 143 auto toStyxObject(T)(T obj) if (isStyxObject!T) 144 { 145 return cast(StyxObject) obj; 146 }