3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Auto-generated file - DO NOT EDIT!
\r
24 // Please edit bitconverter.xsl if you want to make changes.
\r
28 namespace Mono.PEToolkit {
\r
31 /// Little-endian bit converter.
\r
33 public sealed class LEBitConverter {
\r
35 internal interface IConverter {
\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
46 public static readonly bool Native = System.BitConverter.IsLittleEndian;
\r
48 private static readonly IConverter impl = System.BitConverter.IsLittleEndian
\r
49 ? new LEConverter() as IConverter
\r
50 : new BEConverter() as IConverter;
\r
55 private LEBitConverter()
\r
57 // Never instantiated.
\r
60 ///<summary></summary>
\r
61 unsafe public static short SwapInt16(short x)
\r
63 short* p = stackalloc short [1];
\r
65 byte* bp = (byte*) p;
\r
72 ///<summary></summary>
\r
73 unsafe public static ushort SwapUInt16(ushort x)
\r
75 ushort* p = stackalloc ushort [1];
\r
77 byte* bp = (byte*) p;
\r
84 ///<summary></summary>
\r
85 unsafe public static int SwapInt32(int x)
\r
87 int* p = stackalloc int [1];
\r
89 byte* bp = (byte*) p;
\r
99 ///<summary></summary>
\r
100 unsafe public static uint SwapUInt32(uint x)
\r
102 uint* p = stackalloc uint [1];
\r
104 byte* bp = (byte*) p;
\r
114 ///<summary></summary>
\r
115 unsafe public static long SwapInt64(long x)
\r
117 long* p = stackalloc long [1];
\r
119 byte* bp = (byte*) p;
\r
135 ///<summary></summary>
\r
136 unsafe public static ulong SwapUInt64(ulong x)
\r
138 ulong* p = stackalloc ulong [1];
\r
140 byte* bp = (byte*) p;
\r
160 internal sealed class LEConverter : IConverter {
\r
161 ///<summary></summary>
\r
162 public short ToInt16(byte [] val, int idx)
\r
164 return BitConverter.ToInt16(val, idx);
\r
166 ///<summary></summary>
\r
167 public ushort ToUInt16(byte [] val, int idx)
\r
169 return BitConverter.ToUInt16(val, idx);
\r
171 ///<summary></summary>
\r
172 public int ToInt32(byte [] val, int idx)
\r
174 return BitConverter.ToInt32(val, idx);
\r
176 ///<summary></summary>
\r
177 public uint ToUInt32(byte [] val, int idx)
\r
179 return BitConverter.ToUInt32(val, idx);
\r
181 ///<summary></summary>
\r
182 public long ToInt64(byte [] val, int idx)
\r
184 return BitConverter.ToInt64(val, idx);
\r
186 ///<summary></summary>
\r
187 public ulong ToUInt64(byte [] val, int idx)
\r
189 return BitConverter.ToUInt64(val, idx);
\r
194 internal sealed class BEConverter : IConverter {
\r
195 ///<summary></summary>
\r
196 public short ToInt16(byte [] val, int idx)
\r
198 return SwapInt16(BitConverter.ToInt16(val, idx));
\r
200 ///<summary></summary>
\r
201 public ushort ToUInt16(byte [] val, int idx)
\r
203 return SwapUInt16(BitConverter.ToUInt16(val, idx));
\r
205 ///<summary></summary>
\r
206 public int ToInt32(byte [] val, int idx)
\r
208 return SwapInt32(BitConverter.ToInt32(val, idx));
\r
210 ///<summary></summary>
\r
211 public uint ToUInt32(byte [] val, int idx)
\r
213 return SwapUInt32(BitConverter.ToUInt32(val, idx));
\r
215 ///<summary></summary>
\r
216 public long ToInt64(byte [] val, int idx)
\r
218 return SwapInt64(BitConverter.ToInt64(val, idx));
\r
220 ///<summary></summary>
\r
221 public ulong ToUInt64(byte [] val, int idx)
\r
223 return SwapUInt64(BitConverter.ToUInt64(val, idx));
\r
231 ///<summary></summary>
\r
232 public static short ToInt16(byte [] val, int idx)
\r
234 return impl.ToInt16(val, idx);
\r
237 ///<summary></summary>
\r
238 public static ushort ToUInt16(byte [] val, int idx)
\r
240 return impl.ToUInt16(val, idx);
\r
243 ///<summary></summary>
\r
244 public static int ToInt32(byte [] val, int idx)
\r
246 return impl.ToInt32(val, idx);
\r
249 ///<summary></summary>
\r
250 public static uint ToUInt32(byte [] val, int idx)
\r
252 return impl.ToUInt32(val, idx);
\r
255 ///<summary></summary>
\r
256 public static long ToInt64(byte [] val, int idx)
\r
258 return impl.ToInt64(val, idx);
\r
261 ///<summary></summary>
\r
262 public static ulong ToUInt64(byte [] val, int idx)
\r
264 return impl.ToUInt64(val, idx);
\r