ReadUInt16() публичный Метод

Reads a 2-byte unsigned integer from the current position and advances the current position of the buffer by 2 bytes.
public ReadUInt16 ( ) : ushort
Результат ushort
        /// <summary>
        /// Deserialized byte array to a Restriction instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of a Restriction instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public override uint Deserialize(byte[] buffer)
        {
            BufferReader reader = new BufferReader(buffer);
            this.RestrictType = (RestrictionType)reader.ReadByte();
            this.propTag.PropertyType = reader.ReadUInt16();
            this.propTag.PropertyId = reader.ReadUInt16();

            return reader.Position;
        }
 /// <summary>
 /// Deserialized byte array to a TagActionData instance
 /// </summary>
 /// <param name="buffer">Byte array contains data of an ActionData instance.</param>
 /// <returns>Bytes count that deserialized in buffer.</returns>
 public uint Deserialize(byte[] buffer)
 {
     BufferReader bufferReader = new BufferReader(buffer);
     PropertyTag propertyTag = new PropertyTag
     {
         PropertyType = bufferReader.ReadUInt16(),
         PropertyId = bufferReader.ReadUInt16()
     };
     this.PropertyTag = propertyTag;
     uint size = bufferReader.Position;
     this.PropertyValue = AdapterHelper.ReadValueByType(this.PropertyTag.PropertyType, bufferReader.ReadToEnd());
     size += (uint)this.PropertyValue.Length;
     return size;
 }
        /// <summary>
        /// Get a TaggedPropertyValue structure from buffer.
        /// </summary>
        /// <param name="buffer">Buffer contain TaggedPropertyValue instance.</param>
        /// <returns>A TaggedPropertyvalue structure.</returns>
        public static TaggedPropertyValue ReadTaggedProperty(byte[] buffer)
        {
            TaggedPropertyValue tagValue = new TaggedPropertyValue();
            BufferReader bufferReader = new BufferReader(buffer);

            PropertyTag newPropertyTag = new PropertyTag
            {
                PropertyType = bufferReader.ReadUInt16(),
                PropertyId = bufferReader.ReadUInt16()
            };
            tagValue.PropertyTag = newPropertyTag;
            tagValue.Value = ReadValueByType(tagValue.PropertyTag.PropertyType, bufferReader.ReadToEnd());

            return tagValue;
        }
        /// <summary>
        /// Deserialized byte array to a Restriction instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of a Restriction instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public override uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            this.RestrictType = (RestrictionType)bufferReader.ReadByte();
            this.restrictCount = (this.CountType == CountByte.TwoBytesCount) ? bufferReader.ReadUInt16() : bufferReader.ReadUInt32();
            int count = (this.CountType == CountByte.TwoBytesCount) ? (int)(ushort)this.RestrictCount : (int)(uint)this.RestrictCount;
            this.Restricts = new IRestriction[count];

            uint size = bufferReader.Position;
            byte[] tmpArray = bufferReader.ReadToEnd();
            for (int i = 0; i < count; i++)
            {
                RestrictionType restrictionType = (RestrictionType)tmpArray[0];
                switch (restrictionType)
                {
                    case RestrictionType.AndRestriction:
                        this.Restricts[i] = new AndRestriction(this.CountType);
                        break;
                    case RestrictionType.BitMaskRestriction:
                        this.Restricts[i] = new BitMaskRestriction();
                        break;
                    case RestrictionType.CommentRestriction:
                        this.Restricts[i] = new CommentRestriction(this.CountType);
                        break;
                    case RestrictionType.ComparePropertiesRestriction:
                        this.Restricts[i] = new ComparePropertiesRestriction();
                        break;
                    case RestrictionType.ContentRestriction:
                        this.Restricts[i] = new ContentRestriction();
                        break;
                    case RestrictionType.CountRestriction:
                        this.Restricts[i] = new CountRestriction(this.CountType);
                        break;
                    case RestrictionType.ExistRestriction:
                        this.Restricts[i] = new ExistRestriction();
                        break;
                    case RestrictionType.NotRestriction:
                        this.Restricts[i] = new NotRestriction(this.CountType);
                        break;
                    case RestrictionType.OrRestriction:
                        this.Restricts[i] = new OrRestriction(this.CountType);
                        break;
                    case RestrictionType.PropertyRestriction:
                        this.Restricts[i] = new PropertyRestriction();
                        break;
                    case RestrictionType.SizeRestriction:
                        this.Restricts[i] = new SizeRestriction();
                        break;
                    case RestrictionType.SubObjectRestriction:
                        this.Restricts[i] = new SubObjectRestriction(this.CountType);
                        break;
                }

                uint tmpLength = this.Restricts[i].Deserialize(tmpArray);
                size += tmpLength;
                bufferReader = new BufferReader(tmpArray);
                tmpArray = bufferReader.ReadBytes(tmpLength, (uint)(tmpArray.Length - tmpLength));
            }

            return size;
        }
        /// <summary>
        /// Read a value from buffer for special Type.
        /// </summary>
        /// <param name="type">The Type of value.</param>
        /// <param name="buffer">Buffer contains value.</param>
        /// <returns>Byte array of the value.</returns>
        public static byte[] ReadValueByType(ushort type, byte[] buffer)
        {
            byte[] value = null;
            BufferReader bufferReader = new BufferReader(buffer);

            uint length = 0;
            byte[] tmpArray = null;
            uint startIndex = 0;
            uint endIndex = 0;
            switch (type)
            {
                // 2-byte
                // PtypInteger16
                case 0x0002:
                    value = bufferReader.ReadBytes(2);
                    break;

                // 4-byte
                // PtypInteger32
                case 0x0003:

                // PtypFloating32
                case 0x0004:

                // PtypErrorCode 
                case 0x000A:
                    value = bufferReader.ReadBytes(4);
                    break;

                // 8-byte
                // PtypFloating64
                case 0x0005:

                // PtypCurrency 
                case 0x0006:

                // PtypFloatingTime
                case 0x0007:

                // PtypInteger64
                case 0x0014:

                // PtypTime 
                case 0x0040:
                    value = bufferReader.ReadBytes(8);
                    break;

                // 1 byte
                // PtypBoolean 
                case 0x000B:
                    value = new byte[1] { bufferReader.ReadByte() };
                    break;

                // PtypString PT_UNICODE
                case 0x001F:
                    value = Encoding.Unicode.GetBytes(bufferReader.ReadUnicodeString());
                    break;

                // PtypString8
                case 0x001E:
                    value = Encoding.ASCII.GetBytes(bufferReader.ReadASCIIString());
                    break;

                // 16-byte
                // PtypGuid  16bytes
                case 0x0048:

                // PtypServerId 
                case 0x00FB:
                    value = bufferReader.ReadBytes(16);
                    break;

                // PtypRestriction  
                case 0x00FD:
                    tmpArray = bufferReader.ReadToEnd();
                    IRestriction restriction = null;
                    RestrictionType restrictionType = (RestrictionType)tmpArray[0];
                    switch (restrictionType)
                    {
                        case RestrictionType.AndRestriction:
                            restriction = new AndRestriction();
                            break;
                        case RestrictionType.BitMaskRestriction:
                            restriction = new BitMaskRestriction();
                            break;
                        case RestrictionType.CommentRestriction:
                            restriction = new CommentRestriction();
                            break;
                        case RestrictionType.ComparePropertiesRestriction:
                            restriction = new ComparePropertiesRestriction();
                            break;
                        case RestrictionType.ContentRestriction:
                            restriction = new ContentRestriction();
                            break;
                        case RestrictionType.CountRestriction:
                            restriction = new CountRestriction();
                            break;
                        case RestrictionType.ExistRestriction:
                            restriction = new ExistRestriction();
                            break;
                        case RestrictionType.NotRestriction:
                            restriction = new NotRestriction();
                            break;
                        case RestrictionType.OrRestriction:
                            restriction = new OrRestriction();
                            break;
                        case RestrictionType.PropertyRestriction:
                            restriction = new PropertyRestriction();
                            break;
                        case RestrictionType.SizeRestriction:
                            restriction = new SizeRestriction();
                            break;
                        case RestrictionType.SubObjectRestriction:
                            restriction = new SubObjectRestriction();
                            break;
                    }

                    length += restriction.Deserialize(tmpArray);
                    value = bufferReader.ReadBytes(0, length);
                    break;

                // PtypRuleAction  
                case 0x00FE:
                    tmpArray = bufferReader.ReadToEnd();
                    RuleAction ruleAction = new RuleAction();
                    length = ruleAction.Deserialize(tmpArray);
                    bufferReader = new BufferReader(tmpArray);
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypBinary  
                case 0x0102:
                    length = (uint)(buffer[bufferReader.Position] + (buffer[bufferReader.Position + 1] << 8) + 2);
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypMultipleInteger16 
                case 0x1002:
                    length = (uint)(buffer[bufferReader.Position] + (buffer[bufferReader.Position + 1] << 8));
                    length = (length * 2) + 2;
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypMultipleInteger32  
                case 0x1003:

                // PtypMultipleFloating32  
                case 0x1004:
                    length = (uint)(buffer[bufferReader.Position] + (buffer[bufferReader.Position + 1] << 8));
                    length = (length * 4) + 2;
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypMultipleFloating64 
                case 0x1005:

                // PtypMultipleCurrency
                case 0x1006:

                // PtypMultipleFloatingTime
                case 0x1007:

                // PtypMultipleInteger64
                case 0x1014:

                // PtypMultipleTime 
                case 0x1040:
                    length = (uint)(buffer[bufferReader.Position] + (buffer[bufferReader.Position + 1] << 8));
                    length = (length * 8) + 2;
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypMultipleString
                case 0x101F:
                    startIndex = bufferReader.Position;
                    ushort strCount = bufferReader.ReadUInt16();
                    for (int istr = 0; istr < strCount; istr++)
                    {
                        bufferReader.ReadUnicodeString();
                    }

                    endIndex = bufferReader.Position;
                    length = endIndex - startIndex;
                    value = bufferReader.ReadBytes(startIndex, length);
                    break;

                // PtypMultipleString8
                case 0x101E:
                    startIndex = bufferReader.Position;
                    ushort str8Count = bufferReader.ReadUInt16();
                    for (int istr8 = 0; istr8 < str8Count; istr8++)
                    {
                        bufferReader.ReadASCIIString();
                    }

                    endIndex = bufferReader.Position;
                    length = endIndex - startIndex;
                    value = bufferReader.ReadBytes(startIndex, length);
                    break;

                // PtypMultipleGuid
                case 0x1048:
                    length = (uint)(buffer[bufferReader.Position] + (buffer[bufferReader.Position + 1] << 8));
                    length = (length * 16) + 2;
                    value = bufferReader.ReadBytes(length);
                    break;

                // PtypMultipleBinary 
                case 0x1102:
                    startIndex = bufferReader.Position;
                    ushort binCount = bufferReader.ReadUInt16();
                    for (int ibin = 0; ibin < binCount; ibin++)
                    {
                        uint binLength = bufferReader.ReadUInt16();
                        bufferReader.ReadBytes(binLength);
                    }

                    endIndex = bufferReader.Position;
                    length = endIndex - startIndex;
                    value = bufferReader.ReadBytes(startIndex, length);
                    break;

                // PtypUnspecified 
                case 0x0000:
                    throw new NotImplementedException();

                // PtypNull
                case 0x0001:
                    value = null;
                    break;

                // PtypObject or PtypEmbeddedTable 
                case 0x000D:
                    throw new NotImplementedException();
            }

            return value;
        }
        /// <summary>
        /// Deserialized byte array to an ActionBlock instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of an ActionBlock instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            uint totalBytes = 0;
            if (this.CountType == CountByte.TwoBytesCount)
            {
                this.ActionLength = bufferReader.ReadUInt16();
                totalBytes += bufferReader.Position;
                bufferReader = new BufferReader(bufferReader.ReadBytes((ushort)this.ActionLength));
            }
            else if (this.CountType == CountByte.FourBytesCount)
            {
                this.ActionLength = bufferReader.ReadUInt32();
                totalBytes += bufferReader.Position;
                bufferReader = new BufferReader(bufferReader.ReadBytes((uint)this.ActionLength));
            }

            this.ActionType = (ActionType)bufferReader.ReadByte();
            this.ActionFlavor = bufferReader.ReadUInt32();
            this.ActionFlags = bufferReader.ReadUInt32();

            totalBytes += bufferReader.Position;
            byte[] tmpArray = null;
            byte[] remainBuffer = bufferReader.ReadToEnd();
            tmpArray = remainBuffer;

            switch (this.ActionType)
            {
                case ActionType.OP_MOVE:
                case ActionType.OP_COPY:

                    // On Exchange 2013, a redundant "0xff" field may be inserted before the actual Action data. 
                    if (remainBuffer != null && remainBuffer[0] == 0xff)
                    {
                        tmpArray = new byte[remainBuffer.Length - 1];
                        Array.Copy(remainBuffer, 1, tmpArray, 0, remainBuffer.Length - 1);
                        this.ActionLength = (ushort)this.ActionLength - 1;
                    }

                    if (this.CountType == CountByte.TwoBytesCount)
                    {
                        this.ActionDataValue = new MoveCopyActionData();
                    }
                    else if (this.CountType == CountByte.FourBytesCount)
                    {
                        this.ActionDataValue = new MoveCopyActionDataOfExtendedRule();
                    }

                    break;
                case ActionType.OP_REPLY:
                case ActionType.OP_OOF_REPLY:

                    if (this.CountType == CountByte.TwoBytesCount)
                    {
                        this.ActionDataValue = new ReplyActionData();
                    }
                    else if (this.CountType == CountByte.FourBytesCount)
                    {
                        this.ActionDataValue = new ReplyActionDataOfExtendedRule();
                    }

                    break;
                case ActionType.OP_DEFER_ACTION:
                    this.ActionDataValue = new DeferredActionData();
                    break;
                case ActionType.OP_BOUNCE:
                    this.ActionDataValue = new BounceActionData();
                    break;
                case ActionType.OP_FORWARD:
                case ActionType.OP_DELEGATE:
                    this.ActionDataValue = new ForwardDelegateActionData(this.CountType);
                    break;
                case ActionType.OP_TAG:
                    this.ActionDataValue = new TagActionData();
                    break;
                case ActionType.OP_DELETE:
                case ActionType.OP_MARK_AS_READ:
                    this.ActionDataValue = new DeleteMarkReadActionData();
                    break;
            }

            totalBytes += this.ActionDataValue.Deserialize(tmpArray);
            return totalBytes;
        }
        /// <summary>
        /// Parse method to obtain current structure from byte array
        /// </summary>
        /// <param name="buffer">Byte array data.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            uint count = 0;
            if (this.CountType == CountByte.TwoBytesCount)
            {
                this.NoOfActions = bufferReader.ReadUInt16();
                this.Actions = new ActionBlock[(ushort)this.NoOfActions];
                count = (uint)(ushort)this.NoOfActions;
            }
            else if (this.CountType == CountByte.FourBytesCount)
            {
                this.NoOfActions = bufferReader.ReadUInt32();
                this.Actions = new ActionBlock[(uint)this.NoOfActions];
                count = (uint)this.NoOfActions;
            }

            uint totalBytes = bufferReader.Position;
            byte[] tmpArray = bufferReader.ReadToEnd();
            uint bytesCount = 0;
            for (uint i = 0; i < count; i++)
            {
                bufferReader = new BufferReader(tmpArray);
                tmpArray = bufferReader.ReadBytes(bytesCount, (uint)(tmpArray.Length - bytesCount));
                this.Actions[i] = new ActionBlock(this.CountType);
                bytesCount = this.Actions[i].Deserialize(tmpArray);
                totalBytes += bytesCount;
            }

            return totalBytes;
        }
        /// <summary>
        /// Deserialized byte array to a MoveCopyActionData instance
        /// </summary>
        /// <param name="buffer">Byte array contains data of an ActionData instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            this.FolderInThisStore = bufferReader.ReadByte();
            this.StoreEIDSize = bufferReader.ReadUInt16();
            this.StoreEID = bufferReader.ReadBytes(this.StoreEIDSize);
            this.FolderEIDSize = bufferReader.ReadUInt16();
            this.FolderEID = bufferReader.ReadBytes(this.FolderEIDSize);

            return bufferReader.Position;
        }
        /// <summary>
        /// Deserialized byte array to a ForwardActionData instance
        /// </summary>
        /// <param name="buffer">Byte array contains data of an ActionData instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            uint totalBytes = 0;
            uint count = 0;
            if (this.CountType == CountByte.TwoBytesCount)
            {
                this.RecipientCount = bufferReader.ReadUInt16();
                this.RecipientsData = new RecipientBlock[(ushort)this.RecipientCount];
                count = (uint)(ushort)this.RecipientCount;
            }
            else if (this.CountType == CountByte.FourBytesCount)
            {
                this.RecipientCount = bufferReader.ReadUInt32();
                this.RecipientsData = new RecipientBlock[(uint)this.RecipientCount];
                count = (uint)this.RecipientCount;
            }

            totalBytes += bufferReader.Position;
            byte[] tempArray = bufferReader.ReadToEnd();
            uint bytesCount = 0;
            for (uint i = 0; i < count; i++)
            {
                bufferReader = new BufferReader(tempArray);
                tempArray = bufferReader.ReadBytes(bytesCount, (uint)(tempArray.Length - bytesCount));
                this.RecipientsData[i] = new RecipientBlock(this.CountType);
                bytesCount = this.RecipientsData[i].Deserialize(tempArray);
            }

            totalBytes += bufferReader.Position;
            return totalBytes;
        }
Пример #10
0
        /// <summary>
        /// Deserialized byte array to a ForwardActionData instance
        /// </summary>
        /// <param name="buffer">Byte array contains data of an ActionData instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            this.Reserved = bufferReader.ReadByte();

            uint count = 0;
            if (this.CountType == CountByte.TwoBytesCount)
            {
                this.NoOfProperties = bufferReader.ReadUInt16();
                this.PropertiesData = new TaggedPropertyValue[(ushort)this.NoOfProperties];
                count = (uint)(ushort)this.NoOfProperties;
            }
            else if (this.CountType == CountByte.FourBytesCount)
            {
                this.NoOfProperties = bufferReader.ReadUInt32();
                this.PropertiesData = new TaggedPropertyValue[(uint)this.NoOfProperties];
                count = (uint)this.NoOfProperties;
            }

            uint size = bufferReader.Position;
            byte[] tmpArray = bufferReader.ReadToEnd();
            for (uint i = 0; i < count; i++)
            {
                TaggedPropertyValue tagValue = AdapterHelper.ReadTaggedProperty(tmpArray);
                this.PropertiesData[i] = tagValue;
                uint tagSize = (uint)tagValue.Size();
                size += tagSize;

                bufferReader = new BufferReader(tmpArray);
                tmpArray = bufferReader.ReadBytes(tagSize, (uint)(tmpArray.Length - tagSize));
            }

            return size;
        }
        /// <summary>
        /// Deserialized byte array to an ActionBlock instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of an ActionBlock instance</param>
        /// <returns>Bytes count that deserialized in buffer</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            uint totalBytes = 0;
            if (this.CountType == Count.TwoBytesCount)
            {
                this.ActionLength = bufferReader.ReadUInt16();
                totalBytes += bufferReader.Position;
                bufferReader = new BufferReader(bufferReader.ReadBytes((ushort)this.ActionLength));
            }
            else if (this.CountType == Count.FourBytesCount)
            {
                this.ActionLength = bufferReader.ReadUInt32();
                totalBytes += bufferReader.Position;
                bufferReader = new BufferReader(bufferReader.ReadBytes((uint)this.ActionLength));
            }

            this.ActionType = (ActionTypes)bufferReader.ReadByte();
            this.ActionFlavor = bufferReader.ReadUInt32();
            this.ActionFlags = bufferReader.ReadUInt32();

            totalBytes += bufferReader.Position;
            byte[] tmpArray = bufferReader.ReadToEnd();
            this.ActionDataValue = new DeleteMarkReadActionData();
            totalBytes += this.ActionDataValue.Deserialize(tmpArray);
            return totalBytes;
        }
        /// <summary>
        /// Deserialized byte array to an ActionData instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of an ActionData instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public uint Deserialize(byte[] buffer)
        {
            BufferReader bufferReader = new BufferReader(buffer);
            this.NoOfNamedProps = bufferReader.ReadUInt16();
            if (this.NoOfNamedProps == 0x0000)
            {
                return bufferReader.Position;
            }

            this.PropId = new uint[this.NoOfNamedProps];
            for (int i = 0; i < this.NoOfNamedProps; i++)
            {
                this.PropId[i] = bufferReader.ReadUInt32();
            }

            this.NamedPropertiesSize = bufferReader.ReadUInt32();
            this.NamedProperty = new PropertyName[this.NoOfNamedProps];

            uint length = bufferReader.Position;
            byte[] tmpArray = bufferReader.ReadToEnd();
            int startIndex = 0;
            for (int j = 0; j < this.NoOfNamedProps; j++)
            {
                this.NamedProperty[j] = new PropertyName();
                startIndex += this.NamedProperty[j].Deserialize(tmpArray, startIndex);
            }

            length += (uint)startIndex;
            return length;
        }
        /// <summary>
        /// Deserialized byte array to a Restriction instance
        /// </summary>
        /// <param name="buffer">Byte array contain data of a Restriction instance.</param>
        /// <returns>Bytes count that deserialized in buffer.</returns>
        public override uint Deserialize(byte[] buffer)
        {
            BufferReader reader = new BufferReader(buffer);
            this.RestrictType = (RestrictionType)reader.ReadByte();
            this.RelOp = (RelationalOperator)reader.ReadByte();
            this.propTag.PropertyType = reader.ReadUInt16();
            this.propTag.PropertyId = reader.ReadUInt16();

            uint size = reader.Position;
            byte[] tmpArray = reader.ReadToEnd();
            this.TaggedValue = AdapterHelper.ReadTaggedProperty(tmpArray);
            size += (uint)this.TaggedValue.Size();

            return size;
        }