示例#1
0
        private string GetName(byte[] data, ref int pointer)
        {
            var name = new StringBuilder();

            while (data[pointer] < 192 && data[pointer] != 0)
            {
                var length = data[pointer];
                for (int i = pointer + 1; i <= pointer + length; i++)
                {
                    name.Append(Convert.ToChar(data[i]));
                }
                pointer += length + 1;
            }

            if (data[pointer] == 0)
            {
                pointer++;
                return(name.ToString());
            }

            var p = MyBitConverter.ToUInt16(data, ref pointer);

            CompressionPointer = p;
            var offset = GetOffset(p);

            return(name + GetName(data, ref offset));
        }
示例#2
0
        public Record(byte[] data, int pointer, bool isQuestion = false)
        {
            var previousePointer = pointer;

            Name  = GetName(data, ref pointer);
            QType = MyBitConverter.ToUInt16(data, ref pointer);
            if (!availableTypes.Contains(QType))
            {
                throw new Exception($"Incorrect type {QType}");
            }
            QClass = MyBitConverter.ToUInt16(data, ref pointer);
            if (isQuestion)
            {
                LengthRecord = pointer - previousePointer;
                Pointer      = pointer;
                return;
            }

            Ttl           = MyBitConverter.ToUInt32(data, ref pointer);
            DataLenght    = MyBitConverter.ToUInt16(data, ref pointer);
            PointerToData = (ushort)pointer;
            Data          = data.Skip(pointer).Take(DataLenght);
            Pointer       = pointer + DataLenght;
            LengthRecord  = Pointer - previousePointer;
        }
示例#3
0
        private string GetName(int pointer, byte[] data)
        {
            var name = new StringBuilder();

            while (data[pointer] < 192 && data[pointer] != 0)
            {
                var length = data[pointer];
                for (int i = pointer + 1; i <= pointer + length; i++)
                {
                    name.Append(Convert.ToChar(data[i]));
                }
                pointer += length + 1;
                if (data[pointer] != 0)
                {
                    name.Append(".");
                }
            }

            if (data[pointer] == 0)
            {
                return(name.ToString());
            }
            var offset = MyBitConverter.ToUInt16(data, pointer) & 16383;

            return(name + GetName(offset, data));
        }
        public ErrorPacket(byte[] data)
        {
            int offset = 0;

            this.Header            = MyBitConverter.ToUInt16(data, ref offset);
            this.Len               = data[offset++];
            this.SerialNum         = data[offset++];
            this.Type              = data[offset++];
            this.AgvId             = MyBitConverter.ToUInt16(data, ref offset);
            this.IsCheckSumCorrect = ResponseState.Error;
        }
示例#5
0
        public Header(byte[] data)
        {
            var pointer = 0;

            Id              = MyBitConverter.ToUInt16(data, ref pointer);
            FrameFlags      = new Flasg(MyBitConverter.ToUInt16(data, ref pointer));
            QuestionCount   = MyBitConverter.ToUInt16(data, ref pointer);
            AnswerCount     = MyBitConverter.ToUInt16(data, ref pointer);
            NameServerCount = MyBitConverter.ToUInt16(data, ref pointer);
            AdditionalCount = MyBitConverter.ToUInt16(data, ref pointer);
        }
示例#6
0
            /// <summary>
            /// Read sub image header.
            /// </summary>
            /// <param name="stream">Stream to read local header from.</param>
            /// <param name="endianness">Big or little, as defined by TIFF header.</param>
            public ImageFileDirectory(Stream stream, MyBitConverter.Endianness endianness) : this()
            {
                var bytes = stream.ReadBytes(2);

                NumberOfEntries  = MyBitConverter.ToUInt16(bytes, 0, endianness);
                FieldDescriptors = new List <FieldDescriptor>();


                for (int i = 0; i < NumberOfEntries; i++)
                {
                    bytes = stream.ReadBytes(12);
                    FieldDescriptors.Add(new FieldDescriptor(bytes, endianness, stream));
                }
            }
        /// <summary>
        /// 初始化父类中的成员数据
        /// </summary>
        /// <param name="ClassTpye">子类的名称</param>
        /// <param name="data">数据</param>
        protected ReceiveBasePacket(string ClassTpye, byte[] data)
        {
            if (data == null || data.Length < NeedLen())
            {
                throw new PacketException(ClassTpye, ExceptionCode.DataMiss);
            }
            if (data[NeedLen() - 1] != CaculateCheckSum(data))
            {
                throw new PacketException(ClassTpye, ExceptionCode.CheckSumError);
            }
            int offset = 0;

            this.Header    = MyBitConverter.ToUInt16(data, ref offset);
            this.Len       = data[offset++];
            this.SerialNum = data[offset++];
            this.Type      = data[offset++];
            this.AgvId     = MyBitConverter.ToUInt16(data, ref offset);
            this.CheckSum  = data[NeedLen() - 1];
        }