Endian identification support for the current platform and streams. Supports conversion of data between Endian settings. Note: this class still assumes that bit orderings are the same regardless of byte Endian configurations.
Exemplo n.º 1
0
		static Endian()
		{
			Little = new Endian();
			Big = new Endian();
			Native = BitConverter.IsLittleEndian ? Little : Big;
			NonNative = BitConverter.IsLittleEndian ? Big : Little;
		}
Exemplo n.º 2
0
		/// <summary>
		///     Creates a BinaryWriter to write to the stream managed by <paramref name="writer" />
		///     using the provided Endian setting.  <paramref name="marker" /> is written to the
		///     stream to mark the Endian setting used.
		/// </summary>
		public static BinaryWriter WriteEndianMarker(this BinaryWriter writer, Endian endian, uint marker)
		{
			var result = writer;

			if (endian != Endian.Native)
			{
				var endianWriter = new EndianWriter(writer) { Endian = endian };

				result = endianWriter;
			}

			writer.Write(marker);

			return result;
		}
Exemplo n.º 3
0
		/// <summary>
		///     Creates a converter for changing data from the current
		///     Endian setting to the target Endian setting.
		/// </summary>
		public EndianConverter To(Endian target)
		{
			return EndianConverter.Create(this != target);
		}