本文整理汇总了C#中Endianness类的典型用法代码示例。如果您正苦于以下问题:C# Endianness类的具体用法?C# Endianness怎么用?C# Endianness使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Endianness类属于命名空间,在下文中一共展示了Endianness类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RawEncoder
public RawEncoder(int bufferSize, IMsgSource msgSource, Endianness endianness)
: base(bufferSize, endianness)
{
m_msgSource = msgSource;
NextStep(null, 0, RawMessageReadyState, true);
}
示例2: ReadBytes
public static byte[] ReadBytes(this BinaryReader binaryReader, Int32 count, Endianness endianness)
{
if (endianness == Endianness.Little)
return binaryReader.ReadBytes(count);
return binaryReader.ReadBytes(count).Reverse().ToArray();
}
示例3: UInt24
public UInt24(byte[] bytes, Endianness endianness)
{
if (bytes == null) throw new ArgumentNullException("bytes");
if (bytes.Length != 3) throw new ArgumentException("UInt24 should consist of exactly 3 bytes.", "bytes");
_bytes = ConvertConditional(bytes, endianness);
}
示例4: WriteEndian
public static void WriteEndian(this BinaryWriter BinaryWriter, uint Value, Endianness Endian)
{
BinaryWriter.Write((byte)((Value >> 24) & 0xFF));
BinaryWriter.Write((byte)((Value >> 16) & 0xFF));
BinaryWriter.Write((byte)((Value >> 8) & 0xFF));
BinaryWriter.Write((byte)((Value >> 0) & 0xFF));
}
示例5: EncoderBase
protected EncoderBase(int bufsize, Endianness endian)
{
Endian = endian;
m_buffersize = bufsize;
m_buf = new byte[bufsize];
m_error = false;
}
示例6: ReadInt32
public int ReadInt32(Endianness endianness)
{
int val = base.ReadInt32();
if (endianness == Endianness.LittleEndian) { return val; }
else { return System.Net.IPAddress.NetworkToHostOrder(val); }
}
示例7: SaveImage
public static void SaveImage(this FloatMapImage image, string filename, Endianness endianness)
{
FileStream fs = new FileStream(filename, FileMode.Create);
// write the header
SaveHeader(fs, image, endianness);
// write the image data
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
{
for (int band = 0; band < image.TotalChannelsCount; band++)
{
float intensity = image.Image[x, y, band];
byte[] rawIntensity = BitConverter.GetBytes(intensity);
if (endianness == Endianness.BigEndian)
{
// swap the bytes from little to big endian
SwapFloatEndianness(ref rawIntensity);
}
// write one float
fs.Write(rawIntensity, 0, rawIntensity.Length);
}
}
}
fs.Flush();
fs.Close();
}
示例8: Unpack
public void Unpack(Endianness endian, string path)
{
if (endian == Endianness.big)
UnpackBigEndian(path);
else if(endian == Endianness.little)
UnpackLittleEndian(path);
}
示例9: SpiConnection
public SpiConnection(ProcessorPin clock, ProcessorPin ss, ProcessorPin? miso, ProcessorPin? mosi, Endianness endianness)
{
this.clock = clock;
this.ss = ss;
this.miso = miso;
this.mosi = mosi;
this.endianness = endianness;
driver = GpioConnectionSettings.DefaultDriver;
driver.Allocate(clock, PinDirection.Output);
driver.Write(clock, false);
driver.Allocate(ss, PinDirection.Output);
driver.Write(ss, true);
if (mosi.HasValue)
{
driver.Allocate(mosi.Value, PinDirection.Output);
driver.Write(mosi.Value, false);
}
if (miso.HasValue)
driver.Allocate(miso.Value, PinDirection.Input);
}
示例10: BlenderFileHeaderToken
public BlenderFileHeaderToken(string identifer, int sz, Endianness endianness, string version)
{
Identifier = identifer;
PointerSize = sz;
Endianness = endianness;
Version = version;
}
示例11: ReadSingle
public float ReadSingle(Endianness endianness)
{
if (endianness == Endianness.LittleEndian) { return base.ReadSingle(); }
byte[] b = base.ReadBytes(4);
return BitConverter.ToSingle(b.Reverse().ToArray(), 0);
}
示例12: PutLong
/// <summary>
/// Write the given 64-bit value into the buffer, at the position marked by the offset plus the given index i.
/// </summary>
/// <param name="endian">an Endianness to specify in which order to write the bytes</param>
/// <param name="value">the 64-bit value to write into the byte-array buffer</param>
/// <param name="i">the index position beyond the offset to start writing the bytes</param>
public void PutLong(Endianness endian, long value, int i)
{
if (endian == Endianness.Big)
{
m_innerBuffer[i + Offset] = (byte)(((value) >> 56) & 0xff);
m_innerBuffer[i + Offset + 1] = (byte)(((value) >> 48) & 0xff);
m_innerBuffer[i + Offset + 2] = (byte)(((value) >> 40) & 0xff);
m_innerBuffer[i + Offset + 3] = (byte)(((value) >> 32) & 0xff);
m_innerBuffer[i + Offset + 4] = (byte)(((value) >> 24) & 0xff);
m_innerBuffer[i + Offset + 5] = (byte)(((value) >> 16) & 0xff);
m_innerBuffer[i + Offset + 6] = (byte)(((value) >> 8) & 0xff);
m_innerBuffer[i + Offset + 7] = (byte)(value & 0xff);
}
else
{
m_innerBuffer[i + Offset + 7] = (byte)(((value) >> 56) & 0xff);
m_innerBuffer[i + Offset + 6] = (byte)(((value) >> 48) & 0xff);
m_innerBuffer[i + Offset + 5] = (byte)(((value) >> 40) & 0xff);
m_innerBuffer[i + Offset + 4] = (byte)(((value) >> 32) & 0xff);
m_innerBuffer[i + Offset + 3] = (byte)(((value) >> 24) & 0xff);
m_innerBuffer[i + Offset + 2] = (byte)(((value) >> 16) & 0xff);
m_innerBuffer[i + Offset + 1] = (byte)(((value) >> 8) & 0xff);
m_innerBuffer[i + Offset] = (byte)(value & 0xff);
}
}
示例13: EndianReader
public EndianReader(Stream input, Endianness endianess, Encoding encoding, bool leaveOpen)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}
if (!input.CanRead)
throw new ArgumentException("Can't read from the output stream", nameof(input));
Contract.EndContractBlock();
BaseStream = input;
decoder = encoding.GetDecoder();
maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
var minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char
if (minBufferSize < 16)
minBufferSize = 16;
buffer = new byte[minBufferSize];
// m_charBuffer and m_charBytes will be left null.
// For Encodings that always use 2 bytes per char (or more),
// special case them here to make Read() & Peek() faster.
use2BytesPerChar = encoding is UnicodeEncoding;
this.leaveOpen = leaveOpen;
Endianness = endianess;
resolvedEndianess = EndianessHelper.Resolve(endianess);
Contract.Assert(decoder != null, "[EndianReader.ctor]m_decoder!=null");
}
示例14: RawDecoder
public RawDecoder(int bufferSize, long maxMsgSize, IMsgSink msgSink,
Endianness endianness)
: base(bufferSize, endianness)
{
m_msgSink = msgSink;
m_maxMsgSize = maxMsgSize;
}
示例15: ReadFloat
//THIS IS UNFINISHED BECAUSE I CAN'T TEST IT. TRY IT LATER
public static float ReadFloat(byte[] data, int position, Endianness endian = Endianness.BigEndian)
{
if (data == null || data.Length < position + 4)
throw new Exception();
byte[] bytes = new byte[4];
Array.Copy(data, position, bytes, 0, 4);
bytes = bytes.Reverse().ToArray();
return BitConverter.ToSingle(bytes, 0);
switch (endian)
{
case Endianness.BigEndian:
//Do nothing
break;
case Endianness.LittleEndian:
//Reverse
break;
case Endianness.ByteSwap:
break;
case Endianness.WordSwap:
break;
}
return 0;
}