Пример #1
0
        public void TypelessWrite(Amf3Object obj)
        {
            if (CheckObjectTable(obj))
            {
                return;
            }

            TypelessWrite(obj.ClassDef);

            StoreObject(obj);

            if (obj.ClassDef.Externalizable)
            {
                Write(obj["inner"]);
                return;
            }

            foreach (string i in obj.ClassDef.Properties)
            {
                Write(obj[i]);
            }

            if (obj.ClassDef.Dynamic)
            {
                var dynamicProperties =
                    from i in obj.Properties
                    where !obj.ClassDef.Properties.Contains(i.Key)
                    select i;

                foreach (var i in dynamicProperties)
                {
                    TypelessWrite(i.Key);
                    Write(i.Value);
                }

                TypelessWrite("");
            }
        }
Пример #2
0
        public void TypelessWrite(Amf3Object obj)
        {
            if (CheckObjectTable(obj))
                return;

			TypelessWrite(obj.ClassDef);

			StoreObject(obj);

            if (obj.ClassDef.Externalizable) {
                Write(obj["inner"]);
                return;
            }

            foreach (string i in obj.ClassDef.Properties) {
                Write(obj[i]);
            }

            if (obj.ClassDef.Dynamic) {
                var dynamicProperties =
                    from i in obj.Properties
                    where !obj.ClassDef.Properties.Contains(i.Key)
                    select i;

                foreach (var i in dynamicProperties) {
                    TypelessWrite(i.Key);
                    Write(i.Value);
                }

                TypelessWrite("");
            }
        }
Пример #3
0
 public void Write(Amf3Object obj)
 {
     Write(Amf3TypeCode.Object);
     TypelessWrite(obj);
 }
Пример #4
0
 private static object Resolve(Amf3Object root, string path)
 {
     return(root[path]);
 }
Пример #5
0
        public object ReadAmf3Object()
        {
            Amf3Object.Flags flags = (Amf3Object.Flags)ReadInteger();

            if ((flags & Amf3Object.Flags.Inline) == 0)
            {
                return(GetTableEntry(objectTable, ((int)flags) >> 1));
            }

            Amf3ClassDef classDef;

            if ((flags & Amf3Object.Flags.InlineClassDef) == 0)
            {
                classDef = GetTableEntry(traitTable, ((int)flags) >> 2);
            }
            else
            {
                classDef = ReadAmf3ClassDef(flags);
            }

            // get the serializer to use (start with the override serializer)
            IAmf3Serializer serializer = OverrideSerializer;

            if (serializer == null)
            {
                // no override? get serializer from class definition
                serializer = classDef.Serializer;
                if (serializer == null)
                {
                    // no serializer for class definition? use default serializer
                    serializer = DefaultSerializer;
                }
            }

            // fast path the Amf3Object serializer
            if (serializer is Amf3Object.Serializer)
            {
                var obj = new Amf3Object(classDef);

                // add to object table
                objectTable.Add(obj);

                // read all properties into object
                int count = classDef.Properties.Length;
                for (int i = 0; i < count; i++)
                {
                    ReadNextObject(ref obj.Values[i]);
                }

                // read dynamic properties
                if (classDef.Dynamic)
                {
                    string key = ReadString();
                    while (key != "")
                    {
                        var value = ReadNextObject();
                        obj.SetPropertyValueAsObject(key, value);
                        key = ReadString();
                    }
                }
                return(obj);
            }
            else
            {
                // create object instance using serializer
                object obj = serializer.NewInstance(classDef);

                // add to object table
                objectTable.Add(obj);

                // begin property remapping
                var reader = classDef.CreatePropertyReader();
                reader.BeginRead(this);
                // read object using serializer
                serializer.ReadObject(reader, obj);
                // end property remapping
                classDef.ReleasePropertyReader(reader);

                // read dynamic properties
                if (classDef.Dynamic)
                {
                    var    dc  = obj as PlayScript.IDynamicClass;
                    string key = ReadString();
                    while (key != "")
                    {
                        var value = ReadNextObject();
                        if (dc != null)
                        {
                            dc.__SetDynamicValue(key, value);
                        }
                        key = ReadString();
                    }
                }
                return(obj);
            }
        }
Пример #6
0
        public Amf3Object ReadAmf3Object()
        {
            Amf3Object.Flags flags = (Amf3Object.Flags)ReadInteger();

            if ((flags & Amf3Object.Flags.Inline) == 0)
            {
                return((Amf3Object)GetTableEntry(objectTable, ((int)flags) >> 1));
            }

            Amf3ClassDef classDef;

            if ((flags & Amf3Object.Flags.InlineClassDef) == 0)
            {
                classDef = GetTableEntry(traitTable, ((int)flags) >> 2);
            }
            else
            {
                bool   externalizable = ((flags & Amf3Object.Flags.Externalizable) != 0);
                bool   dynamic        = ((flags & Amf3Object.Flags.Dynamic) != 0);
                string name           = ReadString();

                if (externalizable && dynamic)
                {
                    throw new InvalidOperationException("Serialized objects cannot be both dynamic and externalizable");
                }

                List <string> properties = new List <string>();

                int members = ((int)flags) >> 4;

                for (int i = 0; i < members; i++)
                {
                    properties.Add(ReadString());
                }

                classDef = new Amf3ClassDef(name, properties, dynamic, externalizable);
                traitTable.Add(classDef);
            }

            Amf3Object obj = new Amf3Object(classDef);

            objectTable.Add(obj);

            if (classDef.Externalizable)
            {
                obj.Properties["inner"] = ReadNextObject();
                return(obj);
            }

            foreach (string i in classDef.Properties)
            {
                obj.Properties[i] = ReadNextObject();
            }

            if (classDef.Dynamic)
            {
                string key = ReadString();
                while (key != "")
                {
                    obj.Properties[key] = ReadNextObject();
                    key = ReadString();
                }
            }

            return(obj);
        }
Пример #7
0
 public Amf3ObjectDebugView(Amf3Object expando)
 {
     this.mObject = expando;
 }
Пример #8
0
 public KeyValuePairDebugView(Amf3Object expando, string key, bool isDynamic)
 {
     _expando   = expando;
     _key       = key;
     _isDynamic = isDynamic;
 }
Пример #9
0
 public void Write(Amf3Object obj)
 {
     Write(Amf3TypeCode.Object);
     TypelessWrite(obj);
 }
Пример #10
0
        public void TypelessWrite(Amf3Object obj)
        {
            if (CheckObjectTable(obj))
            {
                return;
            }

            int index;

            if (classDefTable.TryGetValue(obj.ClassDef, out index))
            {
                TypelessWrite((index << 2) | 1);
            }
            else
            {
                classDefTable[obj.ClassDef] = classDefTable.Count;

                Amf3Object.Flags flags = Amf3Object.Flags.Inline | Amf3Object.Flags.InlineClassDef;

                if (obj.ClassDef.Externalizable)
                {
                    flags |= Amf3Object.Flags.Externalizable;
                }
                if (obj.ClassDef.Dynamic)
                {
                    flags |= Amf3Object.Flags.Dynamic;
                }

                TypelessWrite((int)flags | (obj.ClassDef.Properties.Count << 4));

                TypelessWrite(obj.ClassDef.Name);

                foreach (string i in obj.ClassDef.Properties)
                {
                    TypelessWrite(i);
                }
            }

            objectTable[obj] = objectTable.Count;

            if (obj.ClassDef.Externalizable)
            {
                Write(obj["inner"]);
                return;
            }

            foreach (string i in obj.ClassDef.Properties)
            {
                Write(obj[i]);
            }

            if (obj.ClassDef.Dynamic)
            {
                var dynamicProperties =
                    from i in obj.Properties
                    where !obj.ClassDef.Properties.Contains(i.Key)
                    select i;

                foreach (var i in dynamicProperties)
                {
                    TypelessWrite(i.Key);
                    Write(i.Value);
                }

                TypelessWrite("");
            }
        }