Esempio n. 1
0
        public void DumpXml(XmlWriter writer)
        {
            writer.WriteStartElement("abc");
            writer.WriteAttributeString("version", Version.ToString());
            if (!string.IsNullOrEmpty(Name))
            {
                writer.WriteAttributeString("name", Name);
            }

            //constant pool
            if (AbcDumpService.DumpConstPool)
            {
                writer.WriteStartElement("constants");
                IntPool.DumpXml(writer);
                UIntPool.DumpXml(writer);
                DoublePool.DumpXml(writer);
                StringPool.DumpXml(writer);
                Namespaces.DumpXml(writer);
                NamespaceSets.DumpXml(writer);
                Multinames.DumpXml(writer);
                writer.WriteEndElement();
            }

            Methods.DumpXml(writer);
            //NOTE: metadata will be dumped with traits.
            //_metadata.DumpXml(writer);
            Instances.DumpXml(writer);
            //NOTE: classes are dumped with instances
            //_classes.DumpXml(writer);
            Scripts.DumpXml(writer);
            //NOTE: bodies are dumped with methods
            //_methodBodies.Dump(writer);
            writer.WriteEndElement();
        }
Esempio n. 2
0
        public void Write(SwfWriter writer)
        {
            writer.ABC = this;
            var ver = Version;

            writer.WriteUInt16((ushort)ver.Minor);
            writer.WriteUInt16((ushort)ver.Major);
            if (ver.Major == CurrentMajor && ver.Minor == CurrentMinor)
            {
                IntPool.Write(writer);
                UIntPool.Write(writer);
                DoublePool.Write(writer);
                StringPool.Write(writer);
                Namespaces.Write(writer);
                NamespaceSets.Write(writer);
                Multinames.Write(writer);

                Methods.Write(writer);
                Metadata.Write(writer);

                int n = Instances.Count;
                writer.WriteUIntEncoded((uint)n);
                Instances.Write(writer);
                Classes.Write(writer);

                Scripts.Write(writer);
                MethodBodies.Write(writer);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
        public void Read(SwfReader reader)
        {
            reader.ABC = this;
            int minor = reader.ReadUInt16();
            int major = reader.ReadUInt16();

            _version = new Version(major, minor);
            if (minor == CurrentMinor && major == CurrentMajor)
            {
                //NOTE: The "0" entry of each constant pool is not used.  If the count for a given pool says there are
                //NOTE: "n" entries in the pool, there are "n-1" entries in the file, corresponding to indices 1..(n-1).
                IntPool.Read(reader);
                UIntPool.Read(reader);

                SwfReader.CheckU30 = true;
                DoublePool.Read(reader);
                StringPool.Read(reader);
                Namespaces.Read(reader);
                NamespaceSets.Read(reader);
                Multinames.Read(reader);
                Methods.Read(reader);
                Metadata.Read(reader);

                int n = (int)reader.ReadUIntEncoded();
                Instances.Read(n, reader);
                Classes.Read(n, reader);
                for (int i = 0; i < n; ++i)
                {
                    var klass    = Classes[i];
                    var instance = Instances[i];
                    instance.Class             = klass;
                    klass.Instance             = instance;
                    klass.Initializer.Instance = instance;
                }

                Scripts.Read(reader);
                MethodBodies.Read(reader);
                SwfReader.CheckU30 = false;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
        public object ImportValue(object value)
        {
            if (value == null)
            {
                return(null);
            }
            if (IsUndefined(value))
            {
                return(Undefined);
            }

            var c = value as IAbcConst;

            if (c != null)
            {
                return(ImportConst(c));
            }

            var tc = Type.GetTypeCode(value.GetType());

            switch (tc)
            {
            case TypeCode.Object:
            {
                var instance = value as AbcInstance;
                if (instance != null)
                {
                    return(ImportInstance(instance));
                }

                var klass = value as AbcClass;
                if (klass != null)
                {
                    return(ImportInstance(klass.Instance));
                }

                var method = value as AbcMethod;
                if (method != null)
                {
                    return(ImportMethod(method));
                }

                throw new NotImplementedException();
            }

            case TypeCode.DBNull:
                throw new NotSupportedException();

            case TypeCode.Boolean:
                return(value);

            case TypeCode.SByte:
                return(IntPool.Define((sbyte)value));

            case TypeCode.Int16:
                return(IntPool.Define((short)value));

            case TypeCode.Int32:
                return(IntPool.Define((int)value));

            case TypeCode.Byte:
                return(UIntPool.Define((byte)value));

            case TypeCode.Char:
                return(UIntPool.Define((char)value));

            case TypeCode.UInt16:
                return(UIntPool.Define((ushort)value));

            case TypeCode.UInt32:
                return(UIntPool.Define((uint)value));

            case TypeCode.Int64:
                throw new NotImplementedException();

            case TypeCode.UInt64:
                throw new NotImplementedException();

            case TypeCode.Single:
                return(DefineSingle((float)value));

            case TypeCode.Double:
                return(DoublePool.Define((double)value));

            case TypeCode.String:
                return(DefineString((string)value));

            default:
                throw new NotImplementedException();
            }
        }
 public static void RestoreRxDouble(IRxStruct <double> rxDouble)
 {
     DoublePool.Restore(rxDouble);
 }
 public static IRxStruct <double> GetRxDouble()
 {
     return(DoublePool.Take());
 }
Esempio n. 7
0
        public AbcConst <double> DefineSingle(float value)
        {
            double v = value.ToDoublePrecisely();

            return(DoublePool.Define(v));
        }
Esempio n. 8
0
 /// <summary>
 /// Defines double constant.
 /// </summary>
 /// <param name="value">value of constant to define.</param>
 /// <returns></returns>
 public AbcConst <double> DefineDouble(double value)
 {
     return(DoublePool.Define(value));
 }