Esempio n. 1
0
        public static void WriteComponent(ref Library.Writer writer, SLComponent com, Predicate <SLComponent> filter = null)
        {
            var comList = new Dictionary <int, SLComponent>();

            com.Traversal(comList);

            if (null != filter)
            {
                unsafe
                {
                    var tempList = stackalloc int[comList.Count];
                    var tempIdx  = 0;
                    var iter     = comList.GetEnumerator();
                    while (iter.MoveNext())
                    {
                        if (filter(iter.Current.Value))
                        {
                            tempList[tempIdx++] = iter.Current.Key;
                        }
                    }

                    while (tempIdx > 0)
                    {
                        comList.Remove(tempList[--tempIdx]);
                    }
                }
            }

            writer.WriteInt(comList.Count);
            var pairIter = comList.GetEnumerator();

            while (pairIter.MoveNext())
            {
                writer.WriteInt((int)pairIter.Current.Value.Type);
                writer.WriteInt(pairIter.Current.Key);
            }

            var ctxList = new Dictionary <int, object>();

            pairIter = comList.GetEnumerator();
            while (pairIter.MoveNext())
            {
                var com2 = pairIter.Current.Value;
                com2.OnSerialized(ref writer);
                if (null != com2.Context && Attribute.IsDefined(com2.Context.GetType(), typeof(SerializableAttribute)))
                {
                    ctxList.Add(pairIter.Current.Key, com2.Context);
                }
            }

            writer.WriteInt(ctxList.Count);
            if (ctxList.Count > 0)
            {
                var stream = new MemoryStream();
                Library.SerializeHelper.SerializeToMemory(ctxList, stream);
                writer.WriteStream(stream);
            }
        }
Esempio n. 2
0
 public void OnSerialized(ref Library.Writer writer)
 {
     writer.WriteInt((int)type);
     if (type == PointerType.Text)
     {
         var ptr  = new IntPtr(value);
         var gcp  = GCHandle.FromIntPtr(ptr);
         var text = gcp.Target as string;
         writer.WriteString(text);
     }
     else if (type == PointerType.Reference)
     {
         throw new NotSupportedException("reference type pointer can't serialized.");
     }
 }
Esempio n. 3
0
        public void OnSerialized(ref Library.Writer writer)
        {
            writer.WriteInt(_groups.Count);
            var gIter = _groups.GetEnumerator();

            while (gIter.MoveNext())
            {
                gIter.Current.Key.OnSerialized(ref writer);

                var wrapper = gIter.Current.Value;
                writer.WriteInt(wrapper.Count);
                var wIter = wrapper.GetEnumerator();
                while (wIter.MoveNext())
                {
                    writer.WriteInt(wIter.Current._index);
                }
            }

            if (null != _props)
            {
                writer.WriteInt(_props.Count);
                var pIter = _props.GetEnumerator();
                while (pIter.MoveNext())
                {
                    var type  = pIter.Current.Key;
                    var attr  = type.GetCustomAttributes(false)[0] as Property.PropertyAttribute;
                    var index = attr.Index;
                    var size  = attr.Size;
                    writer.WriteInt(index);
                    writer.WriteInt(size);

                    var ptr = pIter.Current.Value;
                    writer.WriteMemory(ptr.ToPointer(), size);
                }
            }
            else
            {
                writer.WriteInt(0);
            }
        }