public object DeserializeRootOrInner(SlimReader reader, TypeRegistry registry, RefPool refs, StreamingContext streamingContext, bool root, Type valueType = null) { Type type = valueType; if (type == null) { var thandle = reader.ReadString(); if (TypeRegistry.IsNullHandle(thandle)) { return(null); } type = registry[thandle]; } //we get here if we have a boxed value of directly-handled type var ra = Format.GetReadActionForType(type) ?? Format.GetReadActionForRefType(type);//20150503 DKh fixed root byte[] slow if (ra != null) { return(ra(reader)); } TypeDescriptor td = getTypeDescriptorCachedOrMake(type); object instance = null; if (td.IsArray) { instance = Arrays.DescriptorToArray(reader.ReadString(), registry); } else { instance = SerializationUtils.MakeNewObjectInstance(type); } if (root) { if (!type.IsValueType)//if this is a reference type { refs.Add(instance); } } td.DeserializeInstance(reader, registry, refs, ref instance, streamingContext); return(instance); }
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); } } }
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); } }