@Override public int getFieldClassId(String fieldName) { final FieldDefinition fd = getField(fieldName); if (fd != null) { return fd.getClassId(); } throw new IllegalArgumentException("Unknown field: " + fieldName); }
@Override public int getFieldClassId(String fieldName) { final FieldDefinition fd = getField(fieldName); if (fd != null) { return fd.getClassId(); } throw new IllegalArgumentException("Unknown field: " + fieldName); }
/** * Validates if the given factoryId and classId match the ones from the fieldDefinition * * @param fd given fieldDefinition to validate against * @param factoryId given factoryId to validate * @param classId given factoryId to validate * @param fullPath full path - just for output */ static void validateFactoryAndClass(FieldDefinition fd, int factoryId, int classId, String fullPath) { if (factoryId != fd.getFactoryId()) { throw new IllegalArgumentException("Invalid factoryId! Expected: " + fd.getFactoryId() + ", Current: " + factoryId + " in path " + fullPath); } if (classId != fd.getClassId()) { throw new IllegalArgumentException("Invalid classId! Expected: " + fd.getClassId() + ", Current: " + classId + " in path " + fullPath); } } }
/** * Validates if the given factoryId and classId match the ones from the fieldDefinition * * @param fd given fieldDefinition to validate against * @param factoryId given factoryId to validate * @param classId given factoryId to validate * @param fullPath full path - just for output */ static void validateFactoryAndClass(FieldDefinition fd, int factoryId, int classId, String fullPath) { if (factoryId != fd.getFactoryId()) { throw new IllegalArgumentException("Invalid factoryId! Expected: " + fd.getFactoryId() + ", Current: " + factoryId + " in path " + fullPath); } if (classId != fd.getClassId()) { throw new IllegalArgumentException("Invalid classId! Expected: " + fd.getClassId() + ", Current: " + classId + " in path " + fullPath); } } }
private void checkPortableAttributes(FieldDefinition fd, Portable portable) { if (fd.getFactoryId() != portable.getFactoryId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + " Expected factory-id: " + fd.getFactoryId() + ", Actual factory-id: " + portable.getFactoryId()); } if (fd.getClassId() != portable.getClassId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + "Expected class-id: " + fd.getClassId() + ", Actual class-id: " + portable.getClassId()); } }
private void checkPortableAttributes(FieldDefinition fd, Portable portable) { if (fd.getFactoryId() != portable.getFactoryId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + " Expected factory-id: " + fd.getFactoryId() + ", Actual factory-id: " + portable.getFactoryId()); } if (fd.getClassId() != portable.getClassId()) { throw new HazelcastSerializationException("Wrong Portable type! Generic portable types are not supported! " + "Expected class-id: " + fd.getClassId() + ", Actual class-id: " + portable.getClassId()); } }
throw new IllegalArgumentException("Unknown field: " + name); currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion()); if (currentClassDef == null) {
throw new IllegalArgumentException("Unknown field: " + name); currentClassDef = lookupClassDefinition(fd.getFactoryId(), fd.getClassId(), fd.getVersion()); if (currentClassDef == null) {
@Override public void writePortable(String fieldName, Portable portable) throws IOException { FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE); final boolean isNull = portable == null; out.writeBoolean(isNull); out.writeInt(fd.getFactoryId()); out.writeInt(fd.getClassId()); if (!isNull) { checkPortableAttributes(fd, portable); serializer.writeInternal(out, portable); } }
@Override public void writePortable(String fieldName, Portable portable) throws IOException { FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE); final boolean isNull = portable == null; out.writeBoolean(isNull); out.writeInt(fd.getFactoryId()); out.writeInt(fd.getClassId()); if (!isNull) { checkPortableAttributes(fd, portable); serializer.writeInternal(out, portable); } }
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) { final Set<String> fieldNames = cd.getFieldNames(); for (String fieldName : fieldNames) { FieldDefinition fd = cd.getField(fieldName); if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) { int classId = fd.getClassId(); ClassDefinition nestedCd = classDefMap.get(classId); if (nestedCd != null) { registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors); portableContext.registerClassDefinition(nestedCd); } else if (checkClassDefErrors) { throw new HazelcastSerializationException( "Could not find registered ClassDefinition for class-id: " + classId); } } } portableContext.registerClassDefinition(cd); }
protected void registerClassDefinition(ClassDefinition cd, Map<Integer, ClassDefinition> classDefMap, boolean checkClassDefErrors) { final Set<String> fieldNames = cd.getFieldNames(); for (String fieldName : fieldNames) { FieldDefinition fd = cd.getField(fieldName); if (fd.getType() == FieldType.PORTABLE || fd.getType() == FieldType.PORTABLE_ARRAY) { int classId = fd.getClassId(); ClassDefinition nestedCd = classDefMap.get(classId); if (nestedCd != null) { registerClassDefinition(nestedCd, classDefMap, checkClassDefErrors); portableContext.registerClassDefinition(nestedCd); } else if (checkClassDefErrors) { throw new HazelcastSerializationException( "Could not find registered ClassDefinition for class-id: " + classId); } } } portableContext.registerClassDefinition(cd); }
@Override public void writePortableArray(String fieldName, Portable[] portables) throws IOException { FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE_ARRAY); final int len = portables == null ? NULL_ARRAY_LENGTH : portables.length; out.writeInt(len); out.writeInt(fd.getFactoryId()); out.writeInt(fd.getClassId()); if (len > 0) { final int offset = out.position(); out.writeZeroBytes(len * 4); for (int i = 0; i < len; i++) { Portable portable = portables[i]; checkPortableAttributes(fd, portable); int position = out.position(); out.writeInt(offset + i * INT_SIZE_IN_BYTES, position); serializer.writeInternal(out, portable); } } }
@Override public void writePortableArray(String fieldName, Portable[] portables) throws IOException { FieldDefinition fd = setPosition(fieldName, FieldType.PORTABLE_ARRAY); final int len = portables == null ? NULL_ARRAY_LENGTH : portables.length; out.writeInt(len); out.writeInt(fd.getFactoryId()); out.writeInt(fd.getClassId()); if (len > 0) { final int offset = out.position(); out.writeZeroBytes(len * 4); for (int i = 0; i < len; i++) { Portable portable = portables[i]; checkPortableAttributes(fd, portable); int position = out.position(); out.writeInt(offset + i * INT_SIZE_IN_BYTES, position); serializer.writeInternal(out, portable); } } }