private void writeHeader(SlimWriter writer) { writer.Write((byte)0); writer.Write((byte)0); writer.Write((byte)((HEADER >> 8) & 0xff)); writer.Write((byte)(HEADER & 0xff)); }
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); } }