Exemplo n.º 1
0
        void WriteTrait(AmfTrait trait)
        {
            // By reference or by instance?
            if (_traitLookup.TryGetValue(trait, out int 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);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public AmfObject(AmfTypes type)
        {
            Type = type;

            if (type == AmfTypes.Object)
            {
                Trait = new AmfTrait {
                    Name = "", IsDynamic = true, Properties = new string[0]
                };
            }
        }