Ejemplo n.º 1
0
        /// <summary>
        /// Read a byte array.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="reader">
        /// The reader.
        /// </param>
        /// <param name="output">
        /// The output.
        /// </param>
        /// <remarks>
        /// Type declaration:
        ///     <c>
        ///         U29B-value = U29 (The first (low) bit is a flag with value 1.
        ///         The remaining 1 to 28 significant bits are used to encode the
        ///         byte-length of the ByteArray).
        ///         bytearray-type = bytearray-marker (U29O-ref | U29B-value *(U8))
        ///     </c>
        /// </remarks>
        private static void ReadByteArray(AmfContext context, AmfStreamReader reader, XmlWriter output = null)
        {
            int index, reference;

            if (ReadReference(context, reader, out index, out reference))
            {
                if (output != null)
                {
                    WriteReference(index, output);
                }

                return;
            }

            context.References.Track();

            // Get array length
            int length = reference >> 1;

            byte[] data  = length == 0 ? new byte[] { } : reader.ReadBytes(length);
            string value = Convert.ToBase64String(data);

            if (output != null)
            {
                output.WriteStartElement(AmfxContent.ByteArray);
                output.WriteValue(value);
                output.WriteEndElement();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Read a specified number of bytes of a string.
        /// </summary>
        /// <param name="reader">
        /// AMF reader.
        /// </param>
        /// <param name="length">
        /// Number of bytes to read.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private static string ReadUtf8(AmfStreamReader reader, uint length)
        {
            // Make sure that a null is never returned
            if (length == 0)
            {
                return(string.Empty);
            }

            byte[] data = reader.ReadBytes((int)length);

            // All strings are encoded in UTF-8)
            return(Encoding.UTF8.GetString(data));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read a specified number of bytes of a string.
        /// </summary>
        /// <param name="reader">
        /// AMF reader.
        /// </param>
        /// <param name="length">
        /// Number of bytes to read.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private static string ReadUtf8(AmfStreamReader reader, int length)
        {
            if (length < 0)
            {
                throw new ArgumentException(Errors.Amf3Deserializer_ReadString_NegativeLength, "length");
            }

            // Make sure that a null is never returned
            if (length == 0)
            {
                return(string.Empty);
            }

            byte[] data = reader.ReadBytes(length);

            // All strings are encoded in UTF-8
            return(Encoding.UTF8.GetString(data));
        }