Exemplo n.º 1
0
 /// <summary>
 /// Read a layout model
 /// </summary>
 /// <typeparam name="T">The Layout Model value Type</typeparam>
 /// <param name="position">The position in the file at which to begin reading
 /// relative to the current position in the file. Default is 0</param>
 /// <param name="model">The structure to contain the read data</param>
 public void ReadLayout <TLayoutType>(LayoutModel <TLayoutType> model, long position)
     where TLayoutType : struct
 {
     if (this.Accessor != null)
     {
         TLayoutType fileData;
         this.Accessor.Read <TLayoutType>(position, out fileData);
         model.SetData(fileData);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Peek ahead bytes but do not chnage the seek pointer in sequential access
        /// </summary>
        /// <param name="position">The position in the file at which to begin reading
        /// relative to the current position in the file. Default is 0</param>
        /// <param name="count">The number of bytes to read. Default 1.</param>
        /// <returns>A byte array</returns>
        public LayoutModel <TLayoutType> PeekStructure <TLayoutType>(int count = 1, long position = 0)
            where TLayoutType : struct
        {
            LayoutModel <TLayoutType> model = new LayoutModel <TLayoutType>();

            using (MemoryMappedViewAccessor tempPeek = this.MemoryFile.CreateViewAccessor(position,
                                                                                          count, MemoryMappedFileAccess.Read))
            {
                TLayoutType fileData;
                tempPeek.Read(position, out fileData);
                model.SetData(fileData);
            }

            return(model);
        }
Exemplo n.º 3
0
        private static void ReadLayoutHelper <TLayoutType>(MemoryMappedViewStream viewStream
                                                           , LayoutModel <TLayoutType> model
                                                           , long position = 0)
            where TLayoutType : struct
        {
            if (viewStream != null)
            {
                // Seek Position from current
                viewStream.Seek(position, System.IO.SeekOrigin.Current);

                byte[] bytes = ReadBytes(viewStream, (int)LayoutModel <TLayoutType> .DataSize, position);

                GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                model.SetData(Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(TLayoutType)));
                handle.Free();
            }
        }