C# BinaryReader.ReadBytes的代码示例

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

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


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

BinaryReader.ReadBytes的代码示例1 - FromBinaryReader()

    using System.IO;

        public static T FromBinaryReader(BinaryReader reader)
        {
            T theStructure;
            byte[] bytes = reader.ReadBytes(Marshal.SizeOf(typeof(T)));
            GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
            try
            {
                theStructure = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
            }
            finally
            {
                handle.Free();
            }
            return theStructure;
        }
    

开发者ID:med0x2e,项目名称:SigFlip,代码行数:17,代码来源:Utils.cs

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

BinaryReader.ReadBytes的代码示例2 - 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的代码示例类中的ReadBytes的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

BinaryReader.ReadBytes的代码示例3 - Hash()

    using System.IO;

        public static uint Hash(Stream stream)
        {
            const uint c1 = 0xcc9e2d51;
            const uint c2 = 0x1b873593;

            var h1 = Seed;
            uint streamLength = 0;

            using (var reader = new BinaryReader(stream))
            {
                var chunk = reader.ReadBytes(4);
                while (chunk.Length > 0)
                {
                    streamLength += (uint)chunk.Length;
                    uint k1;
                    switch (chunk.Length)
                    {
                        case 4:
                            k1 = (uint)(chunk[0] | chunk[1] << 8 | chunk[2] << 16 | chunk[3] << 24);
                            k1 *= c1;
                            k1 = Rot(k1, 15);
                            k1 *= c2;
                            h1 ^= k1;
                            h1 = Rot(h1, 13);
                            h1 = h1 * 5 + 0xe6546b64;
                            break;
                        case 3:
                            k1 = (uint) (chunk[0] | chunk[1] << 8 | chunk[2] << 16);
                            k1 *= c1;
                            k1 = Rot(k1, 15);
                            k1 *= c2;
                            h1 ^= k1;
                            break;
                        case 2:
                            k1 = (uint) (chunk[0] | chunk[1] << 8);
                            k1 *= c1;
                            k1 = Rot(k1, 15);
                            k1 *= c2;
                            h1 ^= k1;
                            break;
                        case 1:
                            k1 = (chunk[0]);
                            k1 *= c1;
                            k1 = Rot(k1, 15);
                            k1 *= c2;
                            h1 ^= k1;
                            break;
                    }
                    chunk = reader.ReadBytes(4);
                }
            }

            h1 ^= streamLength;
            h1 = Mix(h1);

            return h1;
        }
    

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

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

BinaryReader.ReadBytes的代码示例4 - GetAlbumCover()

    using System.IO;

        private static async Task GetAlbumCover(string link)
        {
            if (string.IsNullOrWhiteSpace(link)) return null;

            try
            {
                var request = WebRequest.Create(link);
                using (var response = await request.GetResponseAsync())
                {
                    var stream = response.GetResponseStream();
                    if (stream == null) return null;
                    using (var reader = new BinaryReader(stream))
                    {
                        using (var memory = new MemoryStream())
                        {
                            var buffer = reader.ReadBytes(4096);
                            while (buffer.Length > 0)
                            {
                                await memory.WriteAsync(buffer, 0, buffer.Length);
                                buffer = reader.ReadBytes(4096);
                            }

                            return memory.ToArray();
                        }
                    }
                }
            }
            catch
            {
                return null;
            }
        }
    

开发者ID:jwallet,项目名称:spy-spotify,代码行数:34,代码来源:MapperID3.cs

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

BinaryReader.ReadBytes的代码示例5 - SaveStream()

    using System.IO;

        // ReSharper disable UnusedMethodReturnValue.Local
        private static long SaveStream(Stream stream, string path, DateTime touchDate, int streamBufferSize)
            // ReSharper restore UnusedMethodReturnValue.Local
        {
            FilePreparePath(path);

            long len = 0;

            using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                using (BinaryReader br = new BinaryReader(stream))
                {
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        byte[] buffer;
                        do
                        {
                            buffer = br.ReadBytes(streamBufferSize);
                            len += buffer.Length;
                            if (buffer.Length > 0)
                            {
                                bw.Write(buffer);
                            }
                        } while (buffer.Length > 0);

                        bw.Flush();
                    }
                }
            }

            File.SetLastWriteTime(path, touchDate);
            return len;
        }
    

开发者ID:zzzprojects,项目名称:html-agility-pack,代码行数:35,代码来源:HtmlWeb.cs

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

BinaryReader.ReadBytes的代码示例6 - ReadUTF8String()

    using System.IO;
        protected static string ReadUTF8String(System.IO.BinaryReader reader)
        {
            uint bsLength = 0;
            byte b = reader.ReadByte();
            if (b == 0xff)
            {
                return null;
            }
            if (b == 0)
            {
                return string.Empty;
            }
            if ((b & 0x80) == 0)
            {
                bsLength = b;
            }
            else if ((b & 0x40) == 0)
            {
                bsLength = (uint)(((b & -129) << 8) | reader.ReadByte());
            }
            else
            {
                bsLength = (uint)(((b & -193) << 24) | (reader.ReadByte() << 16) | (reader.ReadByte() << 8) | reader.ReadByte());
            }
            if (bsLength == 0)
            {
                return null;
            }
            var bsTemp = reader.ReadBytes((int)bsLength);
            var str = System.Text.Encoding.UTF8.GetString(bsTemp);
            return str;
        }
    

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

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

BinaryReader.ReadBytes的代码示例7 - InitializeByStream()

    using System.IO;
        /// 
        /// Initializes the properties of the  by reading them from the .
        /// 
        /// The stream which contains the metadata.
        protected override unsafe void InitializeByStream(Stream stream)
        {
            //http://flac.sourceforge.net/format.html#metadata_block_streaminfo
            var reader = new BinaryReader(stream, Encoding.ASCII);
            try
            {
                MinBlockSize = reader.ReadInt16();
                MaxBlockSize = reader.ReadInt16();
            }
            catch (IOException e)
            {
                throw new FlacException(e, FlacLayer.Metadata);
            }
            const int bytesToRead = (240 / 8) - 16;
            byte[] buffer = reader.ReadBytes(bytesToRead);
            if (buffer.Length != bytesToRead)
            {
                throw new FlacException(new EndOfStreamException("Could not read StreamInfo-content"),
                    FlacLayer.Metadata);
            }

            fixed (byte* b = buffer)
            {
                var bitreader = new FlacBitReader(b, 0);
                MinFrameSize = (int)bitreader.ReadBits(24);
                MaxFrameSize = (int)bitreader.ReadBits(24);
                SampleRate = (int)bitreader.ReadBits(20);
                Channels = 1 + (int)bitreader.ReadBits(3);
                BitsPerSample = 1 + (int)bitreader.ReadBits(5);
                TotalSamples = (long)bitreader.ReadBits64(36);
                Md5 = new String(reader.ReadChars(16));
            }
        }
    

开发者ID:filoe,项目名称:cscore,代码行数:38,代码来源:FlacMetadataStreamInfo.cs

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

BinaryReader.ReadBytes的代码示例8 - 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的代码示例类中的ReadBytes的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞

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