本文整理汇总了C#中Endianity类的典型用法代码示例。如果您正苦于以下问题:C# Endianity类的具体用法?C# Endianity怎么用?C# Endianity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Endianity类属于命名空间,在下文中一共展示了Endianity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadIpV6Address
/// <summary>
/// Reads 16 bytes from a specific offset as an IPv6 address with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static IpV6Address ReadIpV6Address(this byte[] buffer, int offset, Endianity endianity)
{
return new IpV6Address(buffer.ReadUInt128(offset, endianity));
}
示例2: Write
/// <summary>
/// Writes the given value to the buffer using the given endianity and increments the offset by the number of bytes written.
/// </summary>
/// <param name="buffer">The buffer to write the value to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
/// <param name="value">The value to write.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public static void Write(this byte[] buffer, ref int offset, IpV6Address value, Endianity endianity)
{
buffer.Write(ref offset, value.ToValue(), endianity);
}
示例3: ReadShort
public static short ReadShort(this byte[] buffer, int offset, Endianity endianity)
{
short value = ReadShort(buffer, offset);
if (IsWrongEndianity(endianity))
value = value.ReverseEndianity();
return value;
}
示例4: ReadUInt48
/// <summary>
/// Reads 6 bytes from a specific offset as a UInt48 with a given endianity and increments the offset by the number of bytes read.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static UInt48 ReadUInt48(this byte[] buffer, ref int offset, Endianity endianity)
{
UInt48 result = buffer.ReadUInt48(offset, endianity);
offset += UInt48.SizeOf;
return result;
}
示例5: ReadLong
public static long ReadLong(this byte[] buffer, int offset, Endianity endianity)
{
long value = ReadLong(buffer, offset);
if (IsWrongEndianity(endianity))
value = IPAddress.HostToNetworkOrder(value);
return value;
}
示例6: ReadUInt
public static uint ReadUInt(this byte[] buffer, int offset, Endianity endianity)
{
return (uint)ReadInt(buffer, offset, endianity);
}
示例7: ReadUInt24
/// <summary>
/// Reads 3 bytes from a specific offset as a UInt24 with a given endianity and increments the offset by the number of bytes read.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static UInt24 ReadUInt24(this byte[] buffer, ref int offset, Endianity endianity)
{
UInt24 result = ReadUInt24(buffer, offset, endianity);
offset += UInt24.SizeOf;
return result;
}
示例8: ReadUShort
public static ushort ReadUShort(this byte[] buffer, ref int offset, Endianity endianity)
{
ushort result = ReadUShort(buffer, offset, endianity);
offset += sizeof(ushort);
return result;
}
示例9: ReadULong
public static ulong ReadULong(this byte[] buffer, int offset, Endianity endianity)
{
return (ulong)buffer.ReadLong(offset, endianity);
}
示例10: ReadUInt128
/// <summary>
/// Reads 16 bytes from a specific offset as a UInt128 with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static UInt128 ReadUInt128(this byte[] buffer, int offset, Endianity endianity)
{
UInt128 value = ReadUInt128(buffer, offset);
if (IsWrongEndianity(endianity))
value = HostToNetworkOrder(value);
return value;
}
示例11: ReadUnsignedBigInteger
/// <summary>
/// Reads a given amount of bytes from a specific offset as an unsigned BigInteger with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="length">The number of bytes to read.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static BigInteger ReadUnsignedBigInteger(this byte[] buffer, int offset, int length, Endianity endianity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
BigInteger value = BigInteger.Zero;
for (int i = 0; i != length; ++i)
{
value <<= 8;
if (endianity == Endianity.Big)
value += buffer[offset + i];
else
value += buffer[offset + length - i - 1];
}
return value;
}
示例12: ReadMacAddress
/// <summary>
/// Reads 6 bytes from a specific offset as a MacAddress with a given endianity and increments the offset by the number of bytes read.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static MacAddress ReadMacAddress(this byte[] buffer, ref int offset, Endianity endianity)
{
return new MacAddress(buffer.ReadUInt48(ref offset, endianity));
}
示例13: WriteUnsigned
/// <summary>
/// Writes the given amount of least significant bytes of the value to the buffer using the given endianity.
/// Doesn't write leading zero bytes.
/// </summary>
/// <param name="buffer">The buffer to write the value to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
/// <param name="value">The value to write.</param>
/// <param name="length">The maximum amount of bytes to write.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public static void WriteUnsigned(this byte[] buffer, int offset, BigInteger value, int length, Endianity endianity)
{
if (buffer == null)
throw new ArgumentNullException("buffer");
if (value.Sign < 0)
throw new ArgumentOutOfRangeException("value", value, "Must be non-negative.");
for (int i = 0; i != length && value != BigInteger.Zero; ++i, value >>= 8)
{
byte byteValue = (byte)(value & 0xFF);
if (endianity == Endianity.Small)
buffer[offset + i] = byteValue;
else
buffer[offset + length - i - 1] = byteValue;
}
}
示例14: ReadIpV4Address
/// <summary>
/// Reads 4 bytes from a specific offset as an IPv4 address with a given endianity and increments the offset by the number of bytes read.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static IpV4Address ReadIpV4Address(this byte[] buffer, ref int offset, Endianity endianity)
{
return new IpV4Address(buffer.ReadUInt(ref offset, endianity));
}
示例15: ReadIpV4TimeOfDay
/// <summary>
/// Reads 4 bytes from a specific offset as an IPv4 time of day with a given endianity and increments the offset by the number of bytes read.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public static IpV4TimeOfDay ReadIpV4TimeOfDay(this byte[] buffer, ref int offset, Endianity endianity)
{
return new IpV4TimeOfDay(buffer.ReadUInt(ref offset, endianity));
}