本文整理汇总了C#中ByteOrder类的典型用法代码示例。如果您正苦于以下问题:C# ByteOrder类的具体用法?C# ByteOrder怎么用?C# ByteOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteOrder类属于命名空间,在下文中一共展示了ByteOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DataReader
public DataReader(Stream stream)
{
mStream = new BinaryReader(stream);
if (!BitConverter.IsLittleEndian) {
byteOrder = ByteOrder.Big;
}
}
示例2: GetBytes
/// <summary>
/// Splits number into the byte array
/// </summary>
/// <param name="number">Value to split</param>
/// <param name="outputArray">Array where the bytes be stored</param>
/// <param name="byteOrder">Byte order of the array</param>
public static void GetBytes(long number, byte[] outputArray, ByteOrder byteOrder)
{
if (byteOrder == ByteOrder.BigEndian)
ToBigEndian(number, outputArray);
else
throw new NotImplementedException(Resources.StringResources.NotImplementedLittleEndian.ToString());
}
示例3: GetValue
/// <summary>
/// Get value from the byte array
/// </summary>
/// <param name="byteArray">Byte array</param>
/// <param name="startIndex">Start index in array</param>
/// <param name="length">Number of bytes to parse</param>
/// <param name="byteOrder">Byte order</param>
/// <returns>Long value</returns>
public static long GetValue(byte[] byteArray, int startIndex, int length, ByteOrder byteOrder)
{
if (byteOrder == ByteOrder.BigEndian)
return FromBigEndian(byteArray, startIndex, length);
else
throw new NotImplementedException(Resources.StringResources.NotImplementedLittleEndian.ToString());
}
示例4: PrimitiveElementAttribute
public PrimitiveElementAttribute(int serializationOrder, ByteOrder dataByteOrder)
{
Require.That("serializationOrder", serializationOrder >= 0);
SerializationOrder = serializationOrder;
DataByteOrder = dataByteOrder;
}
示例5: Read16Bits
public static UInt16 Read16Bits(I2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage)
{
try
{
byte[] addr = { reg };
byte[] data = new byte[2];
device.WriteRead(addr, data);
switch (byteOrder)
{
case ByteOrder.BigEndian:
return (UInt16)((data[0] << 8) | data[1]);
case ByteOrder.LittleEndian:
return (UInt16)((data[1] << 8) | data[0]);
default:
throw new SensorException($"Unsupported byte order {byteOrder}");
}
}
catch (Exception exception)
{
throw new SensorException(exceptionMessage, exception);
}
}
示例6: BytesToInt32
public static int BytesToInt32(byte[] bytes, ByteOrder byteOrder)
{
if (byteOrder == ByteOrder.BigEndian)
Array.Reverse(bytes);
return BitConverter.ToInt32(bytes, 0);
}
示例7: OtfHeaderDecoder
/// <summary>
/// Read the message header structure and cache the meta data for finding the key fields for decoding messages.
/// </summary>
/// <param name="headerStructure"> for the meta data describing the message header. </param>
public OtfHeaderDecoder(HeaderStructure headerStructure)
{
_size = headerStructure.Tokens[0].Size;
foreach (Token token in headerStructure.Tokens)
{
switch (token.Name)
{
case HeaderStructure.BlockLength:
_blockLengthOffset = token.Offset;
_blockLengthType = token.Encoding.PrimitiveType;
_blockLengthByteOrder = token.Encoding.ByteOrder;
break;
case HeaderStructure.TemplateId:
_templateIdOffset = token.Offset;
_templateIdType = token.Encoding.PrimitiveType;
_templateIdByteOrder = token.Encoding.ByteOrder;
break;
case HeaderStructure.SchemaId:
_schemaIdOffset = token.Offset;
_schemaIdType = token.Encoding.PrimitiveType;
_schemaIdByteOrder = token.Encoding.ByteOrder;
break;
case HeaderStructure.SchemaVersion:
_schemaVersionOffset = token.Offset;
_schemaVersionType = token.Encoding.PrimitiveType;
_schemaVersionByteOrder = token.Encoding.ByteOrder;
break;
}
}
}
示例8: EmptyByteBuffer
EmptyByteBuffer(IByteBufferAllocator allocator, ByteOrder order)
{
Contract.Requires(allocator != null);
this.allocator = allocator;
this.order = order;
this.str = this.GetType().Name + (order == ByteOrder.BigEndian ? "BE" : "LE");
}
示例9: DataBuffer
/// <summary>
/// Initializes a new instance of the <see cref="DataBuffer"/> class.
/// </summary>
/// <param name="capacity">The capacity of the new instance.</param>
/// <param name="mode">The endianness mode of the new instance.</param>
public DataBuffer(int capacity, ByteOrder mode)
{
Contract.Requires(capacity > 0);
Contract.Ensures(this.Position == 0);
this.data = new byte[capacity];
this.Mode = mode;
}
示例10: Create
/// <summary>Create a <see cref="BinaryReader"/> or a <see cref="BigEndianBinaryReader"/> based upon a <see cref="ByteOrder"/>.</summary>
/// <param name="byteOrder"></param>
/// <param name="input"></param>
/// <returns></returns>
public static BinaryReader Create(ByteOrder byteOrder, Stream input)
{
switch (byteOrder) {
case ByteOrder.LittleEndian: return new BinaryReader(input);
case ByteOrder.BigEndian: return new BigEndianBinaryReader(input);
default: throw new NotSupportedException();
}
}
示例11: ToURational
/// <summary>
/// Returns an unsigned rational number converted from the first
/// eight bytes of the given byte array. The first four bytes are
/// assumed to be the numerator and the next four bytes are the
/// denumerator.
/// Numbers are converted from the given byte-order to platform byte-order.
/// </summary>
public static MathEx.UFraction32 ToURational(byte[] data, ByteOrder frombyteorder)
{
byte[] num = new byte[4];
byte[] den = new byte[4];
Array.Copy(data, 0, num, 0, 4);
Array.Copy(data, 4, den, 0, 4);
return new MathEx.UFraction32(ToUInt32(num, 0, frombyteorder, ByteOrder.System), ToUInt32(den, 0, frombyteorder, ByteOrder.System));
}
示例12: ByteReader
/// <summary>
/// Creates a new instance of ByteReader with UTF-8 encoding.
/// </summary>
/// <param name="message">The bytes to read from</param>
public ByteReader(byte[] message)
{
_message = message;
_position = 0;
if (_byteOrder == ByteOrder.Default)
_byteOrder = _defaultByteOrder;
}
示例13: CoalescedFileXml
public CoalescedFileXml(List<FileEntry> files = null, IEnumerable<int> compileTypes = null, ByteOrder byteOrder = ByteOrder.LittleEndian, int overrideCompileValueTypes = -1, uint version = 0)
{
ByteOrder = byteOrder;
Files = files ?? new List<FileEntry>();
OverrideCompileValueTypes = overrideCompileValueTypes;
Version = version;
CompileTypes = compileTypes ?? new[] { 0, 1, 2, 3, 4 };
}
示例14: GetBytes
/// <summary>
/// Converts the given signed rational number to an array of bytes.
/// Numbers are converted from the platform byte-order to the given byte-order.
/// </summary>
public static byte[] GetBytes(MathEx.Fraction32 value, ByteOrder tobyteorder)
{
byte[] num = GetBytes(value.Numerator, ByteOrder.System, tobyteorder);
byte[] den = GetBytes(value.Denominator, ByteOrder.System, tobyteorder);
byte[] data = new byte[8];
Array.Copy(num, 0, data, 0, 4);
Array.Copy(den, 0, data, 4, 4);
return data;
}
示例15: ToHostOrder
public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder)
{
if (src == null)
return null;
return src.Length > 1 && !srcOrder.IsHostOrder()
? src.CopyReverse()
: src;
}