Exemple #1
0
        /// <summary>
        /// Closes the current archive stream, if necessary.
        /// </summary>
        private void CloseArchiveStream()
        {
            if (mArchiveStream != null)
            {
                long bytesToSkip = mArchiveStream.Length - mArchiveStream.Position;
                if (mStream.CanSeek)
                {
                    // stream supports seeking
                    // => set stream position
                    mStream.Position += bytesToSkip;
                }
                else
                {
                    // stream does not support seeking
                    // => read and discard bytes to skip
                    byte[] buffer = mSerializer.mTempBuffer_BigBuffer;
                    while (bytesToSkip > 0)
                    {
                        int bytesToRead = (int)Math.Min(bytesToSkip, int.MaxValue);
                        bytesToRead  = Math.Min(bytesToRead, buffer.Length);
                        bytesToSkip -= mStream.Read(buffer, 0, bytesToRead);
                    }
                }

                mArchiveStream.Dispose();
                mArchiveStream = null;
            }
        }
Exemple #2
0
 /// <summary>
 /// Closes the current archive stream, if necessary.
 /// </summary>
 private void CloseArchiveStream()
 {
     if (mArchiveStream != null)
     {
         mArchiveStream.Dispose();
         mArchiveStream = null;
     }
 }
Exemple #3
0
        /// <summary>
        /// Reads a byte buffer using a stream.
        /// </summary>
        /// <returns>Stream containing data to read.</returns>
        /// <exception cref="SerializationException">Thrown if deserialization fails due to some reason.</exception>
        public Stream ReadStream()
        {
            // read payload type and size of the following buffer
            ReadAndCheckPayloadType(PayloadType.Buffer);
            long length = Leb128EncodingHelper.ReadInt64(mStream);

            mArchiveStream = new SerializerArchiveStream(mStream, length);
            return(mArchiveStream);
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeserializationArchive"/> class.
 /// </summary>
 /// <param name="serializer">The executing serializer.</param>
 /// <param name="stream">Stream containing the serialized archive.</param>
 /// <param name="type">Type the archive stores data from (used to instantiate the right class during deserialization).</param>
 /// <param name="version">Version of the type the archive contains data from.</param>
 /// <param name="context">User-specific context object.</param>
 internal DeserializationArchive(
     Serializer serializer,
     Stream stream,
     Type type,
     uint version,
     object context)
 {
     mSerializer    = serializer;
     mStream        = stream;
     mArchiveStream = null;
     DataType       = type;
     Version        = version;
     Context        = context;
 }