Beispiel #1
0
 public static void Read(this IO.EndianReader s, out Vector2f v)
 {
     v = new Vector2f(
         s.ReadSingle(),                 // I
         s.ReadSingle()                  // J
         );
 }
Beispiel #2
0
        /// <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);
        }
Beispiel #3
0
 public static void Read(this IO.EndianReader s, out Plane3f v)
 {
     v = new Plane3f(
         s.ReadSingle(),                 // X
         s.ReadSingle(),                 // Y
         s.ReadSingle(),                 // Z
         s.ReadSingle()                  // D
         );
 }
Beispiel #4
0
 public static void Read(this IO.EndianReader s, out QuaternionF v)
 {
     v = new QuaternionF(
         s.ReadSingle(),                 // I
         s.ReadSingle(),                 // J
         s.ReadSingle(),                 // K
         s.ReadSingle()                  // W
         );
 }
Beispiel #5
0
 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));
     }
 }
Beispiel #6
0
 /// <summary>
 /// Read a serializable value type from an endian stream
 /// </summary>
 /// <typeparam name="T">Value type implementing <see cref="IO.IEndianStreamable"/></typeparam>
 /// <param name="s"></param>
 /// <param name="value"></param>
 public static void ReadObject <T>(this IO.EndianReader s, out T value)
     where T : struct, IO.IEndianStreamable
 {
     value = new T();
     value.Read(s);
 }
Beispiel #7
0
 // no Write(length) override
 public static void Read(this IO.EndianReader s, out string value, Text.StringStorageEncoding encoding)
 {
     value = s.ReadString(encoding);
 }
Beispiel #8
0
 // no Write(length) override
 public static void Read(this IO.EndianReader s, out string value, Memory.Strings.StringStorage storage)
 {
     value = s.ReadString(storage);
 }
Beispiel #9
0
 public static void Read(this IO.EndianReader s, out string value)
 {
     value = s.ReadString();
 }
Beispiel #10
0
 public static int Read(this byte[] value, IO.EndianReader s, int index, int count)
 {
     return(s.Read(value, index, count));
 }
Beispiel #11
0
 public static void Read(this IO.EndianReader s, out int value) => value = s.ReadInt32();
Beispiel #12
0
 public static void Read(this IO.EndianReader s, out char value) => value = s.ReadChar();
Beispiel #13
0
 public static void Read(this IO.EndianReader s, out sbyte value) => value = s.ReadSByte();
Beispiel #14
0
 public static void Read(this IO.EndianReader s, out double value) => value = s.ReadDouble();
Beispiel #15
0
 public static void Read(this IO.EndianReader s, out float value) => value = s.ReadSingle();
Beispiel #16
0
 public static void Read(this IO.EndianReader s, out long value) => value = s.ReadInt64();
Beispiel #17
0
 /// <summary>
 /// Read a serializable object from an endian stream
 /// </summary>
 /// <typeparam name="T">Reference type implementing <see cref="IO.IEndianStreamable"/></typeparam>
 /// <param name="s"></param>
 /// <param name="theObj"></param>
 public static void ReadObject <T>(this IO.EndianReader s, T theObj)
     where T : class, IO.IEndianStreamable
 {
     theObj.Read(s);
 }
Beispiel #18
0
 public static int Read(this byte[] value, IO.EndianReader s)
 {
     return(s.Read(value, 0, value.Length));
 }
Beispiel #19
0
 public static void Read(this IO.EndianReader s, out bool value) => value = s.ReadBoolean();
Beispiel #20
0
 public static void Read(this IO.EndianReader s, out short value) => value = s.ReadInt16();