public void WriteTraitsInfo(TraitsInfo value) { WriteU30(value.Name.Index); WriteByte((Byte)((Byte)(value.Attributes) << 4 | (Byte)value.Kind)); switch (value.Kind) { case TraitKind.Slot: case TraitKind.Const: TraitField traitField = value.TraitField; WriteU30(traitField.SlotId); WriteU30(traitField.TypeName == null ? 0 : traitField.TypeName.Index); WriteU30(traitField.ValueIndex); if (traitField.ValueIndex > 0) { WriteByte((Byte)traitField.ValueKind); } break; case TraitKind.Method: TraitMethod traitMethod = value.TraitMethod; WriteU30(traitMethod.DispId); WriteU30(traitMethod.Method.Index); break; case TraitKind.Getter: TraitGetter traitGetter = value.Trait as TraitGetter; WriteU30(traitGetter.DispId); WriteU30(traitGetter.Method.Index); break; case TraitKind.Setter: TraitSetter traitSetter = value.Trait as TraitSetter; WriteU30(traitSetter.DispId); WriteU30(traitSetter.Method.Index); break; case TraitKind.Class: TraitClass traitClass = value.Trait as TraitClass; WriteU30(traitClass.SlotId); WriteU30(traitClass.Class.Index); break; case TraitKind.Function: TraitFunction traitFunction = value.Trait as TraitFunction; WriteU30(traitFunction.SlotId); WriteU30(traitFunction.Function.Index); break; default: throw new ArgumentOutOfRangeException(); } if (value.Attributes.HasFlag(TraitAttributes.Metadata)) { WriteU30Array(value.MetadataArray, true); } }
public TraitsInfo ReadTraitsInfo(Abc abc) { TraitsInfo result = new TraitsInfo(); result.Name = abc.ConstantPool.GetMultinameAt(ReadU30()); byte kindAndAttribute = ReadByte(); result.Kind = (TraitKind)(kindAndAttribute & 0xf); result.Attributes = (TraitAttributes)(kindAndAttribute >> 4); switch (result.Kind) { case TraitKind.Slot: case TraitKind.Const: var traitField = new TraitField(); traitField.SlotId = ReadU30(); traitField.TypeName = abc.ConstantPool.GetMultinameAt(ReadU30()); traitField.ValueIndex = ReadU30(); if (traitField.ValueIndex > 0) { traitField.ValueKind = (ValueKind)ReadByte(); } result.Trait = traitField; break; case TraitKind.Method: var traitMethod = new TraitMethod(); traitMethod.DispId = ReadU30(); traitMethod.Method = abc.MethodArray[ReadU30()]; result.Trait = traitMethod; break; case TraitKind.Getter: var traitGetter = new TraitGetter(); traitGetter.DispId = ReadU30(); traitGetter.Method = abc.MethodArray[ReadU30()]; result.Trait = traitGetter; break; case TraitKind.Setter: var traitSetter = new TraitSetter(); traitSetter.DispId = ReadU30(); traitSetter.Method = abc.MethodArray[ReadU30()]; result.Trait = traitSetter; break; case TraitKind.Class: var traitClass = new TraitClass(); traitClass.SlotId = ReadU30(); traitClass.Class = abc.AbcClassArray[ReadU30()].ClassInfo; result.Trait = traitClass; break; case TraitKind.Function: var traitFunction = new TraitFunction(); traitFunction.SlotId = ReadU30(); traitFunction.Function = abc.MethodArray[ReadU30()]; result.Trait = traitFunction; break; default: throw new ArgumentOutOfRangeException(); } if (result.Attributes.HasFlag(TraitAttributes.Metadata)) { result.MetadataArray = ReadU30Array(ReadU30()); } return(result); }