/// <summary> /// Copies all data to the given stream starting at it's current position prefixed with 8 bytes containing the size. /// </summary> public static long CopyToWithSize(this ISerializableToStream serializable, Stream stream) { var position = stream.Position; stream.Write(new byte[8], 0, 8); // copy the actual data. var size = serializable.CopyTo(stream); // write the size. stream.Seek(position, SeekOrigin.Begin); stream.Write(BitConverter.GetBytes(size), 0, 8); // reposition stream. stream.Seek(position + 8 + size, SeekOrigin.Begin); return(size + 8); }
private void WriteGuidToStream(ISerializableToStream xiObjectToSerialize) { byte[] lGuidBytes = xiObjectToSerialize.GetType().GetSerializationGuid().ToByteArray(); mStream.Write(lGuidBytes, 0, lGuidBytes.Length); }
private void Serialize(ISerializableToStream xiObjectToSerialize) { WriteGuidToStream(xiObjectToSerialize); xiObjectToSerialize.Serialize(mStream); mStream.Flush(); }