* Run code cleanup * Start manual cleanup after dotnet format * Finish up manual pass * Fix up missed warnings * Fix after merge * Update src/Umbraco.Core/Cache/ContentTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DataTypeCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DeepCloneAppCache.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/DomainCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/FastDictionaryAppCacheBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MacroCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MediaCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Cache/MemberGroupCacheRefresher.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/OrderedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Configuration/Models/RequestHandlerSettings.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/SetCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Composing/WeightedCollectionBuilderBase.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/ContentApps/ContentAppFactoryCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Dashboards/DashboardCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DataTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/ContentUnpublishingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DictionaryItemSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/DomainCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/LanguageCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MacroCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptiedRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaEmptyingRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaMovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTreeChangeNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MediaTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberGroupSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeChangedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeMovingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeRefreshedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MemberTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/StringExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovedToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/MovingToRecycleBinNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Extensions/UriExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/PhysicalFileSystem.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/IO/ShadowWrapper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Logging/DisposableTimer.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Install/InstallSteps/UpgradeStep.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Mapping/MapDefinitionCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Media/EmbedProviders/EmbedProvidersCollectionBuilder.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PartialViewSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntryDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/PublicAccessEntrySavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeCacheRefresherNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavedNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/RelationTypeSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StatefulNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetDeletingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Notifications/StylesheetSavingNotification.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/DeepCloneHelper.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/File.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Update src/Umbraco.Core/Models/PropertyGroupExtensions.cs Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> * Fix based on review * Fix after merge Signed-off-by: Zeegaan <nge@umbraco.dk> Co-authored-by: Nikolaj Geisle <niko737@edu.ucl.dk> Co-authored-by: Mole <nikolajlauridsen@protonmail.ch> Co-authored-by: Zeegaan <nge@umbraco.dk>
347 lines
11 KiB
C#
347 lines
11 KiB
C#
namespace Umbraco.Cms.Core.Media.Exif;
|
|
|
|
/// <summary>
|
|
/// An endian-aware converter for converting between base data types
|
|
/// and an array of bytes.
|
|
/// </summary>
|
|
internal class BitConverterEx
|
|
{
|
|
#region Public Enums
|
|
|
|
/// <summary>
|
|
/// Represents the byte order.
|
|
/// </summary>
|
|
public enum ByteOrder
|
|
{
|
|
LittleEndian = 1,
|
|
BigEndian = 2,
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Member Variables
|
|
|
|
private readonly ByteOrder mFrom;
|
|
private readonly ByteOrder mTo;
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
public BitConverterEx(ByteOrder from, ByteOrder to)
|
|
{
|
|
mFrom = from;
|
|
mTo = to;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties
|
|
|
|
/// <summary>
|
|
/// Indicates the byte order in which data is stored in this platform.
|
|
/// </summary>
|
|
public static ByteOrder SystemByteOrder =>
|
|
BitConverter.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian;
|
|
|
|
#endregion
|
|
|
|
#region Predefined Values
|
|
|
|
/// <summary>
|
|
/// Returns a bit converter that converts between little-endian and system byte-order.
|
|
/// </summary>
|
|
public static BitConverterEx LittleEndian => new BitConverterEx(ByteOrder.LittleEndian, SystemByteOrder);
|
|
|
|
/// <summary>
|
|
/// Returns a bit converter that converts between big-endian and system byte-order.
|
|
/// </summary>
|
|
public static BitConverterEx BigEndian => new BitConverterEx(ByteOrder.BigEndian, SystemByteOrder);
|
|
|
|
/// <summary>
|
|
/// Returns a bit converter that does not do any byte-order conversion.
|
|
/// </summary>
|
|
public static BitConverterEx SystemEndian => new BitConverterEx(SystemByteOrder, SystemByteOrder);
|
|
|
|
#endregion
|
|
|
|
#region Static Methods
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a Unicode character.
|
|
/// </summary>
|
|
public static char ToChar(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 2, from, to);
|
|
return BitConverter.ToChar(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 16-bit unsigned integer.
|
|
/// </summary>
|
|
public static ushort ToUInt16(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 2, from, to);
|
|
return BitConverter.ToUInt16(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 32-bit unsigned integer.
|
|
/// </summary>
|
|
public static uint ToUInt32(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 4, from, to);
|
|
return BitConverter.ToUInt32(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 64-bit unsigned integer.
|
|
/// </summary>
|
|
public static ulong ToUInt64(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 8, from, to);
|
|
return BitConverter.ToUInt64(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 16-bit signed integer.
|
|
/// </summary>
|
|
public static short ToInt16(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 2, from, to);
|
|
return BitConverter.ToInt16(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 32-bit signed integer.
|
|
/// </summary>
|
|
public static int ToInt32(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 4, from, to);
|
|
return BitConverter.ToInt32(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 64-bit signed integer.
|
|
/// </summary>
|
|
public static long ToInt64(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 8, from, to);
|
|
return BitConverter.ToInt64(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a single precision floating number.
|
|
/// </summary>
|
|
public static float ToSingle(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 4, from, to);
|
|
return BitConverter.ToSingle(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a double precision floating number.
|
|
/// </summary>
|
|
public static double ToDouble(byte[] value, long startIndex, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = CheckData(value, startIndex, 8, from, to);
|
|
return BitConverter.ToDouble(data, 0);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 16-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(ushort value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 32-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(uint value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 64-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(ulong value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 16-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(short value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 32-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(int value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given 64-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(long value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given single precision floating-point number to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(float value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the given double precision floating-point number to an array of bytes.
|
|
/// </summary>
|
|
public static byte[] GetBytes(double value, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = BitConverter.GetBytes(value);
|
|
data = CheckData(data, from, to);
|
|
return data;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Instance Methods
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 16-bit unsigned integer.
|
|
/// </summary>
|
|
public char ToChar(byte[] value, long startIndex) => ToChar(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 16-bit unsigned integer.
|
|
/// </summary>
|
|
public ushort ToUInt16(byte[] value, long startIndex) => ToUInt16(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 32-bit unsigned integer.
|
|
/// </summary>
|
|
public uint ToUInt32(byte[] value, long startIndex) => ToUInt32(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 64-bit unsigned integer.
|
|
/// </summary>
|
|
public ulong ToUInt64(byte[] value, long startIndex) => ToUInt64(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 16-bit signed integer.
|
|
/// </summary>
|
|
public short ToInt16(byte[] value, long startIndex) => ToInt16(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 32-bit signed integer.
|
|
/// </summary>
|
|
public int ToInt32(byte[] value, long startIndex) => ToInt32(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a 64-bit signed integer.
|
|
/// </summary>
|
|
public long ToInt64(byte[] value, long startIndex) => ToInt64(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a single precision floating number.
|
|
/// </summary>
|
|
public float ToSingle(byte[] value, long startIndex) => ToSingle(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given array of bytes to a double precision floating number.
|
|
/// </summary>
|
|
public double ToDouble(byte[] value, long startIndex) => ToDouble(value, startIndex, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 16-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(ushort value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 32-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(uint value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 64-bit unsigned integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(ulong value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 16-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(short value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 32-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(int value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given 64-bit signed integer to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(long value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given single precision floating-point number to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(float value) => GetBytes(value, mFrom, mTo);
|
|
|
|
/// <summary>
|
|
/// Converts the given double precision floating-point number to an array of bytes.
|
|
/// </summary>
|
|
public byte[] GetBytes(double value) => GetBytes(value, mFrom, mTo);
|
|
|
|
#endregion
|
|
|
|
#region Private Helpers
|
|
|
|
/// <summary>
|
|
/// Reverse the array of bytes as needed.
|
|
/// </summary>
|
|
private static byte[] CheckData(byte[] value, long startIndex, long length, ByteOrder from, ByteOrder to)
|
|
{
|
|
var data = new byte[length];
|
|
Array.Copy(value, startIndex, data, 0, length);
|
|
if (from != to)
|
|
{
|
|
Array.Reverse(data);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reverse the array of bytes as needed.
|
|
/// </summary>
|
|
private static byte[] CheckData(byte[] value, ByteOrder from, ByteOrder to) =>
|
|
CheckData(value, 0, value.Length, from, to);
|
|
|
|
#endregion
|
|
}
|