!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / LuaRemoteDebugger / LuaRemoteDebugger / MiscUtil / BigEndianBitConverter.cs
blob6a5591ccfdcbcdabf44f853abd0c78e3be27f14e
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 namespace MiscUtil.Conversion
5 /// <summary>
6 /// Implementation of EndianBitConverter which converts to/from big-endian
7 /// byte arrays.
8 /// </summary>
9 public sealed class BigEndianBitConverter : EndianBitConverter
11 /// <summary>
12 /// Indicates the byte order ("endianess") in which data is converted using this class.
13 /// </summary>
14 /// <remarks>
15 /// Different computer architectures store data using different byte orders. "Big-endian"
16 /// means the most significant byte is on the left end of a word. "Little-endian" means the
17 /// most significant byte is on the right end of a word.
18 /// </remarks>
19 /// <returns>true if this converter is little-endian, false otherwise.</returns>
20 public sealed override bool IsLittleEndian()
22 return false;
25 /// <summary>
26 /// Indicates the byte order ("endianess") in which data is converted using this class.
27 /// </summary>
28 public sealed override Endianness Endianness
30 get { return Endianness.BigEndian; }
33 /// <summary>
34 /// Copies the specified number of bytes from value to buffer, starting at index.
35 /// </summary>
36 /// <param name="value">The value to copy</param>
37 /// <param name="bytes">The number of bytes to copy</param>
38 /// <param name="buffer">The buffer to copy the bytes into</param>
39 /// <param name="index">The index to start at</param>
40 protected override void CopyBytesImpl(long value, int bytes, byte[] buffer, int index)
42 int endOffset = index+bytes-1;
43 for (int i=0; i < bytes; i++)
45 buffer[endOffset-i] = unchecked((byte)(value&0xff));
46 value = value >> 8;
50 /// <summary>
51 /// Returns a value built from the specified number of bytes from the given buffer,
52 /// starting at index.
53 /// </summary>
54 /// <param name="buffer">The data in byte array format</param>
55 /// <param name="startIndex">The first index to use</param>
56 /// <param name="bytesToConvert">The number of bytes to use</param>
57 /// <returns>The value built from the given bytes</returns>
58 protected override long FromBytes(byte[] buffer, int startIndex, int bytesToConvert)
60 long ret = 0;
61 for (int i=0; i < bytesToConvert; i++)
63 ret = unchecked((ret << 8) | buffer[startIndex+i]);
65 return ret;