/// <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) { int i; int bytesRead = 0; this.groupId = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.reserved = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.groupCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.groups = new PropertyGroup[this.groupCount]; for (i = 0; i < this.groupCount; i++) { this.groups[i] = new PropertyGroup(); bytesRead += this.groups[i].Deserialize(stream, -1); } if (size > 0 && bytesRead != size) { AdapterHelper.Site.Assert.Fail("The bytes length to read should be equal to the stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead); } return(bytesRead); }
/// <summary> /// Deserialize fields in this class from a stream. /// </summary> /// <param name="stream">Stream contains a serialized instance of this class.</param> /// <param name="size">The number of bytes can read if -1, no limitation. MUST be -1.</param> /// <returns>Bytes have been read from the stream.</returns> 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); }
/// <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 int Deserialize(System.IO.Stream stream, int size) { AdapterHelper.Site.Assert.AreEqual(-1, size, "The size value should be -1, but the actual value is {0}.", size); int bytesRead = 0; this.Flags = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.Depth = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.FolderLongTermId = StreamHelper.ReadLongTermId(stream); bytesRead += 0x10 + 6 + 2; this.ServerDNCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.CheapServerDNCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.ServerDNArray = new string[this.ServerDNCount]; for (int i = 0; i < this.ServerDNCount; i++) { this.ServerDNArray[i] = StreamHelper.ReadString8(stream); } AdapterHelper.Site.Assert.AreEqual(this.ServerDNArray.Length, (int)this.ServerDNCount, "The deserialized serverDN count is not equal to the original server DN count. The expected value of the deserialized server DN is {0}, but the actual value is {1}.", this.ServerDNCount, this.ServerDNArray.Length); bytesRead += Common.GetBytesFromMutiUnicodeString(this.ServerDNArray).Length; return(bytesRead); }
/// <summary> /// Deserialize fields in this class from a stream. /// </summary> /// <param name="stream">Stream contains a serialized instance of this class.</param> /// <param name="size">The number of bytes can read if -1, no limitation.</param> /// <returns>Bytes have been read from the stream.</returns> public override int Deserialize(Stream stream, int size) { int bytesRead = 0; this.version = StreamHelper.ReadUInt16(stream); bytesRead += 2; 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); } this.padding1 = StreamHelper.ReadUInt16(stream); bytesRead += 2; 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); } this.faiMessageCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; 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); } this.faiMessageTotalSize = StreamHelper.ReadUInt64(stream); bytesRead += 8; 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); } this.normalMessageCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; 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); } this.padding2 = StreamHelper.ReadUInt32(stream); bytesRead += 4; 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); } this.normalMessageTotalSize = StreamHelper.ReadUInt64(stream); bytesRead += 8; 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); }
/// <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 fields in this class from a stream. /// </summary> /// <param name="stream">stream contains a serialized instance of this class</param> /// <param name="size">The number of bytes can read if -1, no limitation, MUST be -1</param> /// <returns>Bytes have been 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 actual is {0}.", size); int bytesRead = 0; bytesRead += 2; this.blockBytesCount = StreamHelper.ReadUInt32(stream); bytesRead += 4; this.blockBytes = new byte[this.blockBytesCount]; bytesRead += stream.Read(this.blockBytes, 0, (int)this.blockBytesCount); AdapterHelper.Site.Assert.Fail("The bytes length to read is not equal to the stream size, the stream size is {0} and the bytes to read is {1}.", size, bytesRead); return(bytesRead); }
/// <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); }