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!
24 // Please edit bitconverter.xsl if you want to make changes.
28 namespace Mono
.PEToolkit
{
31 /// Little-endian bit converter.
33 public sealed class LEBitConverter
{
35 internal interface IConverter
{
37 short ToInt16(byte [] val
, int idx
);
38 ushort ToUInt16(byte [] val
, int idx
);
39 int ToInt32(byte [] val
, int idx
);
40 uint ToUInt32(byte [] val
, int idx
);
41 long ToInt64(byte [] val
, int idx
);
42 ulong ToUInt64(byte [] val
, int idx
);
46 public static readonly bool Native
= System
.BitConverter
.IsLittleEndian
;
48 private static readonly IConverter impl
= System
.BitConverter
.IsLittleEndian
49 ? new LEConverter() as IConverter
50 : new BEConverter() as IConverter
;
55 private LEBitConverter()
57 // Never instantiated.
60 ///<summary></summary>
61 unsafe public static short SwapInt16(short x
)
63 short* p
= stackalloc short [1];
72 ///<summary></summary>
73 unsafe public static ushort SwapUInt16(ushort x
)
75 ushort* p
= stackalloc ushort [1];
84 ///<summary></summary>
85 unsafe public static int SwapInt32(int x
)
87 int* p
= stackalloc int [1];
99 ///<summary></summary>
100 unsafe public static uint SwapUInt32(uint x
)
102 uint* p
= stackalloc uint [1];
104 byte* bp
= (byte*) p
;
114 ///<summary></summary>
115 unsafe public static long SwapInt64(long x
)
117 long* p
= stackalloc long [1];
119 byte* bp
= (byte*) p
;
135 ///<summary></summary>
136 unsafe public static ulong SwapUInt64(ulong x
)
138 ulong* p
= stackalloc ulong [1];
140 byte* bp
= (byte*) p
;
160 internal sealed class LEConverter
: IConverter
{
161 ///<summary></summary>
162 public short ToInt16(byte [] val
, int idx
)
164 return BitConverter
.ToInt16(val
, idx
);
166 ///<summary></summary>
167 public ushort ToUInt16(byte [] val
, int idx
)
169 return BitConverter
.ToUInt16(val
, idx
);
171 ///<summary></summary>
172 public int ToInt32(byte [] val
, int idx
)
174 return BitConverter
.ToInt32(val
, idx
);
176 ///<summary></summary>
177 public uint ToUInt32(byte [] val
, int idx
)
179 return BitConverter
.ToUInt32(val
, idx
);
181 ///<summary></summary>
182 public long ToInt64(byte [] val
, int idx
)
184 return BitConverter
.ToInt64(val
, idx
);
186 ///<summary></summary>
187 public ulong ToUInt64(byte [] val
, int idx
)
189 return BitConverter
.ToUInt64(val
, idx
);
194 internal sealed class BEConverter
: IConverter
{
195 ///<summary></summary>
196 public short ToInt16(byte [] val
, int idx
)
198 return SwapInt16(BitConverter
.ToInt16(val
, idx
));
200 ///<summary></summary>
201 public ushort ToUInt16(byte [] val
, int idx
)
203 return SwapUInt16(BitConverter
.ToUInt16(val
, idx
));
205 ///<summary></summary>
206 public int ToInt32(byte [] val
, int idx
)
208 return SwapInt32(BitConverter
.ToInt32(val
, idx
));
210 ///<summary></summary>
211 public uint ToUInt32(byte [] val
, int idx
)
213 return SwapUInt32(BitConverter
.ToUInt32(val
, idx
));
215 ///<summary></summary>
216 public long ToInt64(byte [] val
, int idx
)
218 return SwapInt64(BitConverter
.ToInt64(val
, idx
));
220 ///<summary></summary>
221 public ulong ToUInt64(byte [] val
, int idx
)
223 return SwapUInt64(BitConverter
.ToUInt64(val
, idx
));
231 ///<summary></summary>
232 public static short ToInt16(byte [] val
, int idx
)
234 return impl
.ToInt16(val
, idx
);
237 ///<summary></summary>
238 public static ushort ToUInt16(byte [] val
, int idx
)
240 return impl
.ToUInt16(val
, idx
);
243 ///<summary></summary>
244 public static int ToInt32(byte [] val
, int idx
)
246 return impl
.ToInt32(val
, idx
);
249 ///<summary></summary>
250 public static uint ToUInt32(byte [] val
, int idx
)
252 return impl
.ToUInt32(val
, idx
);
255 ///<summary></summary>
256 public static long ToInt64(byte [] val
, int idx
)
258 return impl
.ToInt64(val
, idx
);
261 ///<summary></summary>
262 public static ulong ToUInt64(byte [] val
, int idx
)
264 return impl
.ToUInt64(val
, idx
);