* ProtocolImporter.cs: Use the binding name as class name for the
[mono.git] / mcs / class / Mono.PEToolkit / LEBitConverter.cs
1 \r
2 //\r
3 // Permission is hereby granted, free of charge, to any person obtaining\r
4 // a copy of this software and associated documentation files (the\r
5 // "Software"), to deal in the Software without restriction, including\r
6 // without limitation the rights to use, copy, modify, merge, publish,\r
7 // distribute, sublicense, and/or sell copies of the Software, and to\r
8 // permit persons to whom the Software is furnished to do so, subject to\r
9 // the following conditions:\r
10 // \r
11 // The above copyright notice and this permission notice shall be\r
12 // included in all copies or substantial portions of the Software.\r
13 // \r
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21 //\r
22 \r
23 // Auto-generated file - DO NOT EDIT!\r
24 // Please edit bitconverter.xsl if you want to make changes.\r
25 \r
26 using System;\r
27 \r
28 namespace Mono.PEToolkit {\r
29 \r
30         /// <summary>\r
31         /// Little-endian bit converter.\r
32         /// </summary>\r
33         public sealed class LEBitConverter {\r
34 \r
35                 internal interface IConverter {\r
36 \r
37                         short ToInt16(byte [] val, int idx);\r
38                         ushort ToUInt16(byte [] val, int idx);\r
39                         int ToInt32(byte [] val, int idx);\r
40                         uint ToUInt32(byte [] val, int idx);\r
41                         long ToInt64(byte [] val, int idx);\r
42                         ulong ToUInt64(byte [] val, int idx);\r
43 \r
44                 }\r
45 \r
46                 public static readonly bool Native = System.BitConverter.IsLittleEndian;\r
47 \r
48                 private static readonly IConverter impl = System.BitConverter.IsLittleEndian\r
49                                         ? new LEConverter() as IConverter\r
50                                         : new BEConverter() as IConverter;\r
51 \r
52 \r
53 \r
54 \r
55                 private LEBitConverter()\r
56                 {\r
57                         // Never instantiated.\r
58                 }\r
59 \r
60                 ///<summary></summary>\r
61                 unsafe public static short SwapInt16(short x)\r
62                 {\r
63                         short* p = stackalloc short [1];\r
64                         *p = x;\r
65                         byte* bp = (byte*) p;\r
66                         byte b = bp [0];\r
67                         bp [0] = bp [1];\r
68                         bp [1] = b;\r
69                         return *p;\r
70                 }\r
71 \r
72                 ///<summary></summary>\r
73                 unsafe public static ushort SwapUInt16(ushort x)\r
74                 {\r
75                         ushort* p = stackalloc ushort [1];\r
76                         *p = x;\r
77                         byte* bp = (byte*) p;\r
78                         byte b = bp [0];\r
79                         bp [0] = bp [1];\r
80                         bp [1] = b;\r
81                         return *p;\r
82                 }\r
83 \r
84                 ///<summary></summary>\r
85                 unsafe public static int SwapInt32(int x)\r
86                 {\r
87                         int* p = stackalloc int [1];\r
88                         *p = x;\r
89                         byte* bp = (byte*) p;\r
90                         byte b = bp [0];\r
91                         bp [0] = bp [3];\r
92                         bp [3] = b;\r
93                         b = bp [1];\r
94                         bp [1] = bp [2];\r
95                         bp [2] = b;\r
96                         return *p;\r
97                 }\r
98 \r
99                 ///<summary></summary>\r
100                 unsafe public static uint SwapUInt32(uint x)\r
101                 {\r
102                         uint* p = stackalloc uint [1];\r
103                         *p = x;\r
104                         byte* bp = (byte*) p;\r
105                         byte b = bp [0];\r
106                         bp [0] = bp [3];\r
107                         bp [3] = b;\r
108                         b = bp [1];\r
109                         bp [1] = bp [2];\r
110                         bp [2] = b;\r
111                         return *p;\r
112                 }\r
113 \r
114                 ///<summary></summary>\r
115                 unsafe public static long SwapInt64(long x)\r
116                 {\r
117                         long* p = stackalloc long [1];\r
118                         *p = x;\r
119                         byte* bp = (byte*) p;\r
120                         byte b = bp [0];\r
121                         bp [0] = bp [7];\r
122                         bp [7] = b;\r
123                         b = bp [1];\r
124                         bp [1] = bp [6];\r
125                         bp [6] = b;\r
126                         b = bp [2];\r
127                         bp [2] = bp [5];\r
128                         bp [5] = b;\r
129                         b = bp [3];\r
130                         bp [3] = bp [4];\r
131                         bp [4] = b;\r
132                         return *p;\r
133                 }\r
134 \r
135                 ///<summary></summary>\r
136                 unsafe public static ulong SwapUInt64(ulong x)\r
137                 {\r
138                         ulong* p = stackalloc ulong [1];\r
139                         *p = x;\r
140                         byte* bp = (byte*) p;\r
141                         byte b = bp [0];\r
142                         bp [0] = bp [7];\r
143                         bp [7] = b;\r
144                         b = bp [1];\r
145                         bp [1] = bp [6];\r
146                         bp [6] = b;\r
147                         b = bp [2];\r
148                         bp [2] = bp [5];\r
149                         bp [5] = b;\r
150                         b = bp [3];\r
151                         bp [3] = bp [4];\r
152                         bp [4] = b;\r
153                         return *p;\r
154                 }\r
155 \r
156 \r
157 \r
158 \r
159 \r
160                 internal sealed class LEConverter : IConverter {\r
161                         ///<summary></summary>\r
162                         public short ToInt16(byte [] val, int idx)\r
163                         {\r
164                                 return BitConverter.ToInt16(val, idx);\r
165                         }\r
166                         ///<summary></summary>\r
167                         public ushort ToUInt16(byte [] val, int idx)\r
168                         {\r
169                                 return BitConverter.ToUInt16(val, idx);\r
170                         }\r
171                         ///<summary></summary>\r
172                         public int ToInt32(byte [] val, int idx)\r
173                         {\r
174                                 return BitConverter.ToInt32(val, idx);\r
175                         }\r
176                         ///<summary></summary>\r
177                         public uint ToUInt32(byte [] val, int idx)\r
178                         {\r
179                                 return BitConverter.ToUInt32(val, idx);\r
180                         }\r
181                         ///<summary></summary>\r
182                         public long ToInt64(byte [] val, int idx)\r
183                         {\r
184                                 return BitConverter.ToInt64(val, idx);\r
185                         }\r
186                         ///<summary></summary>\r
187                         public ulong ToUInt64(byte [] val, int idx)\r
188                         {\r
189                                 return BitConverter.ToUInt64(val, idx);\r
190                         }\r
191 \r
192                 }\r
193 \r
194                 internal sealed class BEConverter : IConverter {\r
195                         ///<summary></summary>\r
196                         public short ToInt16(byte [] val, int idx)\r
197                         {\r
198                                 return SwapInt16(BitConverter.ToInt16(val, idx));\r
199                         }\r
200                         ///<summary></summary>\r
201                         public ushort ToUInt16(byte [] val, int idx)\r
202                         {\r
203                                 return SwapUInt16(BitConverter.ToUInt16(val, idx));\r
204                         }\r
205                         ///<summary></summary>\r
206                         public int ToInt32(byte [] val, int idx)\r
207                         {\r
208                                 return SwapInt32(BitConverter.ToInt32(val, idx));\r
209                         }\r
210                         ///<summary></summary>\r
211                         public uint ToUInt32(byte [] val, int idx)\r
212                         {\r
213                                 return SwapUInt32(BitConverter.ToUInt32(val, idx));\r
214                         }\r
215                         ///<summary></summary>\r
216                         public long ToInt64(byte [] val, int idx)\r
217                         {\r
218                                 return SwapInt64(BitConverter.ToInt64(val, idx));\r
219                         }\r
220                         ///<summary></summary>\r
221                         public ulong ToUInt64(byte [] val, int idx)\r
222                         {\r
223                                 return SwapUInt64(BitConverter.ToUInt64(val, idx));\r
224                         }\r
225 \r
226                 }\r
227 \r
228 \r
229 \r
230 \r
231                 ///<summary></summary>\r
232                 public static short ToInt16(byte [] val, int idx)\r
233                 {\r
234                         return impl.ToInt16(val, idx);\r
235                 }\r
236 \r
237                 ///<summary></summary>\r
238                 public static ushort ToUInt16(byte [] val, int idx)\r
239                 {\r
240                         return impl.ToUInt16(val, idx);\r
241                 }\r
242 \r
243                 ///<summary></summary>\r
244                 public static int ToInt32(byte [] val, int idx)\r
245                 {\r
246                         return impl.ToInt32(val, idx);\r
247                 }\r
248 \r
249                 ///<summary></summary>\r
250                 public static uint ToUInt32(byte [] val, int idx)\r
251                 {\r
252                         return impl.ToUInt32(val, idx);\r
253                 }\r
254 \r
255                 ///<summary></summary>\r
256                 public static long ToInt64(byte [] val, int idx)\r
257                 {\r
258                         return impl.ToInt64(val, idx);\r
259                 }\r
260 \r
261                 ///<summary></summary>\r
262                 public static ulong ToUInt64(byte [] val, int idx)\r
263                 {\r
264                         return impl.ToUInt64(val, idx);\r
265                 }\r
266 \r
267 \r
268 \r
269         }\r
270 \r
271 }\r
272 \r