Ejemplo n.º 1
0
        /// <summary>
        /// Reads the value from the stream. First the buffer is filled from the stream by the data's size in bytes, then the data is copied.
        /// </summary>
        /// <typeparam name="T">Type of data to read.</typeparam>
        /// <param name="input">Stream to read from.</param>
        /// <returns>The read value.</returns>
        public unsafe T Read <T>(Stream input) where T : struct
        {
            int size = MemoryInterop.SizeOfInline <T>();

            //Fill buffer...validate we read t he expected # of bytes
            if (ReadBytes(input, size) != size)
            {
                return(default(T));
            }

            //Copy data
            return(MemoryInterop.ReadInline <T>((void *)m_pinHandle.AddrOfPinnedObject()));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Computes the size of the struct type.
 /// </summary>
 /// <typeparam name="T">Struct type</typeparam>
 /// <returns>Size of the struct in bytes.</returns>
 public static unsafe int SizeOf <T>() where T : struct
 {
     return(MemoryInterop.SizeOfInline <T>());
 }