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


C# DataReader.ReadUInt16方法代码示例

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


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

示例1: ReadFrom

        public static AlternateStreamEntry ReadFrom(DataReader reader)
        {
            long startPos = reader.Position;

            long length = reader.ReadInt64();
            if (length == 0)
            {
                return null;
            }

            reader.Skip(8);

            AlternateStreamEntry result = new AlternateStreamEntry();
            result.Length = length;
            result.Hash = reader.ReadBytes(20);
            int nameLength = reader.ReadUInt16();
            if (nameLength > 0)
            {
                result.Name = Encoding.Unicode.GetString(reader.ReadBytes(nameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.Name = string.Empty;
            }

            if (startPos + length > reader.Position)
            {
                int toRead = (int)(startPos + length - reader.Position);
                reader.Skip(toRead);
            }

            return result;
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:33,代码来源:AlternateStreamEntry.cs

示例2: ReadFrom

        public static DirectoryEntry ReadFrom(DataReader reader)
        {
            long startPos = reader.Position;

            long length = reader.ReadInt64();
            if (length == 0)
            {
                return null;
            }

            DirectoryEntry result = new DirectoryEntry();
            result.Length = length;
            result.Attributes = (FileAttributes)reader.ReadUInt32();
            result.SecurityId = reader.ReadUInt32();
            result.SubdirOffset = reader.ReadInt64();
            reader.Skip(16);
            result.CreationTime = reader.ReadInt64();
            result.LastAccessTime = reader.ReadInt64();
            result.LastWriteTime = reader.ReadInt64();
            result.Hash = reader.ReadBytes(20);
            reader.Skip(4);
            result.ReparseTag = reader.ReadUInt32();
            result.HardLink = reader.ReadUInt32();
            result.StreamCount = reader.ReadUInt16();
            int shortNameLength = reader.ReadUInt16();
            int fileNameLength = reader.ReadUInt16();

            if (fileNameLength > 0)
            {
                result.FileName = Encoding.Unicode.GetString(reader.ReadBytes(fileNameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.FileName = string.Empty;
            }

            if (shortNameLength > 0)
            {
                result.ShortName = Encoding.Unicode.GetString(reader.ReadBytes(shortNameLength + 2)).TrimEnd('\0');
            }
            else
            {
                result.ShortName = null;
            }

            if (startPos + length > reader.Position)
            {
                int toRead = (int)(startPos + length - reader.Position);
                reader.Skip(toRead);
            }

            if (result.StreamCount > 0)
            {
                result.AlternateStreams = new Dictionary<string, AlternateStreamEntry>();
                for (int i = 0; i < result.StreamCount; ++i)
                {
                    AlternateStreamEntry stream = AlternateStreamEntry.ReadFrom(reader);
                    result.AlternateStreams.Add(stream.Name, stream);
                }
            }

            return result;
        }
开发者ID:alexcmd,项目名称:DiscUtils,代码行数:63,代码来源:DirectoryEntry.cs

示例3: ReadQuestion

        private static DNSQuestion ReadQuestion(byte[] data, DataReader reader)
        {
            DNSQuestion q = new DNSQuestion();

            q.QName = ReadString(data, reader);
            q.QType = (DNSType)reader.ReadUInt16(false);
            q.QClass = (DNSClass)reader.ReadUInt16(false);

            return q;
        }
开发者ID:michyer,项目名称:canape,代码行数:10,代码来源:DNSPacket.cs

示例4: ReadResourceRecord

        private static DNSRRBase ReadResourceRecord(byte[] data, DataReader reader)
        {
            DNSRRBase rr = null;

            string name = ReadString(data, reader);
            DNSType type = (DNSType)reader.ReadUInt16(false);
            DNSClass cls = (DNSClass)reader.ReadUInt16(false);
            uint ttl = reader.ReadUInt32(false);
            ushort rlen = reader.ReadUInt16(false);
            byte[] rdata = reader.ReadBytes(rlen);

            switch (type)
            {
                case DNSType.CNAME:
                    {
                        CNameDNSRR newRec = new CNameDNSRR(data, rdata);
                        rr = newRec;
                    }
                    break;
                case DNSType.A:
                    {
                        ADNSRR aRec = new ADNSRR(rdata);
                        rr = aRec;
                    }
                    break;
                case DNSType.AAAA:
                    {
                        AAAADNSRR aRec = new AAAADNSRR(rdata);
                        rr = aRec;
                    }
                    break;
                case DNSType.PTR:
                    {
                        PTRDNSRR aRec = new PTRDNSRR(data, rdata);
                        rr = aRec;
                    }
                    break;
                default:
                    {
                        UnknownDNSRR newRec = new UnknownDNSRR();
                        newRec.RData = rdata;
                        rr = newRec;
                    }
                    break;
            }

            rr.Name = name;
            rr.Class = cls;
            rr.Type = type;
            rr.TimeToLive = ttl;

            return rr;
        }
开发者ID:michyer,项目名称:canape,代码行数:53,代码来源:DNSPacket.cs

示例5: FromArray

        /// <summary>
        /// Create from an array
        /// </summary>
        /// <param name="data">The data</param>
        /// <returns>The parsed DNS packet</returns>
        public static DNSPacket FromArray(byte[] data)
        {
            DataReader reader = new DataReader(new MemoryStream(data));

            DNSPacket ret = new DNSPacket();

            ret.Id = reader.ReadUInt16(false);

            ushort flags = reader.ReadUInt16(false);

            ret.Query = GetBooleanFlag(flags, 0);
            ret.Opcode = (DNSOpcode)GetFlagValue(flags, 1);
            ret.AuthoritiveAnswer = GetBooleanFlag(flags, 5);
            ret.Truncation = GetBooleanFlag(flags, 6);
            ret.RecursionDesired = GetBooleanFlag(flags, 7);
            ret.RecursionAvailable = GetBooleanFlag(flags, 8);
            ret.ResponseCode = (DNSRCode)GetFlagValue(flags, 12);

            ushort qdcount = reader.ReadUInt16(false);
            ushort ancount = reader.ReadUInt16(false);
            ushort nscount = reader.ReadUInt16(false);
            ushort arcount = reader.ReadUInt16(false);

            if (qdcount > 0)
            {
                DNSQuestion[] questions = new DNSQuestion[qdcount];

                for (int i = 0; i < qdcount; i++)
                {
                    questions[i] = ReadQuestion(data, reader);
                }

                ret.Questions = questions;
            }

            if (ancount > 0)
            {
                ret.Answers = ReadResourceRecords(data, reader, ancount);
            }

            if (nscount > 0)
            {
                ret.NameServers = ReadResourceRecords(data, reader, nscount);
            }

            if (arcount > 0)
            {
                ret.Additional = ReadResourceRecords(data, reader, arcount);
            }

            return ret;
        }
开发者ID:michyer,项目名称:canape,代码行数:57,代码来源:DNSPacket.cs


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