Esempio n. 1
0
 public void SpecialConstructorInitializesProperties()
 {
     AMFMessage message = new AMFMessage(123, new AMFHeader[] { new AMFHeader() }, new AMFBody[] { new AMFBody() });
     Assert.AreEqual(123, message.Version);
     Assert.AreEqual(1, message.Bodies.Count);
     Assert.AreEqual(1, message.Headers.Count);
 }
Esempio n. 2
0
        /// <summary>
        /// Writes an AMF message to an output stream and bubbles up exceptions.
        /// </summary>
        /// <param name="output">The output stream</param>
        /// <param name="message">The message to write</param>
        private static void UncheckedWriteAMFMessage(AMFDataOutput output, AMFMessage message)
        {
            output.WriteUnsignedShort(message.Version);

            output.WriteUnsignedShort((ushort)message.Headers.Count);
            foreach (AMFHeader header in message.Headers)
                WriteAMFHeader(output, header);

            output.WriteUnsignedShort((ushort)message.Bodies.Count);
            foreach (AMFBody body in message.Bodies)
                WriteAMFBody(output, body);
        }
Esempio n. 3
0
        /// <summary>
        /// Writes an AMF message to an output stream.
        /// </summary>
        /// <param name="output">The output stream</param>
        /// <param name="message">The message to write</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="output"/> or
        /// <paramref name="message"/> is null</exception>
        /// <exception cref="AMFException">Thrown if an exception occurred while writing the message</exception>
        public static void WriteAMFMessage(AMFDataOutput output, AMFMessage message)
        {
            if (output == null)
                throw new ArgumentNullException("output");
            if (message == null)
                throw new ArgumentNullException("message");

            try
            {
                UncheckedWriteAMFMessage(output, message);
            }
            catch (Exception ex)
            {
                throw new AMFException("An exception occurred while writing an AMF message to the stream.", ex);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Writes an AMF message to an output stream and bubbles up exceptions.
        /// </summary>
        /// <param name="output">The output stream</param>
        /// <param name="message">The message to write</param>
        private static void UncheckedWriteAMFMessage(AMFDataOutput output, AMFMessage message)
        {
            output.WriteUnsignedShort(message.Version);

            output.WriteUnsignedShort((ushort)message.Headers.Count);
            foreach (AMFHeader header in message.Headers)
            {
                WriteAMFHeader(output, header);
            }

            output.WriteUnsignedShort((ushort)message.Bodies.Count);
            foreach (AMFBody body in message.Bodies)
            {
                WriteAMFBody(output, body);
            }
        }
Esempio n. 5
0
        public void CanGetAndSetProperties()
        {
            AMFMessage message = new AMFMessage();

            Assert.AreEqual(0, message.Version);
            message.Version = 123;
            Assert.AreEqual(123, message.Version);

            Assert.AreEqual(0, message.Bodies.Count);
            message.Bodies.Add(new AMFBody());
            Assert.AreEqual(1, message.Bodies.Count);

            Assert.AreEqual(0, message.Headers.Count);
            message.Headers.Add(new AMFHeader());
            Assert.AreEqual(1, message.Headers.Count);
        }
        public void WriteMessageWrapsErrorsWithAMFException()
        {
            // Deliberately inject an exception.
            // This should be caught and wrapped by the AMFMessageWriter code.
            IASValue mockValue = Mocks.CreateMock<IASValue>();
            mockValue.AcceptVisitor(serializer, null);
            LastCall.IgnoreArguments().Throw(new Exception("Something bad happened."));

            Mocks.ReplayAll();

            AMFMessage message = new AMFMessage();

            message.Version = 0x1234;
            message.Headers.Add(new AMFHeader("abc", true, mockValue));

            AMFMessageWriter.WriteAMFMessage(output, message);
        }
Esempio n. 7
0
        /// <summary>
        /// Writes an AMF message to an output stream.
        /// </summary>
        /// <param name="output">The output stream</param>
        /// <param name="message">The message to write</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="output"/> or
        /// <paramref name="message"/> is null</exception>
        /// <exception cref="AMFException">Thrown if an exception occurred while writing the message</exception>
        public static void WriteAMFMessage(AMFDataOutput output, AMFMessage message)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            try
            {
                UncheckedWriteAMFMessage(output, message);
            }
            catch (Exception ex)
            {
                throw new AMFException("An exception occurred while writing an AMF message to the stream.", ex);
            }
        }
        public void WriteMessageWithMultipleHeadersAndBodies()
        {
            AMFMessage message = new AMFMessage();

            message.Version = 0x1234;
            message.Headers.Add(new AMFHeader("abc", true, new ASString("123")));
            message.Headers.Add(new AMFHeader("def", false, null));
            message.Bodies.Add(new AMFBody("to", "from", new ASString("123")));
            message.Bodies.Add(new AMFBody("to", "from", null));
            
            AMFMessageWriter.WriteAMFMessage(output, message);

            CollectionAssert.AreElementsEqual(new byte[] {
                0x12, 0x34, // version
                0x00, 0x02, // header count
                0x00, 0x03, 0x61, 0x62, 0x63, 0x01, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x03, 0x31, 0x32, 0x33, // header abc
                0x00, 0x03, 0x64, 0x65, 0x66, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, // header def
                0x00, 0x02, // body count
                0x00, 0x02, 0x74, 0x6f, 0x00, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x03, 0x31, 0x32, 0x33, // first body
                0x00, 0x02, 0x74, 0x6f, 0x00, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0xff, 0xff, 0xff, 0xff, 0x05 // second body
            }, stream.ToArray());
        }
Esempio n. 9
0
 /// <summary>
 /// Sets the AMF request message.
 /// </summary>
 /// <param name="message">The message</param>
 public void SetMessage(AMFMessage message)
 {
     this.message = message;
 }
Esempio n. 10
0
 /// <summary>
 /// Prepares the response message in response to some request.
 /// </summary>
 /// <param name="requestMessage">The original request message</param>
 public void PrepareResponseMessage(AMFMessage requestMessage)
 {
     message = new AMFMessage(requestMessage.Version, new List<AMFHeader>(), new List<AMFBody>());
 }