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


C# BinaryReader.ReadFixedString方法代码示例

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


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

示例1: Read

    public static Tileset Read(BinaryReader reader)
    {
      var name = reader.ReadFixedString();
      var imagePath = reader.ReadFixedString();

      var tileset = new Tileset(name, imagePath)
      {
        Margin = reader.ReadInt32(),
        Spacing = reader.ReadInt32(),
        TileCount = reader.ReadInt32(),
        TileWidth = reader.ReadInt32(),
        TileHeight = reader.ReadInt32(),
        FirstGid = reader.ReadInt32()
      };

      var propertyCount = reader.ReadInt32();

      for (var i = 0; i < propertyCount; i++)
        tileset.PropertyEntries.Add(TilePropertyEntry.Read(reader));

      return tileset;
    }
开发者ID:wow4all,项目名称:Walker,代码行数:22,代码来源:Map.cs

示例2: FormatException

 void ISerializable.Deserialize(BinaryReader reader)
 {
     if (reader.ReadUInt32() != Magic)
         throw new FormatException();
     this.Command = reader.ReadFixedString(12);
     uint length = reader.ReadUInt32();
     if (length > 0x02000000)
         throw new FormatException();
     this.Checksum = reader.ReadUInt32();
     this.Payload = reader.ReadBytes((int)length);
     if (Payload.Checksum() != Checksum)
         throw new FormatException();
 }
开发者ID:peer2peer,项目名称:AntShares,代码行数:13,代码来源:Message.cs

示例3: DeserializeFromStreamAsync

 public static async Task<Message> DeserializeFromStreamAsync(Stream stream)
 {
     byte[] buffer = new byte[sizeof(uint) + 12 + sizeof(uint) + sizeof(uint)];
     await stream.ReadAsync(buffer, 0, buffer.Length);
     Message message = new Message();
     using (MemoryStream ms = new MemoryStream(buffer, false))
     using (BinaryReader reader = new BinaryReader(ms))
     {
         if (reader.ReadUInt32() != Magic)
             throw new FormatException();
         message.Command = reader.ReadFixedString(12);
         uint length = reader.ReadUInt32();
         if (length > 0x02000000)
             throw new FormatException();
         message.Checksum = reader.ReadUInt32();
         message.Payload = new byte[length];
     }
     await stream.ReadAsync(message.Payload, 0, message.Payload.Length);
     return message;
 }
开发者ID:peer2peer,项目名称:AntShares,代码行数:20,代码来源:Message.cs

示例4: ReadTableOfContents

        void ReadTableOfContents()
        {
            Stream stream = null;
              try
              {
            stream = mappedFile.CreateViewStream(0, 0, MemoryMappedFileAccess.Read);
            using (var reader = new BinaryReader(stream, Encoding.ASCII))
            {
              stream = null;
              var entryCount = reader.ReadUInt32() - 1;

              for (int i = 0; i < entryCount; i++)
              {
            var index = i;
            var startAddress = reader.ReadUInt32();
            var name = reader.ReadFixedString(NameLength).Trim();
            var size = reader.ReadInt32() - startAddress;

            reader.BaseStream.Position -= sizeof(uint);

            var entry = new FileArchiveEntry
            {
              Index = index,
              Name = name,
              Offset = startAddress,
              Size = size
            };

            entries[name] = entry;
              }
            }
              }
              finally { stream?.Dispose(); }
        }
开发者ID:ewrogers,项目名称:SleepHunter4,代码行数:34,代码来源:FileArchive.cs

示例5: DecodeMessage

        public static Message DecodeMessage(BinaryReader reader)
        {
            var magic = reader.ReadUInt32();
            var command = reader.ReadFixedString(12);
            var payloadSize = reader.ReadUInt32();
            var payloadChecksum = reader.ReadUInt32();
            var payload = reader.ReadExactly(payloadSize.ToIntChecked()).ToImmutableArray();

            return new Message
            (
                Magic: magic,
                Command: command,
                PayloadSize: payloadSize,
                PayloadChecksum: payloadChecksum,
                Payload: payload
            );
        }
开发者ID:cole2295,项目名称:BitSharp,代码行数:17,代码来源:NodeEncoder.cs

示例6: ReadMODS

        static void ReadMODS(BinaryReader br, WMORoot wmo)
        {
            wmo.DoodadSets = new DoodadSet[wmo.Header.DoodadSetCount];

            for (int i = 0; i < wmo.Header.DoodadSetCount; i++)
            {
                var d = new DoodadSet
                {
                    SetName = br.ReadFixedString(20),
                    FirstInstanceIndex = br.ReadUInt32(),
                    InstanceCount = br.ReadUInt32()
                };
                br.ReadInt32(); // padding

                wmo.DoodadSets[i] = d;
            }
        }
开发者ID:remixod,项目名称:netServer,代码行数:17,代码来源:WMOReader.cs

示例7: WireDecodeMessage

        private Message WireDecodeMessage(UInt32 magic, Stream stream)
        {
            byte[] payload;
            Message message;
            using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true))
            {
                var command = reader.ReadFixedString(12);
                var payloadSize = reader.ReadUInt32();
                var payloadChecksum = reader.ReadUInt32();

                payload = reader.ReadBytes(payloadSize.ToIntChecked());

                if (!Messaging.VerifyPayloadChecksum(payloadChecksum, payload))
                    throw new Exception($"Checksum failed for {command}");

                message = new Message
                (
                    Magic: magic,
                    Command: command,
                    PayloadSize: payloadSize,
                    PayloadChecksum: payloadChecksum,
                    Payload: payload.ToImmutableArray()
                );
            }

            switch (message.Command)
            {
                case "addr":
                    {
                        var addressPayload = NodeEncoder.DecodeAddressPayload(payload);

                        this.OnReceivedAddresses?.Invoke(addressPayload.NetworkAddresses);
                    }
                    break;

                case "alert":
                    {
                        var alertPayload = NodeEncoder.DecodeAlertPayload(payload);
                    }
                    break;

                case "block":
                    {
                        var block = DataEncoder.DecodeBlock(payload);

                        this.OnBlock?.Invoke(this.owner, block);
                    }
                    break;

                case "getblocks":
                    {
                        var getBlocksPayload = NodeEncoder.DecodeGetBlocksPayload(payload);

                        this.OnGetBlocks?.Invoke(getBlocksPayload);
                    }
                    break;

                case "getheaders":
                    {
                        var getHeadersPayload = NodeEncoder.DecodeGetBlocksPayload(payload);

                        this.OnGetHeaders?.Invoke(getHeadersPayload);
                    }
                    break;

                case "getdata":
                    {
                        var invPayload = NodeEncoder.DecodeInventoryPayload(payload);

                        this.OnGetData?.Invoke(invPayload);
                    }
                    break;

                case "headers":
                    {
                        var blockHeaders = ImmutableList.CreateBuilder<BlockHeader>();

                        using (var headerStream = new MemoryStream(payload))
                        using (var reader = new BinaryReader(headerStream))
                        {
                            var headerCount = reader.ReadVarInt().ToIntChecked();

                            for (var i = 0; i < headerCount; i++)
                            {
                                var blockHeader = DataEncoder.DecodeBlockHeader(reader);
                                //TODO wiki says this is a byte and a var int, which is it?
                                var txCount = reader.ReadVarInt();

                                blockHeaders.Add(blockHeader);
                            }
                        }

                        this.OnBlockHeaders?.Invoke(this.owner, blockHeaders.ToImmutable());
                    }
                    break;

                case "inv":
                    {
                        var invPayload = NodeEncoder.DecodeInventoryPayload(payload);

//.........这里部分代码省略.........
开发者ID:ArsenShnurkov,项目名称:BitSharp,代码行数:101,代码来源:RemoteReceiver.cs

示例8: DecodeMessage

        public static Message DecodeMessage(Stream stream)
        {
            using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true))
            {
                var magic = reader.Read4Bytes();
                var command = reader.ReadFixedString(12);
                var payloadSize = reader.Read4Bytes();
                var payloadChecksum = reader.Read4Bytes();
                var payload = reader.ReadBytes(payloadSize.ToIntChecked()).ToImmutableArray();

                return new Message
                (
                    Magic: magic,
                    Command: command,
                    PayloadSize: payloadSize,
                    PayloadChecksum: payloadChecksum,
                    Payload: payload
                );
            }
        }
开发者ID:knocte,项目名称:BitSharp,代码行数:20,代码来源:NetworkEncoder.cs

示例9: MapStream

        public MapStream(string filename)
            : base(filename, FileMode.Open, FileAccess.Read, FileShare.Read)
        {
            this.MemoryBlocks = new MemoryMappedAddress[2];
            //HEADER
            BinaryReader bin = new BinaryReader(this, Encoding.UTF8);

            this.Lock(0, 2048);
            this.Seek(0, SeekOrigin.Begin);
            if (bin.ReadTagClass() != (TagClass)"head")
                throw new InvalidDataException("Not a halo-map file");

            //this.Seek(36, SeekOrigin.Begin);
            //var version = bin.ReadInt32();
            //switch (version)
            //{
            //    case 0:
            //        BuildVersion = Version.XBOX_RETAIL;
            //        break;
            //    case -1:
            //        BuildVersion = Version.PC_RETAIL;
            //        break;
            //    default:
            //}
            BuildVersion = Version.PC_RETAIL;
            this.Seek(16, SeekOrigin.Begin);

            int indexAddress = bin.ReadInt32();
            int indexLength = bin.ReadInt32();
            int tagCacheLength = bin.ReadInt32();

            if (BuildVersion == Version.PC_RETAIL)
                this.Seek(12, SeekOrigin.Current);

            this.Seek(332, SeekOrigin.Current);

            int stringTableLength = bin.ReadInt32();
            this.Seek(4, SeekOrigin.Current);
            int stringTableAddress = bin.ReadInt32();

            this.Seek(36, SeekOrigin.Current);

            MapName = bin.ReadFixedString(32);

            this.Seek(4, SeekOrigin.Current);

            Scenario = bin.ReadFixedString(256);

            this.Seek(4, SeekOrigin.Current);
            int pathsCount = bin.ReadInt32();
            int pathsTableAddress = bin.ReadInt32();
            int pathsTableLength = bin.ReadInt32();

            this.Unlock(0, 2048);

            this.Seek(pathsTableAddress, SeekOrigin.Begin);
            var Paths = Encoding.UTF8.GetString(bin.ReadBytes(pathsTableLength - 1)).Split(char.MinValue);

            //STRINGS

            this.Seek(stringTableAddress, SeekOrigin.Begin);
            Strings = Encoding.UTF8.GetString(bin.ReadBytes(stringTableLength - 1)).Split(char.MinValue);

            //  INDEX
            /*
             *  Vista doesn't use memory addresses for the following address-values. (they are instead 0-based from the index-address)
             *
             *  0x00    Address to Classes array
             *  0x04    Classes array length
             *  0x08    Address to Tags array
             *  0x0C    Scenario        tag_id
             *  0x10    Match-Globals   tag_id
             *  0x14    ~
             *  0x18    Tags array length
             *  0xC0    'sgat'          four_cc
             *
             *  */
            this.Seek(indexAddress, SeekOrigin.Begin);
            int tagClassTableVirtualAddress = bin.ReadInt32();
            this.IndexVirtualAddress = tagClassTableVirtualAddress - 32;
            this.Seek(4, SeekOrigin.Current);
            int tagDatumTableVirtualAddress = bin.ReadInt32();
            var ScenarioID = bin.ReadTagID();
            var GlobalsID = bin.ReadTagID();
            int tagDatumTableOffset = tagDatumTableVirtualAddress - tagClassTableVirtualAddress;
            this.Seek(4, SeekOrigin.Current);
            int tagDatumCount = bin.ReadInt32();

            this.Seek(4 + tagDatumTableOffset, SeekOrigin.Current);
            Tags = new Tag[tagDatumCount];
            for (int i = 0; i < tagDatumCount; i++)
            {
                Tags[i] = new Tag()
                {
                    Type = bin.ReadTagType(),
                    Identifier = bin.ReadInt32(),
                    VirtualAddress = bin.ReadInt32(),
                    Length = bin.ReadInt32()
                };
                if (i == 0)
//.........这里部分代码省略.........
开发者ID:jacksoncougar,项目名称:moonfish,代码行数:101,代码来源:MapStream.cs

示例10: WireDecodeMessage

        private Message WireDecodeMessage(UInt32 magic, Stream stream)
        {
            byte[] payload;
            Message message;
            using (var reader = new BinaryReader(stream, Encoding.ASCII, leaveOpen: true))
            {
                var command = reader.ReadFixedString(12);
                var payloadSize = reader.Read4Bytes();
                var payloadChecksum = reader.Read4Bytes();

                payload = reader.ReadBytes(payloadSize.ToIntChecked());

                if (!Messaging.VerifyPayloadChecksum(payloadChecksum, payload))
                    throw new Exception(string.Format("Checksum failed for {0}", command));

                message = new Message
                (
                    Magic: magic,
                    Command: command,
                    PayloadSize: payloadSize,
                    PayloadChecksum: payloadChecksum,
                    Payload: payload.ToImmutableArray()
                );
            }

            switch (message.Command)
            {
                case "addr":
                    {
                        var addressPayload = NetworkEncoder.DecodeAddressPayload(payload.ToMemoryStream());

                        var handler = this.OnReceivedAddresses;
                        if (handler != null)
                            handler(addressPayload.NetworkAddresses);
                    }
                    break;

                case "alert":
                    {
                        var alertPayload = NetworkEncoder.DecodeAlertPayload(payload.ToMemoryStream());
                    }
                    break;

                case "block":
                    {
                        var block = NetworkEncoder.DecodeBlock(payload.ToMemoryStream());

                        var handler = this.OnBlock;
                        if (handler != null)
                            handler(block);
                    }
                    break;

                case "getblocks":
                    {
                        var getBlocksPayload = NetworkEncoder.DecodeGetBlocksPayload(payload.ToMemoryStream());

                        var handler = this.OnGetBlocks;
                        if (handler != null)
                            handler(getBlocksPayload);
                    }
                    break;

                case "getheaders":
                    {
                        var getHeadersPayload = NetworkEncoder.DecodeGetBlocksPayload(payload.ToMemoryStream());

                        var handler = this.OnGetHeaders;
                        if (handler != null)
                            handler(getHeadersPayload);
                    }
                    break;

                case "headers":
                    {
                        var headerStream = payload.ToMemoryStream();
                        using (var reader = new BinaryReader(headerStream))
                        {
                            var headerCount = reader.ReadVarInt().ToIntChecked();

                            for (var i = 0; i < headerCount; i++)
                            {
                                var blockHeader = NetworkEncoder.DecodeBlockHeader(headerStream);
                                //TODO wiki says this is a byte and a var int, which is it?
                                var txCount = reader.ReadVarInt();

                                var handler = this.OnBlockHeader;
                                if (handler != null)
                                    handler(blockHeader);
                            }
                        }
                    }
                    break;

                case "inv":
                    {
                        var invPayload = NetworkEncoder.DecodeInventoryPayload(payload.ToMemoryStream());

                        var handler = this.OnInventoryVectors;
                        if (handler != null)
//.........这里部分代码省略.........
开发者ID:holinov,项目名称:BitSharp,代码行数:101,代码来源:RemoteReceiver.cs


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