コード例 #1
0
ファイル: ASTrait.cs プロジェクト: scottstamp/TanjiCore
        public ASTrait(ABCFile abc, FlashReader input)
            : this(abc)
        {
            QNameIndex = input.ReadInt30();

            byte bitContainer = input.ReadByte();
            Kind       = (TraitKind)(bitContainer & 0x0F);
            Attributes = (TraitAttributes)(bitContainer >> 4);

            Id = input.ReadInt30();
            switch (Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Constant:
            {
                TypeIndex  = input.ReadInt30();
                ValueIndex = input.ReadInt30();
                if (ValueIndex != 0)
                {
                    ValueKind = (ConstantKind)input.ReadByte();
                }
                break;
            }

            case TraitKind.Method:
            case TraitKind.Getter:
            case TraitKind.Setter:
            {
                MethodIndex  = input.ReadInt30();
                Method.Trait = this;
                break;
            }

            case TraitKind.Class:
            {
                ClassIndex = input.ReadInt30();
                break;
            }

            case TraitKind.Function:
            {
                FunctionIndex = input.ReadInt30();
                break;
            }
            }

            if (Attributes.HasFlag(TraitAttributes.Metadata))
            {
                MetadataIndices.Capacity = input.ReadInt30();
                for (int i = 0; i < MetadataIndices.Capacity; i++)
                {
                    int metadatumIndex = input.ReadInt30();
                    MetadataIndices.Add(metadatumIndex);
                }
            }
        }
コード例 #2
0
        public ASTrait(ABCFile abc, FlashReader reader)
            : this(abc)
        {
            TypeIndex = reader.Read7BitEncodedInt();
            byte trueKind = reader.ReadByte();

            var traitType = (TraitType)(trueKind & 0xF);
            Attributes = (TraitAttributes)(trueKind >> 4);
            #region Trait Reading
            switch (traitType)
            {
            case TraitType.Slot:
            case TraitType.Constant:
            {
                Data = new SlotConstantTrait(abc, reader, traitType)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            case TraitType.Method:
            case TraitType.Getter:
            case TraitType.Setter:
            {
                Data = new MethodGetterSetterTrait(abc, reader, traitType)
                {
                    ObjName = Type.ObjName
                };

                ((MethodGetterSetterTrait)Data).Method.ObjName = ObjName;
                break;
            }

            case TraitType.Class:
            {
                Data = new ClassTrait(abc, reader)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            case TraitType.Function:
            {
                Data = new FunctionTrait(abc, reader)
                {
                    ObjName = Type.ObjName
                };
                break;
            }

            default:
                throw new Exception($"Invalid {nameof(ASTrait)} type: " + traitType);
            }
            #endregion

            if ((Attributes & TraitAttributes.Metadata) != 0)
            {
                MetadataIndices.Capacity = reader.Read7BitEncodedInt();
            }

            for (int i = 0; i < MetadataIndices.Capacity; i++)
            {
                MetadataIndices.Add(reader.Read7BitEncodedInt());
            }
        }