Beispiel #1
0
 public CommandAMF0Message(RTMPMessage x)
     : base(x)
 {
     using (var reader = new AMF0Reader(new MemoryStream(x.Body))) {
         this.commandName   = (string)reader.ReadValue();
         this.transactionId = (int)reader.ReadValue();
         this.commandObject = reader.ReadValue();
         if (AMFValue.IsNull(CommandObject))
         {
             this.commandObject = null;
         }
         var args = new List <AMFValue>();
         while (reader.BaseStream.Position < reader.BaseStream.Length)
         {
             args.Add(reader.ReadValue());
         }
         this.arguments = args;
     }
 }
Beispiel #2
0
        public static CommandMessage Create(
            int version,
            long timestamp,
            long stream_id,
            string command_name,
            int transaction_id,
            AMFValue command_object,
            params AMFValue[] arguments)
        {
            switch (version)
            {
            case 0:
                return(new CommandAMF0Message(timestamp, stream_id, command_name, transaction_id, command_object, arguments));

            case 3:
                return(new CommandAMF3Message(timestamp, stream_id, command_name, transaction_id, command_object, arguments));

            default:
                throw new ArgumentException("Unsupported serialize version", "version");
            }
        }
Beispiel #3
0
        private static byte[] CreateBody(
            string command_name,
            int transaction_id,
            AMFValue command_object,
            IEnumerable <AMFValue> arguments)
        {
            var s = new MemoryStream();

            using (var writer = new AMF0Writer(s)) {
                writer.WriteString(command_name);
                writer.WriteNumber(transaction_id);
                writer.WriteValue(command_object);
                if (arguments != null)
                {
                    foreach (var arg in arguments)
                    {
                        writer.WriteValue(arg);
                    }
                }
            }
            return(s.ToArray());
        }