Microsoft.Protocols.TestSuites.MS_OXCFXICS.GroupPropertyName.Deserialize C# (CSharp) Method

Deserialize() public method

Deserialize fields in this class from a stream.
public Deserialize ( Stream stream, int size ) : int
stream Stream Stream contains a serialized instance of this class.
size int The number of bytes can read if -1, no limitation. MUST be -1.
return int
        public override int Deserialize(Stream stream, int size)
        {
            int bytesRead = 0;
            AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value MUST be -1, the actual value is {0}.", size);

            this.guid = StreamHelper.ReadGuid(stream);
            bytesRead += 0x10;
            this.kind = StreamHelper.ReadUInt32(stream);
            if (this.kind == 0x00000000)
            {
                this.nameSize = null;
                this.name = null;
                this.lid = StreamHelper.ReadUInt32(stream);
                bytesRead += 4;
            }
            else if (this.kind == 0x00000001)
            {
                this.lid = null;
                this.nameSize = StreamHelper.ReadUInt32(stream);
                bytesRead += 4;
                byte[] buffer = new byte[(int)this.nameSize];
                stream.Read(buffer, 0, (int)this.nameSize);
                this.name = Encoding.Unicode.GetChars(buffer);
                bytesRead += (int)this.nameSize;
            }

            return bytesRead;
        }
    }

Usage Example

コード例 #1
0
        /// <summary>
        /// Deserialize an object from a stream.
        /// </summary>
        /// <param name="stream">A stream contains object fields.</param>
        /// <param name="size">Max length can used by this deserialization
        /// if -1 no limitation except stream length.
        /// </param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value MUST be -1, the actual value is {0}.", size);

            int bytesRead = 0;
            int i;

            this.propertyTagCount = StreamHelper.ReadUInt32(stream);
            bytesRead            += 4;
            this.propertyTags     = new Tuple <PropertyTag, GroupPropertyName> [this.propertyTagCount];
            for (i = 0; i < this.propertyTagCount; i++)
            {
                PropertyTag tag = new PropertyTag
                {
                    PropertyType = StreamHelper.ReadUInt16(stream)
                };
                bytesRead     += 2;
                tag.PropertyId = StreamHelper.ReadUInt16(stream);
                bytesRead     += 2;
                GroupPropertyName name = null;
                if (this.IsNamedProperty(tag))
                {
                    name       = new GroupPropertyName();
                    bytesRead += name.Deserialize(stream, -1);
                }

                this.propertyTags[i] = new Tuple <PropertyTag, GroupPropertyName>(tag, name);
            }

            if (size >= 0 && bytesRead > size)
            {
                AdapterHelper.Site.Assert.Fail("The bytes length to read is larger than stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead);
            }

            return(bytesRead);
        }
GroupPropertyName