UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

63 lines 2.79 kB
"use strict"; var PortableContext_1 = require('./PortableContext'); var DefaultPortableReader_1 = require('./DefaultPortableReader'); var MorphingPortableReader_1 = require('./MorphingPortableReader'); var DefaultPortableWriter_1 = require('./DefaultPortableWriter'); var PortableSerializer = (function () { function PortableSerializer(service, portableFactories, portableVersion) { this.service = service; this.portableContext = new PortableContext_1.PortableContext(this.service, portableVersion); this.factories = portableFactories; } PortableSerializer.prototype.getId = function () { return -1; }; PortableSerializer.prototype.read = function (input) { var factoryId = input.readInt(); var classId = input.readInt(); return this.readObject(input, factoryId, classId); }; PortableSerializer.prototype.readObject = function (input, factoryId, classId) { var version = input.readInt(); var factory = this.factories[factoryId]; if (factory == null) { throw new RangeError("There is no suitable portable factory for " + factoryId + "."); } var portable = factory.create(classId); var classDefinition = this.portableContext.lookupClassDefinition(factoryId, classId, version); if (classDefinition === null) { var backupPos = input.position(); try { classDefinition = this.portableContext.readClassDefinitionFromInput(input, factoryId, classId, version); } finally { input.position(backupPos); } } var reader; if (classDefinition.getVersion() === this.portableContext.getClassVersion(portable)) { reader = new DefaultPortableReader_1.DefaultPortableReader(this, input, classDefinition); } else { reader = new MorphingPortableReader_1.MorphingPortableReader(this, input, classDefinition); } portable.readPortable(reader); reader.end(); return portable; }; PortableSerializer.prototype.write = function (output, object) { output.writeInt(object.getFactoryId()); output.writeInt(object.getClassId()); this.writeObject(output, object); }; PortableSerializer.prototype.writeObject = function (output, object) { var cd = this.portableContext.lookupOrRegisterClassDefinition(object); output.writeInt(cd.getVersion()); var writer = new DefaultPortableWriter_1.DefaultPortableWriter(this, output, cd); object.writePortable(writer); writer.end(); }; return PortableSerializer; }()); exports.PortableSerializer = PortableSerializer; //# sourceMappingURL=PortableSerializer.js.map