AmfTrait ReadTrait(int refIndex) { // Stored by ref? bool isInstance = PopFlag(ref refIndex); if (!isInstance) { return(_traitLookup[refIndex]); } // Stored by value var result = new AmfTrait(); _traitLookup.Add(result); result.IsExternalizable = PopFlag(ref refIndex); result.IsDynamic = PopFlag(ref refIndex); result.Name = ReadString(); result.Properties = new string[refIndex]; for (var i = 0; i < result.Properties.Length; i++) { result.Properties[i] = ReadString(); } // Special hack for serializable traits return(result); }
void WriteTrait(AmfTrait trait) { // By reference or by instance? int index; if (_traitLookup.TryGetValue(trait, out index)) { WriteU29((index << 2) | 1); return; } _traitLookup.Add(trait, _traitLookup.Count); // Index and flags index = 3; // 0b0011. trait by instance, obj by instance if (trait.IsExternalizable) { index |= 4; // 0b0100 } if (trait.IsDynamic) { index |= 8; // 0b1000 } index |= (trait.Properties.Length << 4); WriteU29(index); // Name and properties WriteString(trait.Name); foreach (var name in trait.Properties) { WriteString(name); } }
public AmfObject(AmfTypes type) { Type = type; if (type == AmfTypes.Object) { Trait = new AmfTrait { Name = "", IsDynamic = true, Properties = new string[0] }; } }