Esempio n. 1
0
            private void serialize(SlimWriter writer, object root, RefPool pool)
            {                           
               if (root is Type)
                 root = new rootTypeBox{ TypeValue = (Type)root};

               var scontext = new StreamingContext();
               var registry = (m_TypeMode == TypeRegistryMode.PerCall) ? new TypeRegistry(m_GlobalTypes) : m_BatchTypeRegistry;
               var type = root!=null? root.GetType() : typeof(object);
               var isValType = type.IsValueType;
                               
               
                 writeHeader(writer);
                 var rcount = registry.Count;
                 m_BatchTypeRegistryPriorCount = rcount;
                
                 if (!m_SkipTypeRegistryCrosschecks)
                 {
                    writer.Write( (uint)rcount );
                    writer.Write( registry.CSum );
                 }      
                                            

                 //Write root in pool if it is reference type
                 if (!isValType && root!=null)
                   pool.Add(root);
               
                 m_Format.TypeSchema.Serialize(writer, registry, pool, root, scontext);

                 
                 if (root==null) return;

                 var i = 1;

                 if (!isValType) i++;
                     
                 //Write all the rest of objects. The upper bound of this loop may increase as objects are written
                 //0 = NULL
                 //1 = root IF root is ref type
                 var ts = m_Format.TypeSchema;
                 for(; i<pool.Count; i++)
                 {
                    var instance = pool[i];
                    var tinst = instance.GetType();
                    if (!m_Format.IsRefTypeSupported(tinst))
                      ts.Serialize(writer, registry, pool, instance, scontext); 
                 }

            }
Esempio n. 2
0
 private void writeHeader(SlimWriter writer)
 {
    writer.Write((byte)0);
    writer.Write((byte)0);
    writer.Write((byte)((HEADER >> 8) & 0xff));
    writer.Write((byte)(HEADER & 0xff));
 }
Esempio n. 3
0
            public void Serialize(Stream stream, object root)
            {
                try
                {
                    var singleThreaded = m_TypeMode == TypeRegistryMode.Batch;
                    
                    SlimWriter writer;
                    
                    if (!singleThreaded || m_SerializeNestLevel >0)
                     writer = m_Format.MakeWritingStreamer();
                    else
                    {
                      writer = m_CachedWriter;
                      if (writer==null) 
                      {
                        writer = m_Format.MakeWritingStreamer();
                        m_CachedWriter = writer;
                      }
                    }
                    
                    var pool = reservePool( SerializationOperation.Serializing );
                    try
                    {
                     m_SerializeNestLevel++;
                     writer.BindStream( stream );

                     serialize(writer, root, pool);
                    }
                    finally
                    {
                      writer.UndindStream();
                      m_SerializeNestLevel--;
                      releasePool(pool);
                    }
                }
                catch(Exception error)
                {
                    throw new SlimSerializationException(StringConsts.SLIM_SERIALIZATION_EXCEPTION_ERROR + error.ToMessageWithType(), error);
                }
            }