当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadStructure方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadStructure方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadStructure方法的具体用法?C# BinaryReader.ReadStructure怎么用?C# BinaryReader.ReadStructure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadStructure方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalRead

 private void InternalRead(BinaryReader reader)
 {
     _header = reader.ReadStructure<CVMDirectoryListingHeader>(CVMDirectoryListingHeader.SIZE);
     _subEntries = new CVMDirectoryListingEntry[_header.entryCount];
   
     for (int i = 0; i < _header.entryCount; i++)
     {
         _subEntries[i] = new CVMDirectoryListingEntry(reader, this);
     }
     
     reader.AlignPosition(16);
    
     for (int i = 0; i < _header.entryCount; i++)
     {
         if (i > 1 && _subEntries[i].Flags.HasFlagUnchecked(RecordFlags.DirectoryRecord))
         {
             _subEntries[i].DirectoryListing = new CVMDirectoryListing(reader, _subEntries[i]);
         }
     }
 }
开发者ID:TGEnigma,项目名称:Amicitia,代码行数:20,代码来源:CVMDirectoryListing.cs

示例2: Parse

        /// <summary>
        /// Parses the <see cref="ControlFile"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException">"No EMAX control file name was specified.</exception>
        /// <exception cref="FileNotFoundException">EMAX control file was not found.</exception>
        public void Parse()
        {
            if (string.IsNullOrEmpty(FileName))
                throw new InvalidOperationException("No EMAX control file name was specified.");

            if (!File.Exists(FileName))
                throw new FileNotFoundException(string.Format("EMAX control file {0} not found.", FileName));

            m_parsedSuccesses.Clear();
            m_parsedFailures.Clear();

            byte byteValue;

            using (FileStream stream = File.OpenRead(FileName))
            {
                // Read in header and file structure definitions
                using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    // Read control header
                    Header = reader.ReadStructure<CTL_HEADER>();

                    // Read byte that defines number of analog channels
                    m_configuredAnalogChannels = BinaryCodedDecimal.Decode(Header.id.LowByte());

                    // Read byte that defines data size (i.e., 12 or 16 bits)
                    byteValue = Header.id.HighByte();

                    if (!Enum.IsDefined(typeof(DataSize), byteValue))
                        throw new InvalidOperationException("Invalid EMAX data size code encountered: 0x" + byteValue.ToString("X").PadLeft(2, '0'));

                    DataSize = (DataSize)byteValue;

                    // Create array of file structures
                    List<CTL_FILE_STRUCT> fileStructures = new List<CTL_FILE_STRUCT>();
                    CTL_FILE_STRUCT fileStructure = new CTL_FILE_STRUCT(reader);

                    // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
                    while (fileStructure.type != StructureType.EndOfStructures)
                    {
                        if (fileStructure.type != StructureType.Unknown)
                            fileStructures.Add(fileStructure);

                        fileStructure = new CTL_FILE_STRUCT(reader);
                    }

                    FileStructures = fileStructures.ToArray();
                }

                // Read in actual file structures
                for (int index = 0; index < FileStructures.Length; index++)
                {
                    CTL_FILE_STRUCT fileStructure = FileStructures[index];

                    if (fileStructure.type == StructureType.Unknown)
                        continue;

                    // Set current type
                    m_currentType = fileStructure.type;

                    // Locate structure in the file
                    stream.Position = fileStructure.offset;

                    // Parse the structure type
                    using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))
                    {
                        switch (m_currentType)
                        {
                            case StructureType.SYSTEM_PARAMETERS:
                                AttemptParse(() => SystemParameters = reader.ReadStructure<SYSTEM_PARAMETERS>());
                                break;
                            case StructureType.SYS_SETTINGS:
                                AttemptParse(() => SystemSettings = reader.ReadStructure<SYS_SETTINGS>());
                                break;
                            case StructureType.A_E_RSLTS:
                                AttemptParse(() => AnalogEventResults = new A_E_RSLTS(reader, m_configuredAnalogChannels, SystemParameters.analog_groups));
                                break;
                            case StructureType.ANALOG_GROUP:
                                AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, m_configuredAnalogChannels));
                                break;
                            case StructureType.EVENT_GROUP:
                                AttemptParse(() => EventGroup = reader.ReadStructure<EVENT_GROUP>());
                                break;
                            case StructureType.ANLG_CHNL_NEW:
                                AttemptParse(() =>
                                {
                                    AnalogChannelSettings = new Dictionary<int, ANLG_CHNL_NEW>();
                                    ScalingFactors = new Dictionary<int, double>();
                                    ANLG_CHNL_NEW settings;

                                    uint nextOffset = (index + 1 < FileStructures.Length) ? FileStructures[index + 1].offset : (uint)stream.Length;
                                    uint length = nextOffset - fileStructure.offset;
                                    Func<ANLG_CHNL_NEW> channelFactory;

                                    if (Marshal.SizeOf<ANLG_CHNL_NEW2>() * ConfiguredAnalogChannels <= length)
                                        channelFactory = () => reader.ReadStructure<ANLG_CHNL_NEW2>().ToAnlgChnlNew();
//.........这里部分代码省略.........
开发者ID:rmc00,项目名称:gsf,代码行数:101,代码来源:ControlFile.cs

示例3: SEQUENCE_CHANNELS

        public SEQUENCE_CHANNELS(BinaryReader reader)
        {
            length = reader.ReadInt16();
            channels = new SEQUENCE_CHANNEL[length / Marshal.SizeOf(typeof(SEQUENCE_CHANNEL))];

            for (int i = 0; i < channels.Length; i++)
            {
                channels[i] = reader.ReadStructure<SEQUENCE_CHANNEL>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ControlFileStructures.cs

示例4: FAULT_LOCATIONS

        public FAULT_LOCATIONS(BinaryReader reader)
        {
            length = reader.ReadInt16();
            locations = new FAULT_LOCATION[length / Marshal.SizeOf(typeof(FAULT_LOCATION))];

            for (int i = 0; i < locations.Length; i++)
            {
                locations[i] = reader.ReadStructure<FAULT_LOCATION>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ControlFileStructures.cs

示例5: LINE_NAMES

        public LINE_NAMES(BinaryReader reader)
        {
            length = reader.ReadInt16();
            names = new LINE_NAME[length / Marshal.SizeOf(typeof(LINE_NAME))];

            for (int i = 0; i < names.Length; i++)
            {
                names[i] = reader.ReadStructure<LINE_NAME>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ControlFileStructures.cs

示例6: LINE_CONSTANTS

        public LINE_CONSTANTS(BinaryReader reader)
        {
            length = reader.ReadInt16();
            constants = new LINE_CONSTANT[length / Marshal.SizeOf(typeof(LINE_CONSTANT))];

            for (int i = 0; i < constants.Length; i++)
            {
                constants[i] = reader.ReadStructure<LINE_CONSTANT>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ControlFileStructures.cs

示例7: PHASOR_GROUPS

        public PHASOR_GROUPS(BinaryReader reader)
        {
            length = reader.ReadInt16();
            groups = new PHASOR_GROUP[length / Marshal.SizeOf(typeof(PHASOR_GROUP))];

            for (int i = 0; i < groups.Length; i++)
            {
                groups[i] = reader.ReadStructure<PHASOR_GROUP>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:10,代码来源:ControlFileStructures.cs

示例8: A_E_RSLTS

        public A_E_RSLTS(BinaryReader reader, int channels, int analogGroups)
        {
            sequence_r = reader.ReadInt16();
            flag_r = reader.ReadUInt16();
            offset_r = reader.ReadUInt16();
            channel_r = reader.ReadUInt16();
            mSec_r = reader.ReadUInt16();
            time_fault_r = reader.ReadUInt32();
            rcd_sample_count_r = reader.ReadInt32();

            aer = new A_E_RESULTS[channels * analogGroups];

            for (int i = 0; i < aer.Length; i++)
            {
                aer[i] = reader.ReadStructure<A_E_RESULTS>();
            }
        }
开发者ID:avs009,项目名称:gsf,代码行数:17,代码来源:ControlFileStructures.cs

示例9: Deserialize

        public void Deserialize(BinaryReader from)
        {
            // Bezier File Format :
            //   Header ('BZR ')            | sizeof(uint)
            //   Version (1.1)              | sizeof(uint)
            //   Regular patch count        | sizeof(uint)
            //   Quad patch count           | sizeof(uint)
            //   Triangle patch count       | sizeof(uint)

            this.Header = from.ReadStructure<BezierMesh.BezierHeader>();

            byte[] expectedHeader = {Convert.ToByte(' '), Convert.ToByte('R'), Convert.ToByte('Z'), Convert.ToByte('B')};

            if (BitConverter.IsLittleEndian)
                Array.Reverse(expectedHeader);

            if (Header.Header != BitConverter.ToInt32(expectedHeader,0) || (Header.Version != 0x0100 && Header.Version != 0x0101))
            {
                throw new ArgumentException("Incorrect input header or unsupported file format version");
            }

            //   Part 1.  Precomputed Control Points:
            //     Regular Patches:
            //       Bezier control points        | 16 * regularPatchCount * sizeof(float3)
            //       Texture coordinates          | 16 * regularPatchCount * sizeof(float2)
            //       Normal control points        | 16 * regularPatchCount * sizeof(float3)
            _RegularBezierControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.RegularPatchCount * 16));
            _RegularTextureCoordinates = new List<Vector2>(from.ReadStructure<Vector2>(Header.RegularPatchCount * 16));
            if (Header.Version == 0x0101)
            {
                // Load normals
                _RegularNormals = new List<Vector3>(from.ReadStructure<Vector3>(Header.RegularPatchCount * 16));
            } else
            {
                _RegularNormals = new List<Vector3>();
            }

            //     Quad Patches:
            //       Bezier control points        | 32 * quadPatchCount * sizeof(float3)
            //       Gregory control points       | 20 * quadPatchCount * sizeof(float3)
            //       Pm control points            | 24 * quadPatchCount * sizeof(float3)
            //       Texture coordinates          | 16 * quadPatchCount * sizeof(float2)
            //       Normal control points        | 16 * quadPatchCount * sizeof(float3)
            _QuadBezierControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.QuadPatchCount * 32));
            _QuadGregoryControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.QuadPatchCount * 20));
            _QuadPmControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.QuadPatchCount * 24));
            _QuadTextureCoordinates = new List<Vector2>(from.ReadStructure<Vector2>(Header.QuadPatchCount * 16));
            if (Header.Version == 0x0101)
            {
                // Load normals
                _QuadNormals = new List<Vector3>(from.ReadStructure<Vector3>(Header.QuadPatchCount * 16));
            }
            else
            {
                _QuadNormals = new List<Vector3>();
            }

            //     Triangle Patches:
            //       Gregory control points       | 15 * trianglePatchCount * sizeof(float3)
            //       Pm control points            | 19 * trianglePatchCount * sizeof(float3)
            //       Texture coordinates          | 12 * trianglePatchCount * sizeof(float2)
            _TriGregoryControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.TriPatchCount * 15));
            _TriPmControlPoints = new List<Vector3>(from.ReadStructure<Vector3>(Header.TriPatchCount * 19));
            _TriTextureCoordinates = new List<Vector2>(from.ReadStructure<Vector2>(Header.TriPatchCount * 12));

            //   Part 2. Stencils:
            //     faceTopologyCount              | sizeof(int)
            //     primitiveSize                  | sizeof(int)
            //     Bezier Stencil                 | faceTopologyCount * 32 * m_primitiveSize * sizeof(float)
            //     Gregory Stencil                | faceTopologyCount * 20 * m_primitiveSize * sizeof(float)
            //     regularFaceTopologyIndex       | regularPatchCount * sizeof(uint)
            //     regularVertexIndices           | 16 * regularPatchCount * sizeof(uint)
            //     regularStencilIndices          | 16 * regularPatchCount * sizeof(uint)
            //     quadVertexCount                | quadPatchCount * sizeof(uint)
            //     quadFaceTopologyIndex          | quadPatchCount * sizeof(uint)
            //     quadVertexIndices              | primitiveSize * quadpatchCount * sizeof(uint)
            //     quadStecilIndices              | primitiveSize * quadPatchCount * sizeof(uint)

            FaceTopologyCount = from.ReadInt32();
            PrimitiveSize = from.ReadInt32();

            _BezierStencil = new List<float>(from.ReadStructure<float>(FaceTopologyCount * 32 * PrimitiveSize));
            _GregoryStencil = new List<float>(from.ReadStructure<float>(FaceTopologyCount * 20 * PrimitiveSize));

            _RegularFaceTopologyIndex = new List<int>(from.ReadStructure<int>(Header.RegularPatchCount));
            _RegularVertexIndices = new List<int>(from.ReadStructure<int>(Header.RegularPatchCount * 16));
            _RegularStencilIndices = new List<int>(from.ReadStructure<int>(Header.RegularPatchCount * 16));

            _QuadFaceVertexCount = new List<int>(from.ReadStructure<int>(Header.QuadPatchCount));
            _QuadFaceTopologyIndex = new List<int>(from.ReadStructure<int>(Header.QuadPatchCount));
            _QuadVertexIndices = new List<int>(from.ReadStructure<int>(Header.QuadPatchCount * PrimitiveSize));
            _QuadStencilIndices = new List<int>(from.ReadStructure<int>(Header.QuadPatchCount * PrimitiveSize));

            //   Part 3. Input Mesh Topology:
            //     Vertex count                   | sizeof(uint)
            //     Vertices                       | vertexCount * sizeof(float3)
            //     Tangents/Bitangents            | vertexCount * 2 * sizeof(float3)
            //     Valences                       | vertexCount * sizeof(int)
            //     Texture coordinates            | vertexCount * sizeof(float2)
            //     Max valence                    | sizeof(uint)
//.........这里部分代码省略.........
开发者ID:QamarWaqar,项目名称:Direct3D-Rendering-Cookbook,代码行数:101,代码来源:BezierMesh.cs

示例10: Read

        public void Read(string path)
        {
            if (!File.Exists(path))
            {
                System.Windows.Forms.MessageBox.Show("File not found - " + path, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }

            var header = new FileIntegrityHeader();
            var list = new List<FileIntegrityEntry>();

            using (var reader = new BinaryReader(File.Open(FileIntegrity.FileName, FileMode.Open, FileAccess.Read)))
            {
                header = reader.ReadStructure<FileIntegrityHeader>();

                for (int i = 0; i < header.EntryCount; i++)
                {
                    var entry = new FileIntegrityEntry();
                    entry.FileNameLen = reader.ReadInt16();
                    entry.FileName = new string(reader.ReadChars(entry.FileNameLen));
                    entry.LastModifiedTime = reader.ReadInt64();
                    entry.Size = reader.ReadInt32();
                    entry.Checksum = reader.ReadInt32();

                    list.Add(entry);
                }
            }

            Scan(Environment.CurrentDirectory);

            foreach (var entry in Entries)
            {
                if (list.Contains(entry, new FileIntegrityEntryComparer()))
                {
                    var lentry = list.Find(e => e.FileName == entry.FileName);
                    if (lentry.LastModifiedTime != entry.LastModifiedTime)
                    {
                        System.Windows.Forms.MessageBox.Show("File time missmatch - " + entry.FileName);
                    }
                    if (lentry.Size != entry.Size)
                    {
                        System.Windows.Forms.MessageBox.Show("File size missmatch - " + entry.FileName);
                    }
                    if (lentry.Checksum != entry.Checksum)
                    {
                        System.Windows.Forms.MessageBox.Show("File checksum missmatch - " + entry.FileName);
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("File not found - " + entry.FileName);
                }
            }
        }
开发者ID:MadnessFreak,项目名称:IntegrityChecker,代码行数:54,代码来源:FileIntegrity.cs

示例11: CVMDirectoryListingEntry

 internal CVMDirectoryListingEntry(BinaryReader reader, CVMDirectoryListing originDirList)
 {
     _originDirList = originDirList;
     _header = reader.ReadStructure<DirectoryListingEntryHeader>(DirectoryListingEntryHeader.SIZE);
 }
开发者ID:TGEnigma,项目名称:Amicitia,代码行数:5,代码来源:CVMDirectoryListingEntry.cs


注:本文中的System.IO.BinaryReader.ReadStructure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。