C# BinaryReader.ReadUInt32的代码示例

通过代码示例来学习C# BinaryReader.ReadUInt32方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


BinaryReader.ReadUInt32是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的BinaryReader.ReadUInt32() 已经帮大家高亮显示了,大家可以重点学习BinaryReader.ReadUInt32() 方法的写法,从而快速掌握该方法的应用。

BinaryReader.ReadUInt32的代码示例1 - ConvertH3D()

    
        private void ConvertH3D(System.IO.Stream stream)
        {
            CanSave = true;

            System.IO.BinaryReader Reader = new System.IO.BinaryReader(stream);
            using (FileReader reader = new FileReader(stream, true))
            {
                uint magicNumber = reader.ReadUInt32();

                switch (magicNumber)
                {
                    case 0x15122117:
                        FormatType = FileFormatType.GFModel;
                        H3DFile = new H3D();
                        H3DFile.Models.Add(new SPICA.Formats.GFL2.Model.GFModel(Reader, "Model").ToH3DModel());
                        break;
                }

                string mbnPath = FilePath.Replace("bch", "mbn");

                if (reader.CheckSignature(3, "BCH"))
                {
                    H3DFile = H3D.Open(stream.ToBytes());
                    FormatType = FileFormatType.BCH;
                    return;
                }
                else if (reader.CheckSignature(4, "CGFX"))
                {
                    H3DFile = SPICA.Formats.CtrGfx.Gfx.Open(stream);
                    FormatType = FileFormatType.BCRES;
                }
                else if (GFPackage.IsValidPackage(stream))
                {
                    GFPackage.Header PackHeader = GFPackage.GetPackageHeader(stream);
                    switch (PackHeader.Magic)
                    {
                        case "PC": H3DFile = GFPkmnModel.OpenAsH3D(stream, PackHeader, null); break;
                    }
                }
                else  if (System.IO.File.Exists(mbnPath))
                {
                    var ModelBinary = new SPICA.Formats.ModelBinary.MBn(new System.IO.BinaryReader(
                        System.IO.File.OpenRead(mbnPath)), H3DFile);

                    H3DFile = ModelBinary.ToH3D();
                    FormatType = FileFormatType.MBN;
                }
                else
                    H3DFile = H3D.Open(stream.ToBytes());
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:52,代码来源:BCH.cs

在ConvertH3D()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例2 - InitializeHashCache()

    using System.IO;

        public static void InitializeHashCache()
        {
            HashBinaryPath = Path.Combine(Runtime.ExecutableDir, "Hashes", "GFPAKHashCache.bin");
            string HashExtraPath = Path.Combine(Runtime.ExecutableDir, "Hashes", "GFPAK.txt");

            bool NeedsBaseCacheRebuild = true;
            CurrentVersionHash = GetToolboxVersionHash();

            if (File.Exists(HashBinaryPath))
            {
                using (BinaryReader Reader = new BinaryReader(new FileStream(HashBinaryPath, FileMode.Open)))
                {
                    ulong CacheVersionHash = Reader.ReadUInt64();
                    NeedsBaseCacheRebuild = CacheVersionHash != CurrentVersionHash;
                    uint Count = Reader.ReadUInt32();
                    for (uint HashIndex = 0; HashIndex < Count; HashIndex++)
                    {
                        ulong HashCode = Reader.ReadUInt64();
                        string HashName = Reader.ReadString();
                        PutHash(HashCode, HashName);
                    }
                }
            }

            if (NeedsBaseCacheRebuild)
            {
                GenerateBaseHashList();
            }

            if (File.Exists(HashExtraPath))
            {
                string[] UserHashLines = File.ReadAllLines(HashExtraPath);
                foreach (string Line in UserHashLines){
                    PutHash(Line);
                }
            }

            WriteCache();
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:41,代码来源:GFPAKHashCache.cs

在InitializeHashCache()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例3 - DecompressMeshCodec()

    using System.IO;

        public static byte[] DecompressMeshCodec(Stream stream)
        {
            using (var reader = new BinaryReader(stream))
            {
                reader.ReadUInt32(); //Magic
                reader.ReadUInt32(); //Version 1.1.0.0
                var flags = reader.ReadInt32();
                var decompressed_size = (flags >> 5) << (flags & 0xf);

                reader.BaseStream.Seek(0xC, SeekOrigin.Begin);
                byte[] src = reader.ReadBytes((int)reader.BaseStream.Length - 0xC);
               return Decompress(src, (uint)decompressed_size);
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:16,代码来源:MeshCodec.cs

在DecompressMeshCodec()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例4 - ReadAsync()

    using System.IO;

        /// 
        /// Read a Request from the given stream.
        /// 
        /// The total request size must be less than 1MB.
        /// 
        /// null if the Request was too large, the Request otherwise.
        public static async Task ReadAsync(Stream inStream, CancellationToken cancellationToken)
        {
            // Read the length of the request
            var lengthBuffer = new byte[4];
            ServerLogger.Log("Reading length of request");
            await ServerProtocol.ReadAllAsync(inStream, lengthBuffer, 4, cancellationToken).ConfigureAwait(false);
            var length = BitConverter.ToInt32(lengthBuffer, 0);

            // Back out if the request is > 1MB
            if (length > 0x100000)
            {
                ServerLogger.Log("Request is over 1MB in length, cancelling read.");
                return null;
            }

            cancellationToken.ThrowIfCancellationRequested();

            // Read the full request
            var requestBuffer = new byte[length];
            await ServerProtocol.ReadAllAsync(inStream, requestBuffer, length, cancellationToken).ConfigureAwait(false);

            cancellationToken.ThrowIfCancellationRequested();

            ServerLogger.Log("Parsing request");
            // Parse the request into the Request data structure.
            using (var reader = new BinaryReader(new MemoryStream(requestBuffer), Encoding.Unicode))
            {
                var protocolVersion = reader.ReadUInt32();
                var argumentCount = reader.ReadUInt32();

                var argumentsBuilder = new List((int)argumentCount);

                for (var i = 0; i < argumentCount; i++)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    argumentsBuilder.Add(RequestArgument.ReadFromBinaryReader(reader));
                }

                return new ServerRequest(protocolVersion, argumentsBuilder);
            }
        }
    

开发者ID:aspnet,项目名称:Razor,代码行数:49,代码来源:ServerRequest.cs

在ReadAsync()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例5 - ReadAttributeValue()

    using System.IO;
        //internal static object ReadPrimativTypeValue( BinaryReader reader , DCILElementType type , out bool isPrimativeType )
        //{
        //    switch (type)
        //    {
        //        case DCILElementType.Boolean: isPrimativeType = true; return reader.ReadByte() == 1;
        //        case DCILElementType.I1: isPrimativeType = true; return (sbyte)reader.ReadByte();
        //        case DCILElementType.U1: isPrimativeType = true; return reader.ReadByte();
        //        case DCILElementType.Char: isPrimativeType = true; return (char)reader.ReadInt16();
        //        case DCILElementType.I2: isPrimativeType = true; return reader.ReadInt16();
        //        case DCILElementType.U2: isPrimativeType = true; return reader.ReadUInt16();
        //        case DCILElementType.I4: isPrimativeType = true; return reader.ReadInt32();
        //        case DCILElementType.U4: isPrimativeType = true; return reader.ReadUInt32();
        //        case DCILElementType.I8: isPrimativeType = true; return reader.ReadInt64();
        //        case DCILElementType.U8: isPrimativeType = true; return reader.ReadUInt64();
        //        case DCILElementType.R4: isPrimativeType = true; return reader.ReadSingle();
        //        case DCILElementType.R8: isPrimativeType = true; return reader.ReadDouble();
        //        case DCILElementType.String: isPrimativeType = true; return ReadUTF8String(reader);
        //        case DCILElementType.Type: isPrimativeType = true; return ReadUTF8String(reader);
        //        default:
        //            isPrimativeType = false;
        //            return null;
        //    }
        //}
        protected static object ReadAttributeValue(ReadCustomAttributeValueArgs args, DCILElementType type)
        {
            switch (type)
            {
                case DCILElementType.Boolean: return args.Reader.ReadByte() == 1;
                case DCILElementType.I1: return (sbyte)args.Reader.ReadByte();
                case DCILElementType.U1: return args.Reader.ReadByte();
                case DCILElementType.Char: return (char)args.Reader.ReadInt16();
                case DCILElementType.I2: return args.Reader.ReadInt16();
                case DCILElementType.U2: return args.Reader.ReadUInt16();
                case DCILElementType.I4: return args.Reader.ReadInt32();
                case DCILElementType.U4: return args.Reader.ReadUInt32();
                case DCILElementType.I8: return args.Reader.ReadInt64();
                case DCILElementType.U8: return args.Reader.ReadUInt64();
                case DCILElementType.R4: return args.Reader.ReadSingle();
                case DCILElementType.R8: return args.Reader.ReadDouble();
                case DCILElementType.String: return DCUtils.GetStringUseTable( ReadUTF8String(args.Reader));
                case DCILElementType.Enum:
                    return args.Reader.ReadInt32();
                case DCILElementType.Type:
                    return new TypeRefInfo(args);
                case DCILElementType.Object:
                    return new PackageValueInfo(args);
                default:
                    throw new NotSupportedException(type.ToString());
            }
            return null;
        }
    

开发者ID:dcsoft-yyf,项目名称:JIEJIE.NET,代码行数:52,代码来源:DCILCustomAttributeValue.cs

在ReadAttributeValue()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例6 - RestoreProgramData()

    using System.IO;
		public static byte[] RestoreProgramData(BinaryReader reader, Version version, ref ShaderSubProgram shaderSubProgram)
		{
			using (MemoryStream dest = new MemoryStream())
			{
				using (BinaryWriter writer = new BinaryWriter(dest))
				{
					uint baseOffset = (uint)reader.BaseStream.Position;
					byte[] magicBytes = reader.ReadBytes(4);
					byte[] checksum = reader.ReadBytes(16);
					uint unknown0 = reader.ReadUInt32();
					uint totalSize = reader.ReadUInt32();
					uint chunkCount = reader.ReadUInt32();
					List chunkOffsets = new List();
					for (int i = 0; i < chunkCount; i++)
					{
						chunkOffsets.Add(reader.ReadUInt32());
					}
					uint bodyOffset = (uint)reader.BaseStream.Position;
					// Check if shader already has resource chunk
					foreach (uint chunkOffset in chunkOffsets)
					{
						reader.BaseStream.Position = chunkOffset + baseOffset;
						uint fourCc = reader.ReadUInt32();
						if (fourCc == RDEFFourCC)
						{
							reader.BaseStream.Position = baseOffset;
							byte[] original = reader.ReadBytes((int)reader.BaseStream.Length);
							return original;
						}
					}
					reader.BaseStream.Position = bodyOffset;
					byte[] resourceChunkData = GetResourceChunk(version, ref shaderSubProgram);
					//Adjust for new chunk
					totalSize += (uint)resourceChunkData.Length;
					for (int i = 0; i < chunkCount; i++)
					{
						chunkOffsets[i] += (uint)resourceChunkData.Length + 4;
					}
					chunkOffsets.Insert(0, bodyOffset - baseOffset + 4);
					chunkCount += 1;
					totalSize += (uint)resourceChunkData.Length;

					writer.Write(magicBytes);
					writer.Write(checksum);
					writer.Write(unknown0);
					writer.Write(totalSize);
					writer.Write(chunkCount);
					foreach (uint chunkOffset in chunkOffsets)
					{
						writer.Write(chunkOffset);
					}
					writer.Write(resourceChunkData);
					byte[] rest = reader.ReadBytes((int)reader.BaseStream.Length - (int)reader.BaseStream.Position);
					writer.Write(rest);
					return dest.ToArray();
				}
			}
		}
    

开发者ID:mafaca,项目名称:UtinyRipper,代码行数:59,代码来源:DXShaderProgramRestorer.cs

在RestoreProgramData()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了5次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadUInt32的代码示例7 - Export()

    using System.IO;
		public override void Export(ShaderWriter writer, ref ShaderSubProgram subProgram)
		{
			using (MemoryStream memStream = new MemoryStream(subProgram.ProgramData))
			{
				using (BinaryReader reader = new BinaryReader(memStream))
				{
					if (Shader.HasBlob(writer.Version))
					{
						long position = reader.BaseStream.Position;
						uint fourCC = reader.ReadUInt32();
						if (fourCC == MetalFourCC)
						{
							int offset = reader.ReadInt32();
							reader.BaseStream.Position = position + offset;
						}
						using (EndianReader endReader = new EndianReader(reader.BaseStream, EndianType.LittleEndian))
						{
							EntryName = endReader.ReadStringZeroTerm();
						}
					}

					ExportText(writer, reader);
				}
			}
		}
    

开发者ID:mafaca,项目名称:UtinyRipper,代码行数:26,代码来源:ShaderMetalExporter.cs

在Export()方法中,BinaryReader的代码示例类中的ReadUInt32的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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