Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException" />
        public IClassDefinition LookupOrRegisterClassDefinition(IPortable p)
        {
            var portableVersion = PortableVersionHelper.GetVersion(p, _version);
            var cd = LookupClassDefinition(p.GetFactoryId(), p.GetClassId(), portableVersion);

            if (cd == null)
            {
                var writer = new ClassDefinitionWriter(this, p.GetFactoryId(), p.GetClassId(), portableVersion);
                p.WritePortable(writer);
                cd = writer.RegisterAndGet();
            }
            return(cd);
        }
Exemplo n.º 2
0
        /// <exception cref="System.IO.IOException"></exception>
        public void WritePortable(string fieldName, IPortable portable)
        {
            if (portable == null)
            {
                throw new HazelcastSerializationException("Cannot write null portable without explicitly "
                                                          + "registering class definition!");
            }
            int version = PortableVersionHelper.GetVersion(portable, context.GetVersion());
            IClassDefinition nestedClassDef = CreateNestedClassDef(portable, new ClassDefinitionBuilder
                                                                       (portable.GetFactoryId(), portable.GetClassId(), version));

            builder.AddPortableField(fieldName, nestedClassDef);
        }
        private int FindPortableVersion(int factoryId, int classId, IPortable portable)
        {
            var currentVersion = _context.GetClassVersion(factoryId, classId);

            if (currentVersion < 0)
            {
                currentVersion = PortableVersionHelper.GetVersion(portable, _context.GetVersion());
                if (currentVersion > 0)
                {
                    _context.SetClassVersion(factoryId, classId, currentVersion);
                }
            }
            return(currentVersion);
        }
Exemplo n.º 4
0
        /// <exception cref="System.IO.IOException"></exception>
        public void WritePortableArray(string fieldName, IPortable[] portables)
        {
            if (portables == null || portables.Length == 0)
            {
                throw new HazelcastSerializationException("Cannot write null portable array without explicitly "
                                                          + "registering class definition!");
            }
            IPortable p       = portables[0];
            int       classId = p.GetClassId();

            for (int i = 1; i < portables.Length; i++)
            {
                if (portables[i].GetClassId() != classId)
                {
                    throw new ArgumentException("Detected different class-ids in portable array!");
                }
            }
            int version = PortableVersionHelper.GetVersion(p, context.GetVersion());
            IClassDefinition nestedClassDef = CreateNestedClassDef(p, new ClassDefinitionBuilder
                                                                       (p.GetFactoryId(), classId, version));

            builder.AddPortableArrayField(fieldName, nestedClassDef);
        }