Ejemplo n.º 1
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);
        }