Exemplo n.º 1
0
        public void Serialize(Stream serializationStream, object graph)
        {
            IMessage message = (graph as IMessage);

            serializationStream.EncodeVariableInt(message.Id);

            PropertyManager.ReadLock();
            try
            {
                Dictionary <UInt32, PropertyContainer> .Enumerator iterator = PropertyManager.GetEnumerator();
                if (iterator.MoveNext())
                {
                    MemoryStream components = MemoryPool <MemoryStream> .Get();

                    try
                    {
                        do
                        {
                            object value; if (iterator.Current.Value.TryGet(message.Template, out value) && value != null && TypeFormatter.CanSerialize(value.GetType()))
                            {
                                components.Encode(iterator.Current.Key);
                                TypeFormatter.Serialize(components, value);

                                serializationStream.Encode(components.Length);
                                components.Seek(0, SeekOrigin.Begin);
                                components.CopyTo(serializationStream);
                                components.SetLength(0);
                            }
                        }while (iterator.MoveNext());
                    }
                    finally
                    {
                        MemoryPool <MemoryStream> .Return(components);
                    }
                }
            }
            finally
            {
                PropertyManager.ReadRelease();
            }
            serializationStream.Encode((long)0);
        }
Exemplo n.º 2
0
 public static void Serialize(this IMessage message, Stream target)
 {
     TypeFormatter.Serialize(target, TypeId, message);
 }