public void WriteData(AmfWriter writer, object obj)
 {
     if (!(obj is IExternalizable))
     {
         IDictionary <string, object> dictionary1;
         if ((dictionary1 = obj as IDictionary <string, object>) != null)
         {
             writer.WriteMarker(Amf3TypeMarkers.Array);
             writer.WriteAmf3AssociativeArray(dictionary1);
             return;
         }
         IDictionary dictionary2;
         if ((dictionary2 = obj as IDictionary) != null)
         {
             writer.WriteMarker(Amf3TypeMarkers.Dictionary);
             writer.WriteAmf3Dictionary(dictionary2);
         }
         IEnumerable source;
         if ((source = obj as IEnumerable) != null)
         {
             writer.WriteMarker(Amf3TypeMarkers.Array);
             writer.WriteAmf3Array((Array)source.Cast <object>().ToArray <object>());
             return;
         }
     }
     writer.WriteMarker(Amf3TypeMarkers.Object);
     writer.WriteAmf3Object(obj);
 }
Exemple #2
0
        public byte[] Encode()
        {
            using (var ms = new MemoryStream())
            {
                var aw = new AmfWriter(ms);

                aw.Write(CommandName);

                int transid = 0;
                switch (transid)
                {
                case -2:
                    transid = CurrentTransactionID++;
                    break;

                case -1:
                    transid = 0;
                    break;

                default:
                    transid = TransactionID;
                    break;
                }
                aw.Write(transid);

                aw.Write(CommandObject);

                if (Arguments != null)
                {
                    Arguments.ForEach(aw.Write);
                }

                return(ms.ToArray());
            }
        }
Exemple #3
0
 public static void WriteTo(AmfWriter writer, byte format, int chunkStreamId)
 {
     if (chunkStreamId <= 63)
     {
         //  0 1 2 3 4 5 6 7
         // +-+-+-+-+-+-+-+-+
         // |fmt|   cs id   |
         // +-+-+-+-+-+-+-+-+
         writer.WriteByte((byte)((format << 6) + chunkStreamId));
     }
     else if (chunkStreamId <= 320)
     {
         //  0             1
         //  0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // |fmt|    0     |   cs id - 64   |
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         writer.WriteByte((byte)(format << 6));
         writer.WriteByte((byte)(chunkStreamId - 64));
     }
     else
     {
         //  0               1               3
         //  0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // |fmt|     1    |           cs id - 64           |
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         writer.WriteByte((byte)((format << 6) | 1));
         writer.WriteByte((byte)((chunkStreamId - 64) & 0xff));
         writer.WriteByte((byte)((chunkStreamId - 64) >> 8));
     }
 }
        public void WriteData(AmfWriter writer, object obj)
        {
            var externalizable = obj is IExternalizable;

            // if IExternalizable then use those methods, even if it is a collection
            if (!externalizable)
            {
                IDictionary <string, object> stringDictionary;
                IDictionary dictionary;
                IEnumerable enumerable;

                if ((stringDictionary = obj as IDictionary <string, object>) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Array);
                    writer.WriteAmf3AssociativeArray(stringDictionary);
                    return;
                }
                if ((dictionary = obj as IDictionary) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Dictionary);
                    writer.WriteAmf3Dictionary(dictionary);
                }
                if ((enumerable = obj as IEnumerable) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Array);
                    writer.WriteAmf3Array(enumerable.Cast <object>().ToArray());
                    return;
                }
            }

            writer.WriteMarker(Amf3TypeMarkers.Object);
            writer.WriteAmf3Object(obj);
        }
        public void WriteData(AmfWriter writer, object obj)
        {
            var externalizable = obj is IExternalizable;

            // if IExternalizable then use those methods, even if it is a collection
            if (!externalizable)
            {
                IDictionary<string, object> stringDictionary;
                IDictionary dictionary;
                IEnumerable enumerable;

                if ((stringDictionary = obj as IDictionary<string, object>) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Array);
                    writer.WriteAmf3AssociativeArray(stringDictionary);
                    return;
                }
                if ((dictionary = obj as IDictionary) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Dictionary);
                    writer.WriteAmf3Dictionary(dictionary);
                }
                if ((enumerable = obj as IEnumerable) != null)
                {
                    writer.WriteMarker(Amf3TypeMarkers.Array);
                    writer.WriteAmf3Array(enumerable.Cast<object>().ToArray());
                    return;
                }
            }

            writer.WriteMarker(Amf3TypeMarkers.Object);
            writer.WriteAmf3Object(obj);
        }
Exemple #6
0
            public static void WriteTo(AmfWriter writer, Snapshot previous, Snapshot next, int chunkLength, Space <byte> message)
            {
                Kon.Assert(
                    !previous.Ready || previous.ChunkStreamId == next.ChunkStreamId,
                    "previous and next describe two different chunk streams");

                Kon.Assert(
                    next.MessageLength == message.Length,
                    "mismatch between reported message length and actual message length");

                // we don't write zero-length packets, and as state for `next` and `previous` won't match what our peer
                // sees if we pass a zero-length message here. zero-length sends should be filtered out at a higher level.
                Kon.Assert(
                    next.MessageLength != 0,
                    "message length cannot be zero");


                var header = GetInitialHeaderType();

                for (var i = 0; i < next.MessageLength; i += chunkLength)
                {
                    if (i == 0)
                    {
                        BasicHeader.WriteTo(writer, (byte)header, next.ChunkStreamId);
                        MessageHeader.WriteTo(writer, header, next);
                    }
                    else
                    {
                        BasicHeader.WriteTo(writer, (byte)MessageHeader.Type.Type3, next.ChunkStreamId);
                    }

                    var count = Math.Min(chunkLength, next.MessageLength - i);
                    var slice = message.Slice(i, count);

                    writer.WriteBytes(slice);
                }


                MessageHeader.Type GetInitialHeaderType()
                {
                    if (!previous.Ready || next.MessageStreamId != previous.MessageStreamId)
                    {
                        return(MessageHeader.Type.Type0);
                    }

                    if (next.MessageLength != previous.MessageLength || next.ContentType != previous.ContentType)
                    {
                        return(MessageHeader.Type.Type1);
                    }

                    if (next.Timestamp != previous.Timestamp)
                    {
                        return(MessageHeader.Type.Type2);
                    }

                    return(MessageHeader.Type.Type3);
                }
            }
 byte[] GetMessageBytes(RtmpEvent message, Action <AmfWriter, RtmpEvent> handler)
 {
     using (var stream = new MemoryStream())
         using (var messageWriter = new AmfWriter(stream, writer.SerializationContext, objectEncoding))
         {
             handler(messageWriter, message);
             return(stream.ToArray());
         }
 }
Exemple #8
0
        public void ApplyValues()
        {
            var writer = new AmfWriter();

            writer.WriteString("createStream");
            writer.WriteNumber(TransactionId);
            writer.WriteNull();
            Data = writer.GetByteArray();
        }
Exemple #9
0
        public FlvPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding)
        {
            this.objectEncoding = objectEncoding;
            this.writer         = writer;

            queuedPackets        = new ConcurrentQueue <RtmpPacket>();
            packetAvailableEvent = new AutoResetEvent(false);

            Continue = true;
        }
 public RtmpPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding)
 {
     this._objectEncoding       = objectEncoding;
     this._writer               = writer;
     this._rtmpHeaders          = new Dictionary <int, RtmpHeader>();
     this._rtmpPackets          = new Dictionary <int, RtmpPacket>();
     this._queuedPackets        = new ConcurrentQueue <RtmpPacket>();
     this._packetAvailableEvent = new AutoResetEvent(false);
     this.Continue              = true;
 }
        public RtmpPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding)
        {
            this.objectEncoding = objectEncoding;
            this.writer = writer;

            rtmpHeaders = new Dictionary<int, RtmpHeader>();
            queuedPackets = new ConcurrentQueue<RtmpPacket>();
            packetAvailableEvent = new AutoResetEvent(false);

            Continue = true;
        }
 private byte[] GetMessageBytes(RtmpEvent message, Action <AmfWriter, RtmpEvent> handler)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (AmfWriter amfWriter = new AmfWriter((Stream)memoryStream, this._writer.SerializationContext, this._objectEncoding))
         {
             handler(amfWriter, message);
             return(memoryStream.ToArray());
         }
     }
 }
 void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
 {
     if (o is Command)
     {
         WriteCommandOrData(writer, o, encoding);
     }
     else if (o is ByteData)
     {
         writer.WriteBytes(((ByteData)o).Data);
     }
 }
        public byte[] Encode()
        {
            using (var ms = new MemoryStream())
            {
                var aw = new AmfWriter(ms);

                aw.Write(Name);
                Data.ForEach(aw.Write);

                return ms.ToArray();
            }
        }
Exemple #15
0
        public byte[] Encode()
        {
            using (var ms = new MemoryStream())
            {
                var aw = new AmfWriter(ms);

                aw.Write(Name);
                Data.ForEach(aw.Write);

                return(ms.ToArray());
            }
        }
        public FlvPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding)
        {
            this._objectEncoding = objectEncoding;

            this._writer = writer;

            _packetQueue = new ConcurrentQueue <RtmpPacket>();

            _packetAvailableEvent = new AutoResetEvent(false);

            _started = true;
        }
        private void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
        {
            Command command = o as Command;

            if (command.MethodCall == null)
            {
                this.WriteCommandOrData(writer, o, encoding);
            }
            else
            {
                writer.WriteBytes(command.Buffer);
            }
        }
        void WriteData(AmfWriter writer, RtmpMessage o, ObjectEncoding encoding)
        {
            var command = o as Command;

            if (command.MethodCall == null)
            {
                WriteCommandOrData(writer, o, encoding);
            }
            else
            {
                writer.WriteBytes(command.Buffer);
            }
        }
Exemple #19
0
            static async Task WriteC2Async(Stream stream, uint remoteTime, Space <byte> remoteRandom)
            {
                var time = Ts.CurrentTime;

                var writer = new AmfWriter(new byte[FrameLength], EmptyContext);

                writer.WriteUInt32(remoteTime);  // "time":        a copy of s1 time
                writer.WriteUInt32(time);        // "time2":       current local time
                writer.WriteBytes(remoteRandom); // "random echo": a copy of s1 random

                await stream.WriteAsync(writer.Span);

                writer.Return();
            }
Exemple #20
0
            async Task WriteOnceAsync()
            {
                await reset.WaitAsync();

                while (!token.IsCancellationRequested && queue.TryDequeue(out var packet))
                {
                    // quickly estimate the maximum required length for this message. our estimation is as follows:
                    //
                    //     - [payload]
                    //         - take the message length, and add the chunk + message headers.
                    //
                    //     - [chunk headers]
                    //         - all chunk headers begin with a 0-3 byte header, indicating chunk stream id + message header
                    //             format.
                    //         - the one byte variant can encode chunk stream ids up to and including #63. we don't expect to
                    //             encode that many streams right now (unless a user library wants it), so we can assume 1 byte
                    //             chunk headers for now.
                    //~
                    //     - [message headers]
                    //         - the first message header must be a type 0 (new) header, which is 11 bytes large.
                    //         - all further message headers can be a type 3 (continuation) header, which is 0 bytes large.
                    //
                    //     - [total]
                    //         - message_length + chunk_count * 1 + 11
                    //
                    var packetLength       = packet.Span.Length;
                    var chunkCount         = packetLength / chunkLength + 1;
                    var estimatedMaxLength = packetLength + chunkCount + 11;
                    var writer             = new AmfWriter(estimatedMaxLength, context);

                    var previous = streams.TryGetValue(packet.StreamId, out var value) ? value : default(ChunkStream.Snapshot);
                    var next     = previous.Clone();

                    next.Ready           = true;
                    next.ContentType     = packet.Type;
                    next.ChunkStreamId   = packet.StreamId;
                    next.MessageStreamId = 0;
                    next.MessageLength   = packetLength;
                    next.Timestamp       = Ts.CurrentTime;

                    streams[packet.StreamId] = next;
                    ChunkStream.WriteTo(writer, previous, next, chunkLength, packet.Span);

                    await stream.WriteAsync(writer.Span, token);

                    writer.Return();
                }
            }
        public static Task WriteAsync(Stream stream, RtmpHandshake h, bool writeVersion)
        {
            using (var memoryStream = new MemoryStream())
            using (var writer = new AmfWriter(memoryStream, null))
            {
                if (writeVersion)
                    writer.WriteByte(h.Version);

                writer.WriteUInt32(h.Time);
                writer.WriteUInt32(h.Time2);
                writer.WriteBytes(h.Random);

                var buffer = memoryStream.ToArray();
                return stream.WriteAsync(buffer, 0, buffer.Length);
            }
        }
Exemple #22
0
        private void WriteCommandOrData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
        {
            var command    = o as Command;
            var methodCall = command.MethodCall;
            var isInvoke   = command is Invoke;

            // write the method name or result type (first section)
            var isRequest = methodCall.CallStatus == CallStatus.Request;
            var isResult  = methodCall.CallStatus == CallStatus.Result;

            if (isRequest)
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, methodCall.Name);
            }
            else
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, methodCall.IsSuccess ? "_result" : "_error");
            }

            if (isInvoke)
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, command.InvokeId);
                writer.WriteAmfItem(encoding, command.ConnectionParameters);
            }

            if (isRequest || isResult)
            {
                // write arguments
                foreach (var arg in methodCall.Parameters)
                {
                    writer.WriteAmfItem(encoding, arg);
                }
            }
            else if (isInvoke)
            {
                // write the result
                if (!methodCall.IsSuccess)
                {
                    methodCall.Parameters = new object[]
                    { new StatusAsObject(StatusCode.CallFailed, "error", "Call failed.") }
                }
                ;
                writer.WriteAmfItem(encoding, methodCall.Parameters);
            }
        }
    }
        private void WriteCommandOrData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
        {
            Command command    = o as Command;
            Method  methodCall = command.MethodCall;
            bool    flag1      = command is Invoke;
            bool    flag2      = methodCall.CallStatus == CallStatus.Request;
            bool    flag3      = methodCall.CallStatus == CallStatus.Result;

            if (flag2)
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, (object)methodCall.Name);
            }
            else
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, methodCall.IsSuccess ? (object)"_result" : (object)"_error");
            }
            if (flag1)
            {
                writer.WriteAmfItem(ObjectEncoding.Amf0, (object)command.InvokeId);
                writer.WriteAmfItem(encoding, command.ConnectionParameters);
            }
            if (flag2 | flag3)
            {
                foreach (object parameter in methodCall.Parameters)
                {
                    writer.WriteAmfItem(encoding, parameter);
                }
            }
            else
            {
                if (!flag1)
                {
                    return;
                }
                if (!methodCall.IsSuccess)
                {
                    methodCall.Parameters = new object[1]
                    {
                        (object)new StatusAsObject("NetConnection.Call.Failed", "error", "Call failed.")
                    }
                }
                ;
                writer.WriteAmfItem(encoding, (object)methodCall.Parameters);
            }
        }
    }
Exemple #24
0
            static async Task <(uint time, Space <byte> random)> WriteC1Async(Stream stream)
            {
                var writer = new AmfWriter(new byte[C1Length], EmptyContext);
                var random = RandomEx.GetBytes(RandomLength);
                var time   = Ts.CurrentTime;

                writer.WriteByte(3);       // rtmp version (constant 3) [c0]
                writer.WriteUInt32(time);  // time                      [c1]
                writer.WriteUInt32(0);     // zero                      [c1]
                writer.WriteBytes(random); // random bytes              [c1]

                await stream.WriteAsync(writer.Span);

                writer.Return();

                return(time, random);
            }
Exemple #25
0
        public static Task WriteAsync(Stream stream, RtmpHandshake h, bool writeVersion)
        {
            using (var memoryStream = new MemoryStream())
                using (var writer = new AmfWriter(memoryStream, null))
                {
                    if (writeVersion)
                    {
                        writer.WriteByte(h.Version);
                    }

                    writer.WriteUInt32(h.Time);
                    writer.WriteUInt32(h.Time2);
                    writer.WriteBytes(h.Random);

                    var buffer = memoryStream.ToArray();
                    return(stream.WriteAsync(buffer, 0, buffer.Length));
                }
        }
Exemple #26
0
        void WriteCommandOrData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
        {
            var command    = o as Command;
            var methodCall = command.MethodCall;
            var isInvoke   = command is Invoke;

            // write the method name or result type (first section)
            if (methodCall.Name == "@setDataFrame")
            {
                writer.WriteAmfItem(encoding, command.ConnectionParameters);
            }

            // write arguments
            foreach (var arg in methodCall.Parameters)
            {
                writer.WriteAmfItem(encoding, arg);
            }
        }
 public static Task WriteAsync(Stream stream, RtmpHandshake h, bool writeVersion)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (AmfWriter amfWriter = new AmfWriter((Stream)memoryStream, (SerializationContext)null))
         {
             if (writeVersion)
             {
                 amfWriter.WriteByte(h.Version);
             }
             amfWriter.WriteUInt32(h.Time);
             amfWriter.WriteUInt32(h.Time2);
             amfWriter.WriteBytes(h.Random);
             byte[] array = memoryStream.ToArray();
             return(stream.WriteAsync(array, 0, array.Length));
         }
     }
 }
Exemple #28
0
            public static void WriteTo(AmfWriter writer, Type type, ChunkStream.Snapshot stream)
            {
                var extendTs = stream.Timestamp >= ExtendedTimestampSentinel;
                var inlineTs = extendTs ? ExtendedTimestampSentinel : stream.Timestamp;

                switch (type)
                {
                case Type.Type0:
                    writer.WriteUInt24((uint)inlineTs);
                    writer.WriteUInt24((uint)stream.MessageLength);
                    writer.WriteByte((byte)stream.ContentType);
                    writer.WriteLittleEndianInt(stream.MessageStreamId);
                    if (extendTs)
                    {
                        writer.WriteUInt32(stream.Timestamp);
                    }
                    break;

                case Type.Type1:
                    writer.WriteUInt24((uint)inlineTs);
                    writer.WriteUInt24((uint)stream.MessageLength);
                    writer.WriteByte((byte)stream.ContentType);
                    if (extendTs)
                    {
                        writer.WriteUInt32(stream.Timestamp);
                    }
                    break;

                case Type.Type2:
                    writer.WriteUInt24((uint)inlineTs);
                    if (extendTs)
                    {
                        writer.WriteUInt32(stream.Timestamp);
                    }
                    break;

                case Type.Type3:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type));
                }
            }
        public void WriteData(AmfWriter writer, object obj)
        {
            IDictionary <string, object> dictionary;
            IEnumerable enumerable;

            if ((dictionary = obj as IDictionary <string, object>) != null)
            {
                // method writes type marker
                writer.WriteAmf0AssociativeArray(dictionary);
            }
            else if ((enumerable = obj as IEnumerable) != null)
            {
                writer.WriteMarker(Amf0TypeMarkers.StrictArray);
                writer.WriteAmf0Array(enumerable.Cast <object>().ToArray());
            }
            else
            {
                // method writes type marker
                writer.WriteAmf0TypedObject(obj);
            }
        }
        public void WriteData(AmfWriter writer, object obj)
        {
            IDictionary<string, object> dictionary;
            IEnumerable enumerable;

            if ((dictionary = obj as IDictionary<string, object>) != null)
            {
                // method writes type marker
                writer.WriteAmf0AssociativeArray(dictionary);
            }
            else if ((enumerable = obj as IEnumerable) != null)
            {
                writer.WriteMarker(Amf0TypeMarkers.StrictArray);
                writer.WriteAmf0Array(enumerable.Cast<object>().ToArray());
            }
            else
            {
                // method writes type marker
                writer.WriteAmf0TypedObject(obj);
            }
        }
Exemple #31
0
        public void ApplyValues()
        {
            var writer = new AmfWriter();

            writer.WriteString("connect");
            writer.WriteNumber(TransactionId);

            var obj = new AmfObject();
            obj.Strings.Add("app", App);
            obj.Strings.Add("flashver", FlashVersion);
            obj.Strings.Add("swfUrl", SwfUrl);
            obj.Strings.Add("tcUrl", ServerUrl);
            obj.Booleans.Add("fpad", Proxy);
            obj.Numbers.Add("audioCodecs", AudioCodecs);
            obj.Numbers.Add("videoCodecs", VideoCodecs);
            obj.Numbers.Add("videoFunction", VideoFunction);
            obj.Strings.Add("pageUrl", PageUrl);
            obj.Numbers.Add("objectEncoding", ObjectEncoding);

            writer.WriteObject(obj);
            Data = writer.GetByteArray();
        }
Exemple #32
0
        public void WriteData(AmfWriter writer, object obj)
        {
            IDictionary <string, object> dictionary;

            if ((dictionary = obj as IDictionary <string, object>) != null)
            {
                writer.WriteAmf0AssociativeArray(dictionary);
            }
            else
            {
                IEnumerable source;
                if ((source = obj as IEnumerable) != null)
                {
                    writer.WriteMarker(Amf0TypeMarkers.StrictArray);
                    writer.WriteAmf0Array((Array)source.Cast <object>().ToArray <object>());
                }
                else
                {
                    writer.WriteAmf0TypedObject(obj);
                }
            }
        }
Exemple #33
0
            // most rtmp servers we are interested in only support amf3 via an amf0 envelope
            static void WriteCommand(ObjectEncoding encoding, AmfWriter w, RtmpMessage message)
            {
                switch (message)
                {
                case Notify notify:
                    w.WriteBoxedAmf0Object(encoding, notify.Data);
                    break;

                case Invoke request:
                    w.WriteBoxedAmf0Object(encoding, request.MethodName);
                    w.WriteBoxedAmf0Object(encoding, request.InvokeId);
                    w.WriteBoxedAmf0Object(encoding, request.Headers);

                    foreach (var arg in request.Arguments ?? EmptyArray <object> .Instance)
                    {
                        w.WriteBoxedAmf0Object(encoding, arg);
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
 byte[] GetMessageBytes(RtmpEvent message, Action<AmfWriter, RtmpEvent> handler)
 {
     using (var stream = new MemoryStream())
     using (var messageWriter = new AmfWriter(stream, writer.SerializationContext, objectEncoding))
     {
         handler(messageWriter, message);
         return stream.ToArray();
     }
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteAmf0StringSpecial(obj as string);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteAmf0AsObject(obj as AsObject);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.Number);
     writer.WriteDouble(Convert.ToDouble(obj));
 }
Exemple #38
0
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.Integer);
     writer.WriteAmf3Int(Convert.ToInt32(obj));
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.Boolean);
     writer.WriteBoolean((bool)obj);
 }
Exemple #40
0
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteAmf3NumberSpecial(Convert.ToInt32(obj));
 }
Exemple #41
0
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.Array);
     writer.WriteAmf3Array(obj as Array);
 }
        public byte[] Encode()
        {
            using (var ms = new MemoryStream())
            {
                var aw = new AmfWriter(ms);

                aw.Write(CommandName);

                int transid = 0;
                switch (transid)
                {
                    case -2:
                        transid = CurrentTransactionID++;
                        break;
                    case -1:
                        transid = 0;
                        break;
                    default:
                        transid = TransactionID;
                        break;
                }
                aw.Write(transid);

                aw.Write(CommandObject);

                if (Arguments != null)
                {
                    Arguments.ForEach(aw.Write);
                }

                return ms.ToArray();
            }
        }
Exemple #43
0
 /// <summary>
 /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code.
 /// </summary>
 protected virtual void WriteBodyData(ObjectEncoding objectEncoding, AmfWriter writer)
 {
     object content = this.Content;
     writer.WriteAmfItem(objectEncoding, content);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.Xml);
     writer.WriteAmf0XDocument(obj as XDocument);
 }
        void WriteCommandOrData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
        {
            var command = o as Command;
            var methodCall = command.MethodCall;
            var isInvoke = command is Invoke;

            // write the method name or result type (first section)
            var isRequest = methodCall.CallStatus == CallStatus.Request;
            if (isRequest)
                writer.WriteAmfItem(encoding, methodCall.Name);
            else
                writer.WriteAmfItem(encoding, methodCall.IsSuccess ? "_result" : "_error");

            if (isInvoke)
            {
                writer.WriteAmfItem(encoding, command.InvokeId);
                writer.WriteAmfItem(encoding, command.ConnectionParameters);
            }

            if (isRequest)
            {
                // write arguments
                foreach (var arg in methodCall.Parameters)
                    writer.WriteAmfItem(encoding, arg);
            }
            else if (isInvoke)
            {
                // write the result
                if (!methodCall.IsSuccess)
                    methodCall.Parameters = new object[] { new StatusAsObject(StatusCode.CallFailed, "error", "Call failed.") };
                writer.WriteAmfItem(encoding, methodCall.Parameters);
            }
        }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.String);
     writer.WriteAmf3Utf(obj as string);
 }
 void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding)
 {
     var command = o as Command;
     if (command.MethodCall == null)
         WriteCommandOrData(writer, o, encoding);
     else
         writer.WriteBytes(command.Buffer);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.String);
     writer.WriteUtfPrefixed(((Guid)obj).ToString());
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.Number);
     writer.WriteDouble(Convert.ToDouble(obj));
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf0TypeMarkers.Date);
     writer.WriteAmf0DateTime((DateTime)obj);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteAmf3BoolSpecial((bool)obj);
 }
Exemple #52
0
 public DataOutput(AmfWriter writer)
 {
     this.writer = writer;
     this.objectEncoding = ObjectEncoding.Amf3;
 }
Exemple #53
0
        internal void WriteBody(ObjectEncoding objectEncoding, AmfWriter writer)
        {
            writer.Reset();
            if (this.Target == null)
                writer.WriteUtfPrefixed("null");
            else
                writer.WriteUtfPrefixed(this.Target);

            if (this.Response == null)
                writer.WriteUtfPrefixed("null");
            else
                writer.WriteUtfPrefixed(this.Response);
            writer.WriteInt32(-1);

            WriteBodyData(objectEncoding, writer);
        }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.ByteArray);
     // We're just writing a plain byte array, so we don't need a serialization context
     writer.WriteAmf3ByteArray(new ByteArray((byte[])obj, null));
 }
Exemple #55
0
 public DataOutput(AmfWriter writer)
 {
     this._writer        = writer;
     this.ObjectEncoding = ObjectEncoding.Amf3;
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.Xml);
     writer.WriteAmf3XElement(obj as XElement);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.Xml);
     writer.WriteAmf3XElement(obj as XElement);
 }
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.Object);
     writer.WriteAmf3Object(obj);
 }
Exemple #59
0
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.String);
     writer.WriteAmf3Utf(obj as string);
 }
Exemple #60
0
 public void WriteData(AmfWriter writer, object obj)
 {
     writer.WriteMarker(Amf3TypeMarkers.String);
     writer.WriteAmf3Utf(((Guid)obj).ToString());
 }