/// <summary>Read a <typeparamref name="TEnum"/> value from a stream</summary> /// <param name="s">Stream to read from</param> /// <param name="value">Enum value read from the stream</param> /// <remarks> /// Uses <typeparamref name="TEnum"/>'s underlying <see cref="TypeCode"/> to /// decide how big of a numeric type to read from the stream. /// </remarks> public static void Read(IO.EndianReader s, out TEnum value) { Contract.Requires(s != null); ulong stream_value; switch (Reflection.EnumUtil <TEnum> .UnderlyingTypeCode) { case TypeCode.Byte: case TypeCode.SByte: stream_value = s.ReadByte(); break; case TypeCode.Int16: case TypeCode.UInt16: stream_value = s.ReadUInt16(); break; case TypeCode.Int32: case TypeCode.UInt32: stream_value = s.ReadUInt32(); break; case TypeCode.Int64: case TypeCode.UInt64: stream_value = s.ReadUInt64(); break; default: throw new Debug.UnreachableException(); } value = Reflection.EnumValue <TEnum> .FromUInt64(stream_value); }
public static void Read(this IO.EndianReader s, out Guid value, bool respectEndian = true) { if (respectEndian) { uint a = s.ReadUInt32(); ushort b = s.ReadUInt16(); ushort c = s.ReadUInt16(); byte d = s.ReadByte(); byte e = s.ReadByte(); byte f = s.ReadByte(); byte g = s.ReadByte(); byte h = s.ReadByte(); byte i = s.ReadByte(); byte j = s.ReadByte(); byte k = s.ReadByte(); value = new Guid(a, b, c, d, e, f, g, h, i, j, k); } else { value = new Guid(s.ReadBytes(16)); } }
public static void Read(this IO.EndianReader s, out uint value) => value = s.ReadUInt32();