示例#1
0
        /// <summary>
        /// Deserialize from a stream.
        /// </summary>
        /// <param name="stream">A stream contains serialize.</param>
        /// <param name="size">Must be -1.</param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            int previousPosition = (int)stream.Position;
            int bytesRead        = 0;

            this.version   = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            this.padding1  = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            this.errorCode = StreamHelper.ReadUInt32(stream);
            bytesRead     += 4;
            byte[] buffer = new byte[22];
            stream.Read(buffer, 0, 22);
            this.folderGID = StructureSerializer.Deserialize <GID>(buffer);
            bytesRead     += 22;
            this.padding2  = StreamHelper.ReadUInt16(stream);
            bytesRead     += 2;
            buffer         = new byte[22];
            stream.Read(buffer, 0, 22);
            this.messageGID = StructureSerializer.Deserialize <GID>(buffer);
            bytesRead      += 22;
            this.padding3   = StreamHelper.ReadUInt16(stream);
            bytesRead      += 2;
            this.reserved1  = new byte[24];
            stream.Read(this.reserved1, 0, 24);
            bytesRead          += 24;
            this.auxBytesCount  = StreamHelper.ReadUInt32(stream);
            bytesRead          += 4;
            this.auxBytesOffset = StreamHelper.ReadUInt32(stream);
            bytesRead          += 4;
            int reservedBytesCount = (int)this.auxBytesOffset - previousPosition - bytesRead;

            if (reservedBytesCount > 0)
            {
                this.reserved2 = new byte[reservedBytesCount];
                bytesRead     += stream.Read(this.reserved2, 0, reservedBytesCount);
            }
            else if (reservedBytesCount == 0)
            {
                this.reserved2 = null;
            }
            else
            {
                AdapterHelper.Site.Assert.Fail("The deserialization operation should be successful.");
            }

            this.auxBytes = new byte[this.auxBytesCount];
            bytesRead    += stream.Read(this.auxBytes, 0, (int)this.auxBytesCount);
            AdapterHelper.Site.Assert.AreEqual(size, bytesRead, "The stream size is not equal to the bytes to read. The stream size is {0} and the read bytes is {1}.", size, bytesRead);

            return(bytesRead);
        }
        /// <summary>
        /// Deserialize from a stream.
        /// </summary>
        /// <param name="stream">A stream contains serialize.</param>
        /// <param name="size">Must be -1.</param>
        /// <returns>The number of bytes read from the stream.</returns>
        public override int Deserialize(Stream stream, int size)
        {
            int previousPosition = (int)stream.Position;
            int bytesRead = 0;
            this.version = StreamHelper.ReadUInt16(stream);
            bytesRead += 2;
            this.padding1 = StreamHelper.ReadUInt16(stream);
            bytesRead += 2;
            this.errorCode = StreamHelper.ReadUInt32(stream);
            bytesRead += 4;
            byte[] buffer = new byte[22];
            stream.Read(buffer, 0, 22);
            this.folderGID = StructureSerializer.Deserialize<GID>(buffer);
            bytesRead += 22;
            this.padding2 = StreamHelper.ReadUInt16(stream);
            bytesRead += 2;
            buffer = new byte[22];
            stream.Read(buffer, 0, 22);
            this.messageGID = StructureSerializer.Deserialize<GID>(buffer);
            bytesRead += 22;
            this.padding3 = StreamHelper.ReadUInt16(stream);
            bytesRead += 2;
            this.reserved1 = new byte[24];
            stream.Read(this.reserved1, 0, 24);
            bytesRead += 24;
            this.auxBytesCount = StreamHelper.ReadUInt32(stream);
            bytesRead += 4;
            this.auxBytesOffset = StreamHelper.ReadUInt32(stream);
            bytesRead += 4;
            int reservedBytesCount = (int)this.auxBytesOffset - previousPosition - bytesRead;
            if (reservedBytesCount > 0)
            {
                this.reserved2 = new byte[reservedBytesCount];
                bytesRead += stream.Read(this.reserved2, 0, reservedBytesCount);
            }
            else if (reservedBytesCount == 0)
            {
                this.reserved2 = null;
            }
            else
            {
                AdapterHelper.Site.Assert.Fail("The deserialization operation should be successful.");
            }

            this.auxBytes = new byte[this.auxBytesCount];
            bytesRead += stream.Read(this.auxBytes, 0, (int)this.auxBytesCount);
            AdapterHelper.Site.Assert.AreEqual(size, bytesRead, "The stream size is not equal to the bytes to read. The stream size is {0} and the read bytes is {1}.", size, bytesRead);

            return bytesRead;
        }