@Override Object getValue(Object target, String fieldPath) throws Exception { Data data = (Data) target; PortableContext context = serializationService.getPortableContext(); PortableReader reader = serializationService.createPortableReader(data); ClassDefinition classDefinition = context.lookupClassDefinition(data); FieldDefinition fieldDefinition = context.getFieldDefinition(classDefinition, fieldPath); if (fieldDefinition != null) { return ((DefaultPortableReader) reader).read(fieldPath); } else { return null; } }
@Override public void writeNullPortable(String fieldName, int factoryId, int classId) throws IOException { final ClassDefinition nestedClassDef = context.lookupClassDefinition(factoryId, classId, context.getVersion()); if (nestedClassDef == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } builder.addPortableField(fieldName, nestedClassDef); }
ClassDefinition registerAndGet() { final ClassDefinition cd = builder.build(); return context.registerClassDefinition(cd); } }
@Override public void writePortable(String fieldName, Portable portable) throws IOException { if (portable == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } int version = SerializationUtil.getPortableVersion(portable, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version)); builder.addPortableField(fieldName, nestedClassDef); }
@Override public void writePortable(String fieldName, Portable portable) throws IOException { if (portable == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } int version = SerializationUtil.getPortableVersion(portable, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(portable, new ClassDefinitionBuilder(portable.getFactoryId(), portable.getClassId(), version)); builder.addPortableField(fieldName, nestedClassDef); }
@Override public void writeNullPortable(String fieldName, int factoryId, int classId) throws IOException { final ClassDefinition nestedClassDef = context.lookupClassDefinition(factoryId, classId, context.getVersion()); if (nestedClassDef == null) { throw new HazelcastSerializationException("Cannot write null portable without explicitly " + "registering class definition!"); } builder.addPortableField(fieldName, nestedClassDef); }
@Override Object getValue(Object target, String fieldPath) throws Exception { Data data = (Data) target; PortableContext context = serializationService.getPortableContext(); PortableReader reader = serializationService.createPortableReader(data); ClassDefinition classDefinition = context.lookupClassDefinition(data); FieldDefinition fieldDefinition = context.getFieldDefinition(classDefinition, fieldPath); if (fieldDefinition != null) { return ((DefaultPortableReader) reader).read(fieldPath); } else { return null; } }
ClassDefinition registerAndGet() { final ClassDefinition cd = builder.build(); return context.registerClassDefinition(cd); } }
@Override public void writePortableArray(String fieldName, Portable[] portables) throws IOException { if (portables == null || portables.length == 0) { throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!"); } Portable p = portables[0]; int classId = p.getClassId(); for (int i = 1; i < portables.length; i++) { if (portables[i].getClassId() != classId) { throw new IllegalArgumentException("Detected different class-ids in portable array!"); } } int version = SerializationUtil.getPortableVersion(p, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version)); builder.addPortableArrayField(fieldName, nestedClassDef); }
private ClassDefinition createNestedClassDef(Portable portable, ClassDefinitionBuilder nestedBuilder) throws IOException { ClassDefinitionWriter writer = new ClassDefinitionWriter(context, nestedBuilder); portable.writePortable(writer); return context.registerClassDefinition(nestedBuilder.build()); }
@Override public void writePortableArray(String fieldName, Portable[] portables) throws IOException { if (portables == null || portables.length == 0) { throw new HazelcastSerializationException("Cannot write null portable array without explicitly " + "registering class definition!"); } Portable p = portables[0]; int classId = p.getClassId(); for (int i = 1; i < portables.length; i++) { if (portables[i].getClassId() != classId) { throw new IllegalArgumentException("Detected different class-ids in portable array!"); } } int version = SerializationUtil.getPortableVersion(p, context.getVersion()); ClassDefinition nestedClassDef = createNestedClassDef(p, new ClassDefinitionBuilder(p.getFactoryId(), classId, version)); builder.addPortableArrayField(fieldName, nestedClassDef); }
private ClassDefinition createNestedClassDef(Portable portable, ClassDefinitionBuilder nestedBuilder) throws IOException { ClassDefinitionWriter writer = new ClassDefinitionWriter(context, nestedBuilder); portable.writePortable(writer); return context.registerClassDefinition(nestedBuilder.build()); }