Пример #1
0
        private static void DecodeSharedObject(SharedObjectMessage so, ByteBuffer stream, RtmpReader reader)
        {
            while (stream.HasRemaining)
            {
                SharedObjectEventType type = SharedObjectTypeMapping.ToType(reader.ReadByte());
                string key  = null;
                object obj2 = null;
                int    @int = stream.GetInt();
                switch (type)
                {
                case SharedObjectEventType.CLIENT_STATUS:
                    key  = reader.ReadString();
                    obj2 = reader.ReadString();
                    break;

                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                    key  = reader.ReadString();
                    obj2 = reader.ReadData();
                    break;

                default:
                    if ((type != SharedObjectEventType.SERVER_SEND_MESSAGE) && (type != SharedObjectEventType.CLIENT_SEND_MESSAGE))
                    {
                        if (@int > 0)
                        {
                            key = reader.ReadString();
                            if (@int > (key.Length + 2))
                            {
                                obj2 = reader.ReadData();
                            }
                        }
                    }
                    else
                    {
                        int position = (int)stream.Position;
                        key = reader.ReadData() as string;
                        List <object> list = new List <object>();
                        while ((stream.Position - position) < @int)
                        {
                            object item = reader.ReadData();
                            list.Add(item);
                        }
                        obj2 = list;
                    }
                    break;
                }
                so.AddEvent(type, key, obj2);
            }
        }
        static void DecodeSharedObject(SharedObjectMessage so, ByteBuffer stream, RtmpReader reader)
        {
            // Parse request body
            while (stream.HasRemaining)
            {
                byte typeCode = reader.ReadByte();
                SharedObjectEventType type = SharedObjectTypeMapping.ToType(typeCode);
                string key   = null;
                object value = null;

                int length = stream.GetInt();                //reader.ReadInt32();
                switch (type)
                {
                case SharedObjectEventType.CLIENT_STATUS:
                    // Status code
                    key = reader.ReadString();
                    // Status level
                    value = reader.ReadString();
                    break;

                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                {
                    key   = reader.ReadString();
                    value = reader.ReadData();

                    /*
                     *                      key = null;
                     *                      // Map containing new attribute values
                     *                      Hashtable map = new Hashtable();
                     *                      int start = (int)stream.Position;
                     *                      while((int)stream.Position - start < length)
                     *                      {
                     *                              string tmp = reader.ReadString();
                     *                              map[tmp] = reader.ReadData();
                     *                      }
                     *                      value = map;
                     */
                }
                break;

                default:
                    if (type != SharedObjectEventType.SERVER_SEND_MESSAGE && type != SharedObjectEventType.CLIENT_SEND_MESSAGE)
                    {
                        if (length > 0)
                        {
                            key = reader.ReadString();
                            if (length > key.Length + 2)
                            {
                                value = reader.ReadData();
                            }
                        }
                    }
                    else
                    {
                        int start = (int)stream.Position;
                        // the "send" event seems to encode the handler name
                        // as complete AMF string including the string type byte
                        key = reader.ReadData() as string;
                        // read parameters
#if !(NET_1_1)
                        List <object> paramList = new List <object>();
#else
                        ArrayList paramList = new ArrayList();
#endif
                        while (stream.Position - start < length)
                        {
                            object tmp = reader.ReadData();
                            paramList.Add(tmp);
                        }
                        value = paramList;
                    }
                    break;
                }
                so.AddEvent(type, key, value);
            }
        }
Пример #3
0
        private static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output)
        {
            RtmpWriter writer = new RtmpWriter(output);

            writer.WriteUTF(so.Name);
            writer.WriteInt32(so.Version);
            writer.WriteInt32(so.IsPersistent ? 2 : 0);
            writer.WriteInt32(0);
            int num2 = 0;

            foreach (ISharedObjectEvent event2 in so.Events)
            {
                int  position;
                byte num3 = SharedObjectTypeMapping.ToByte(event2.Type);
                switch (event2.Type)
                {
                case SharedObjectEventType.SERVER_CONNECT:
                case SharedObjectEventType.CLIENT_CLEAR_DATA:
                case SharedObjectEventType.CLIENT_INITIAL_DATA:
                {
                    writer.WriteByte(num3);
                    writer.WriteInt32(0);
                    continue;
                }

                case SharedObjectEventType.SERVER_DISCONNECT:
                {
                    writer.WriteByte(num3);
                    output.PutInt((int)output.Position, 0);
                    continue;
                }

                case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                {
                    if (event2.Key != null)
                    {
                        break;
                    }
                    IDictionary dictionary = event2.Value as IDictionary;
                    foreach (DictionaryEntry entry in dictionary)
                    {
                        writer.WriteByte(num3);
                        position = (int)output.Position;
                        output.Skip(4);
                        string key  = entry.Key as string;
                        object data = entry.Value;
                        writer.WriteUTF(key);
                        writer.WriteData(context.ObjectEncoding, data);
                        num2 = (((int)output.Position) - position) - 4;
                        output.PutInt(position, num2);
                    }
                    continue;
                }

                case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_DELETE_DATA:
                case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteUTF(event2.Key);
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                case SharedObjectEventType.SERVER_SEND_MESSAGE:
                case SharedObjectEventType.CLIENT_SEND_MESSAGE:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteData(context.ObjectEncoding, event2.Key);
                    foreach (object obj3 in event2.Value as IList)
                    {
                        writer.WriteData(context.ObjectEncoding, obj3);
                    }
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                case SharedObjectEventType.CLIENT_STATUS:
                {
                    writer.WriteByte(num3);
                    position = (int)output.Position;
                    output.Skip(4);
                    writer.WriteUTF(event2.Key);
                    writer.WriteUTF(event2.Value as string);
                    num2 = (((int)output.Position) - position) - 4;
                    output.PutInt(position, num2);
                    continue;
                }

                default:
                    goto Label_033A;
                }
                writer.WriteByte(num3);
                position = (int)output.Position;
                output.Skip(4);
                writer.WriteUTF(event2.Key);
                writer.WriteData(context.ObjectEncoding, event2.Value);
                num2 = (((int)output.Position) - position) - 4;
                output.PutInt(position, num2);
                continue;
Label_033A:
                _log.Error("Unknown event " + event2.Type.ToString());
                writer.WriteByte(num3);
                position = (int)output.Position;
                output.Skip(4);
                if (event2.Key != null)
                {
                    writer.WriteUTF(event2.Key);
                    writer.WriteData(context.ObjectEncoding, event2.Value);
                }
                num2 = (((int)output.Position) - position) - 4;
                output.PutInt(position, num2);
            }
        }
Пример #4
0
        static void EncodeSharedObject(RtmpContext context, ISharedObjectMessage so, ByteBuffer output)
        {
            RtmpWriter writer = new RtmpWriter(output);

            //Set legacy collection flag from context
            writer.UseLegacyCollection = context.UseLegacyCollection;
            writer.UseLegacyThrowable  = context.UseLegacyThrowable;

            writer.WriteUTF(so.Name);
            // SO version
            writer.WriteInt32(so.Version);
            // Encoding (this always seems to be 2 for persistent shared objects)
            writer.WriteInt32(so.IsPersistent ? 2 : 0);
            // unknown field
            writer.WriteInt32(0);

            int mark, len = 0;

            foreach (ISharedObjectEvent sharedObjectEvent in so.Events)
            {
                byte type = SharedObjectTypeMapping.ToByte(sharedObjectEvent.Type);
                switch (sharedObjectEvent.Type)
                {
                case SharedObjectEventType.SERVER_CONNECT:
                case SharedObjectEventType.CLIENT_INITIAL_DATA:
                case SharedObjectEventType.CLIENT_CLEAR_DATA:
                    writer.WriteByte(type);
                    writer.WriteInt32(0);
                    break;

                case SharedObjectEventType.SERVER_DELETE_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_DELETE_DATA:
                case SharedObjectEventType.CLIENT_UPDATE_ATTRIBUTE:
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    writer.WriteUTF(sharedObjectEvent.Key);
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.SERVER_SET_ATTRIBUTE:
                case SharedObjectEventType.CLIENT_UPDATE_DATA:
                    if (sharedObjectEvent.Key == null)
                    {
                        // Update multiple attributes in one request
                        IDictionary initialData = sharedObjectEvent.Value as IDictionary;
                        foreach (DictionaryEntry entry in initialData)
                        {
                            writer.WriteByte(type);
                            mark = (int)output.Position;
                            output.Skip(4);                                     // we will be back
                            string key   = entry.Key as string;
                            object value = entry.Value;
                            writer.WriteUTF(key);
                            writer.WriteData(context.ObjectEncoding, value);

                            len = (int)output.Position - mark - 4;
                            output.PutInt(mark, len);
                        }
                    }
                    else
                    {
                        writer.WriteByte(type);
                        mark = (int)output.Position;
                        output.Skip(4);                                 // we will be back
                        writer.WriteUTF(sharedObjectEvent.Key);
                        writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
                        //writer.WriteData(sharedObjectEvent.Value);

                        len = (int)output.Position - mark - 4;
                        output.PutInt(mark, len);
                    }
                    break;

                case SharedObjectEventType.CLIENT_SEND_MESSAGE:
                case SharedObjectEventType.SERVER_SEND_MESSAGE:
                    // Send method name and value
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back

                    // Serialize name of the handler to call
                    writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Key);
                    //writer.WriteUTF(sharedObjectEvent.Key);
                    // Serialize the arguments
                    foreach (object arg in sharedObjectEvent.Value as IList)
                    {
                        writer.WriteData(context.ObjectEncoding, arg);
                    }
                    //writer.WriteData(sharedObjectEvent.Value as IList);
                    len = (int)output.Position - mark - 4;
                    //output.PutInt(mark, len);
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.CLIENT_STATUS:
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    writer.WriteUTF(sharedObjectEvent.Key);
                    writer.WriteUTF(sharedObjectEvent.Value as string);
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;

                case SharedObjectEventType.SERVER_DISCONNECT:
                    writer.WriteByte(type);
                    output.PutInt((int)output.Position, 0);
                    break;

                default:
#if !SILVERLIGHT
                    _log.Error("Unknown event " + sharedObjectEvent.Type.ToString());
#endif
                    writer.WriteByte(type);
                    mark = (int)output.Position;
                    output.Skip(4);                             // we will be back
                    if (sharedObjectEvent.Key != null)
                    {
                        writer.WriteUTF(sharedObjectEvent.Key);
                        writer.WriteData(context.ObjectEncoding, sharedObjectEvent.Value);
                    }
                    len = (int)output.Position - mark - 4;
                    output.PutInt(mark, len);
                    break;
                }
            }
        }