Example #1
0
        /// <summary>
        /// Read array of structs from a reader
        /// </summary>
        /// <param name="reader">Target reader</param>
        /// <param name="count">Count</param>
        /// <typeparam name="T">Struct to read</typeparam>
        /// <returns>Stuct array</returns>
        public static T[] ReadArray <T>(this BinaryReader reader, int count) where T : struct
        {
            if (count == 0)
            {
                return(new T[0]);
            }

            var numBytes = FastStruct <T> .Size * count;

            byte[] result = reader.ReadBytes(numBytes);

            return(FastStruct <T> .ReadArray(result));
        }
Example #2
0
        /// <summary>
        /// Read array of structs from a BinaryReader
        /// </summary>
        /// <param name="reader">Source reader</param>
        /// <typeparam name="T">Struct to read</typeparam>
        /// <returns>Array of read structs</returns>
        public static T[] ReadArray <T>(this BinaryReader reader) where T : struct
        {
            var numBytes = (int)reader.ReadInt64();

            if (numBytes == 0)
            {
                return(new T[0]);
            }

            byte[] result = reader.ReadBytes(numBytes);

            reader.BaseStream.Position += (0 - numBytes) & 0x07;
            return(FastStruct <T> .ReadArray(result));
        }
Example #3
0
 /// <summary>
 /// Write an array of structs to a BinaryWriter
 /// </summary>
 /// <param name="writer">Target write</param>
 /// <param name="struct">Struct array to write</param>
 /// <typeparam name="T">Struct type</typeparam>
 public static void WriteStructArray <T>(this BinaryWriter writer, T[] @struct) where T : struct
 {
     writer.Write(FastStruct <T> .WriteArray(@struct));
 }
Example #4
0
 /// <summary>
 /// Write a struct to a BinaryWriter
 /// </summary>
 /// <param name="writer">Target writer</param>
 /// <param name="struct">Struct instance to write</param>
 /// <typeparam name="T">Struct type</typeparam>
 public static void Write <T>(this BinaryWriter writer, T @struct) where T : struct
 {
     writer.Write(FastStruct <T> .StructureToArray(@struct));
 }
Example #5
0
 /// <summary>
 /// Read struct from a BinaryReader
 /// </summary>
 /// <param name="reader">Source reader</param>
 /// <typeparam name="T">Struct to read</typeparam>
 /// <returns>Read struct</returns>
 public static T Read <T>(this BinaryReader reader) where T : struct
 {
     byte[] result = reader.ReadBytes(FastStruct <T> .Size);
     return(FastStruct <T> .ArrayToStructure(result));
 }