private DefaultPortableReader CreateReader(IBufferObjectDataInput input, int factoryId, int classId, int version, int portableVersion) { var effectiveVersion = version; if (version < 0) { effectiveVersion = _context.GetVersion(); } var cd = _context.LookupClassDefinition(factoryId, classId, effectiveVersion); if (cd == null) { var begin = input.Position; cd = _context.ReadClassDefinition(input, factoryId, classId, effectiveVersion); input.Position = begin; } DefaultPortableReader reader; if (portableVersion == effectiveVersion) { reader = new DefaultPortableReader(this, input, cd); } else { reader = new MorphingPortableReader(this, input, cd); } return(reader); }
internal IClassDefinition Register(IClassDefinition cd) { if (cd == null) { return(null); } if (cd.FactoryId != _factoryId) { throw new SerializationException("Invalid factory-id! " + _factoryId + " -> " + cd); } if (cd is ClassDefinition cdImpl) { cdImpl.SetVersionIfNotSet(_portableContext.GetVersion()); } var versionedClassId = CombineToLong(cd.ClassId, cd.Version); var currentCd = _versionedDefinitions.GetOrAdd(versionedClassId, cd); if (Equals(currentCd, cd)) { return(cd); } if (currentCd is ClassDefinition) { if (!currentCd.Equals(cd)) { throw new SerializationException( "Incompatible class-definitions with same class-id: " + cd + " VS " + currentCd); } return(currentCd); } _versionedDefinitions.AddOrUpdate(versionedClassId, cd, (key, oldValue) => cd); return(cd); }