Ejemplo n.º 1
0
        public AmfContext(AmfVersion version)
        {
            AmfVersion = version;

            References       = new List <AmfReference>();
            StringReferences = new List <string>();
            TraitsReferences = new List <AmfTypeTraits>();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AmfContext"/> class.
        /// </summary>
        /// <param name="version">
        /// The version.
        /// </param>
        public AmfContext(AmfVersion version)
        {
            this.AmfVersion = version;

            this.References       = new List <AmfReference>();
            this.StringReferences = new List <string>();
            this.TraitsReferences = new List <AmfTypeTraits>();
        }
Ejemplo n.º 3
0
        public AmfContext(AmfVersion version)
        {
            AmfVersion = version;

            References = new List<AmfReference>();
            StringReferences = new List<string>();
            TraitsReferences = new List<AmfTypeTraits>();
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Create default AMF decoding context.
        /// </summary>
        /// <returns>
        ///     The <see cref="AmfContext" />.
        /// </returns>
        protected AmfContext CreateDefaultContext()
        {
            // In mixed context enviroinments,
            // AMF0 is always used by default
            AmfVersion amfVersion = this.DecodingOptions.UseContextSwitch
                                        ? AmfVersion.Amf0
                                        : this.DecodingOptions.AmfVersion;

            return(new AmfContext(amfVersion));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Convert version enumeration value to an AMFX value.
        /// </summary>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ToAmfxName(this AmfVersion value)
        {
            switch (value)
            {
            case AmfVersion.Amf0:
                return(AmfxContent.VersionAmf0);

            case AmfVersion.Amf3:
                return(AmfxContent.VersionAmf3);

            default:
                throw new NotSupportedException("Version '" + value + "' is not supported.");
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create AMF decoder.
        /// </summary>
        /// <param name="version">AMF packet version.</param>
        /// <param name="options">Encoding options.</param>
        private static IAmfDecoder CreateDecoder(AmfVersion version, AmfEncodingOptions options)
        {
            switch (version)
            {
            case AmfVersion.Amf0:
                return(new Amf0Decoder(options));

            case AmfVersion.Amf3:
                return(new Amf3Decoder(options));

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Write AMF message version.
 /// </summary>
 static private void WriteAmfVersion(AmfStreamWriter writer, AmfVersion version)
 {
     writer.Write((ushort)version);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Write AMF message version.
 /// </summary>
 private static void WriteAmfVersion(AmfStreamWriter writer, AmfVersion version)
 {
     writer.Write((ushort)version);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Decode an AMF packet into an AMFX format.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <param name="output">
        /// The output.
        /// </param>
        /// <exception cref="InvalidDataException">
        /// Error during decoding.
        /// </exception>
        public void Decode(Stream stream, XmlWriter output)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException(Errors.AmfPacketReader_Read_StreamClosed, "stream");
            }

            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            try
            {
                var amfStreamReader = new AmfStreamReader(stream);

                AmfVersion  version = ReadPacketVersion(amfStreamReader);
                IAmfDecoder decoder = CreateDecoder(version, this._options);

                output.WriteStartDocument();
                output.WriteStartElement(AmfxContent.AmfxDocument, AmfxContent.Namespace);
                output.WriteAttributeString(AmfxContent.VersionAttribute, version.ToAmfxName());
                output.Flush();

                // Read headers
                uint headerCount = ReadDataCount(amfStreamReader);

                for (int i = 0; i < headerCount; i++)
                {
                    AmfHeaderDescriptor header = decoder.ReadPacketHeader(stream);

                    output.WriteStartElement(AmfxContent.PacketHeader);
                    output.WriteAttributeString(AmfxContent.PacketHeaderName, header.Name);
                    output.WriteAttributeString(
                        AmfxContent.PacketHeaderMustUnderstand,
                        header.MustUnderstand.ToString());
                    decoder.Decode(stream, output);
                    output.WriteEndElement();
                    output.Flush();
                }

                // Read messages
                uint messageCount = ReadDataCount(amfStreamReader);

                for (int i = 0; i < messageCount; i++)
                {
                    AmfMessageDescriptor body = decoder.ReadPacketBody(stream);

                    output.WriteStartElement(AmfxContent.PacketBody);
                    output.WriteAttributeString(AmfxContent.PacketBodyTarget, body.Target);
                    output.WriteAttributeString(AmfxContent.PacketBodyResponse, body.Response);
                    decoder.Decode(stream, output);
                    output.WriteEndElement();
                    output.Flush();
                }

                output.WriteEndElement();
                output.WriteEndDocument();
                output.Flush();
            }
            catch (Exception e)
            {
                output.Flush();
                throw new InvalidDataException(Errors.AmfPacketReader_DecodingError, e);
            }
        }
Ejemplo n.º 10
0
 public SerializationContext(AmfVersion version)
     : base(version)
 {
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Create AMF decoder.
        /// </summary>
        /// <param name="version">AMF packet version.</param>
        /// <param name="options">Encoding options.</param>
        private static IAmfDecoder CreateDecoder(AmfVersion version, AmfEncodingOptions options)
        {
            switch (version)
            {
                case AmfVersion.Amf0:
                    return new Amf0Decoder(options);

                case AmfVersion.Amf3:
                    return new Amf3Decoder(options);

                default:
                    throw new NotSupportedException();
            }
        }