Ejemplo n.º 1
0
 // Token: 0x06003274 RID: 12916 RVA: 0x00126FC8 File Offset: 0x001253C8
 void IExtension.EndAppend(Stream stream, bool commit)
 {
     try
     {
         int num;
         if (commit && (num = (int)stream.Length) > 0)
         {
             MemoryStream memoryStream = (MemoryStream)stream;
             if (this.buffer == null)
             {
                 this.buffer = memoryStream.ToArray();
             }
             else
             {
                 int    num2 = this.buffer.Length;
                 byte[] to   = new byte[num2 + num];
                 Helpers.BlockCopy(this.buffer, 0, to, 0, num2);
                 Helpers.BlockCopy(Helpers.GetBuffer(memoryStream), 0, to, num2, num);
                 this.buffer = to;
             }
         }
     }
     finally
     {
         if (stream != null)
         {
             ((IDisposable)stream).Dispose();
         }
     }
 }
        void IExtension.EndAppend(Stream stream, bool commit)
        {
            using (stream)
            {
                int len;
                if (commit && (len = (int)stream.Length) > 0)
                {
                    MemoryStream ms = (MemoryStream)stream;

                    if (buffer == null)
                    {   // allocate new buffer
                        buffer = ms.ToArray();
                    }
                    else
                    {   // resize and copy the data
                        // note: Array.Resize not available on CF
                        int    offset = buffer.Length;
                        byte[] tmp    = new byte[offset + len];
                        Buffer.BlockCopy(buffer, 0, tmp, 0, offset);

                        Buffer.BlockCopy(Helpers.GetBuffer(ms), 0, tmp, offset, len);
                        buffer = tmp;
                    }
                }
            }
        }
 /// <summary>
 /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
 /// </summary>
 /// <typeparam name="T">The type being serialized.</typeparam>
 /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
 /// <param name="writer">The destination XmlWriter to write to.</param>
 public static void Serialize <[DynamicallyAccessedMembers(DynamicAccess.ContractType)] T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
 {
     if (writer is null)
     {
         throw new ArgumentNullException(nameof(writer));
     }
     if (instance is null)
     {
         throw new ArgumentNullException(nameof(instance));
     }
     using MemoryStream ms = new MemoryStream();
     Serializer.Serialize <T>(ms, instance);
     Helpers.GetBuffer(ms, out var segment);
     writer.WriteBase64(segment.Array, segment.Offset, segment.Count);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, instance);
                writer.WriteBase64(Helpers.GetBuffer(ms), 0, (int)ms.Length);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
#pragma warning disable RCS1165 // Unconstrained type parameter checked for null.
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
#pragma warning restore RCS1165 // Unconstrained type parameter checked for null.

            using MemoryStream ms = new MemoryStream();
            Serializer.Serialize <T>(ms, instance);
            Helpers.GetBuffer(ms, out var segment);
            writer.WriteBase64(segment.Array, segment.Offset, segment.Count);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Writes a protocol-buffer representation of the given instance to the supplied XmlWriter.
        /// </summary>
        /// <typeparam name="T">The type being serialized.</typeparam>
        /// <param name="instance">The existing instance to be serialized (cannot be null).</param>
        /// <param name="writer">The destination XmlWriter to write to.</param>
        public static void Serialize <T>(System.Xml.XmlWriter writer, T instance) where T : System.Xml.Serialization.IXmlSerializable
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
#pragma warning disable RCS1165 // Unconstrained type parameter checked for null.
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }
#pragma warning restore RCS1165 // Unconstrained type parameter checked for null.

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, instance);
                writer.WriteBase64(Helpers.GetBuffer(ms), 0, (int)ms.Length);
            }
        }
Ejemplo n.º 7
0
        void IExtension.EndAppend(Stream stream, bool commit)
        {
            using (stream)
            {
                int len;
                if (commit && (len = (int)stream.Length) > 0)
                {
                    MemoryStream ms = (MemoryStream)stream;

                    if (buffer == null)
                    {   // allocate new buffer
                        buffer = ms.ToArray();
                    }
                    else
                    {   // resize and copy the data
                        // note: Array.Resize not available on CF
                        int    offset = buffer.Length;
                        byte[] tmp    = new byte[offset + len];
                        Buffer.BlockCopy(buffer, 0, tmp, 0, offset);

#if PORTABLE // no GetBuffer() - fine, we'll use Read instead
                        int  bytesRead;
                        long oldPos = ms.Position;
                        ms.Position = 0;
                        while (len > 0 && (bytesRead = ms.Read(tmp, offset, len)) > 0)
                        {
                            len    -= bytesRead;
                            offset += bytesRead;
                        }
                        if (len != 0)
                        {
                            throw new EndOfStreamException();
                        }
                        ms.Position = oldPos;
#else
                        Buffer.BlockCopy(Helpers.GetBuffer(ms), 0, tmp, offset, len);
#endif
                        buffer = tmp;
                    }
                }
            }
        }