/// <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 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); this.replguid = StreamHelper.ReadGuid(stream); this.globset = new GLOBSET(); return(0x10 + this.globset.Deserialize(stream, -1)); }
/// <summary> /// Read a LongTermId from a stream /// and advances the position within the stream by 24. /// </summary> /// <param name="stream">The stream.</param> /// <returns>The number of bytes read from the stream.</returns> public static LongTermId ReadLongTermId(Stream stream) { LongTermId id = new LongTermId(); id.DatabaseGuid = StreamHelper.ReadGuid(stream).ToByteArray(); id.GlobalCounter = new byte[6]; stream.Read(id.GlobalCounter, 0, 6); stream.Read(new byte[2], 0, 2); return(id); }
/// <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(System.IO.Stream stream, int size) { if (size == -1) { size = (int)(stream.Length - stream.Position); } this.namespaceGuid = StreamHelper.ReadGuid(stream); int bufferSize = size - GuidSize; if (bufferSize >= 0) { this.localId = new byte[bufferSize]; stream.Read(this.localId, 0, this.localId.Length); return(size); } else { AdapterHelper.Site.Assert.Fail("The specified size should be larger than the size of a Guid in bytes.", "size"); return(-1); } }