public ulong ReadUInt64(int numBits) { ulong result = FastStruct <ulong> .ArrayToStructure(ref m_array[m_readOffset + (m_readPos >> 3)]) << (64 - numBits - (m_readPos & 7)) >> (64 - numBits); m_readPos += numBits; return(result); }
public uint ReadUInt32(int numBits) { uint result = FastStruct <uint> .ArrayToStructure(ref m_array[m_readOffset + (m_readPos >> 3)]) << (32 - numBits - (m_readPos & 7)) >> (32 - numBits); m_readPos += numBits; return(result); }
public static T[] ReadArray <T>(this BinaryReader reader, int size) where T : struct { int numBytes = Marshal.SizeOf <T>() * size; byte[] result = reader.ReadBytes(numBytes); return(FastStruct <T> .ReadArray(result)); }
public T GetValue <T>() where T : struct { unsafe { fixed(byte *ptr = Value) return(FastStruct <T> .ArrayToStructure(ref ptr[0])); } }
public T Read <T>(MemoryStream ms) where T : struct { int size = FastStruct <T> .Size; byte[] result = new byte[size]; ms.Read(result, 0, size); return(FastStruct <T> .ArrayToStructure(result)); }
public T[] ReadArray <T>(MemoryStream ms, int size) where T : struct { int numBytes = Marshal.SizeOf <T>() * size; byte[] result = new byte[numBytes]; ms.Read(result, 0, numBytes); return(FastStruct <T> .ReadArray(result)); }
public static T[] ReadArray <T>(this BinaryReader reader) where T : struct { int numBytes = (int)reader.ReadInt64(); byte[] result = reader.ReadBytes(numBytes); reader.BaseStream.Position += (0 - numBytes) & 0x07; return(FastStruct <T> .ReadArray(result)); }
public T[] ReadArray <T>(MemoryStream ms) where T : struct { int numBytes = (int)ReadInt64(ms); byte[] result = new byte[numBytes]; ms.Read(result, 0, numBytes); ms.Position += (0 - numBytes) & 0x07; return(FastStruct <T> .ReadArray(result)); }
/// <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]); } int numBytes = FastStruct <T> .Size * count; byte[] result = reader.ReadBytes(numBytes); return(FastStruct <T> .ReadArray(result)); }
public static T Read <T>(this BinaryReader reader) where T : struct { byte[] result = reader.ReadBytes(FastStruct <T> .Size); return(FastStruct <T> .ArrayToStructure(result)); }
public void Parse(byte[] bytes) { Header = FastStruct <Structure> .ArrayToStructure(bytes); }
/// <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)); }
/// <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)); }