public Portable[] readPortableArray(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE_ARRAY) { throw new HazelcastSerializationException("Not a Portable array field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final int len = in.readInt(); final Portable[] portables = new Portable[len]; if (len > 0) { final int offset = in.position(); for (int i = 0; i < len; i++) { final int start = in.readInt(offset + i * 4); in.position(start); portables[i] = serializer.readAndInitialize(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } } return portables; } finally { in.position(currentPos); } }
private int readNestedPosition(String fieldName, FieldType type) throws IOException { String[] fieldNames = NESTED_FIELD_PATTERN.split(fieldName); if (fieldNames.length > 1) { FieldDefinition fd = null; DefaultPortableReader reader = this; for (int i = 0; i < fieldNames.length; i++) { fd = reader.cd.getField(fieldNames[i]); if (fd == null) { break; } if (i == fieldNames.length - 1) { break; } int pos = reader.readPosition(fd); in.position(pos); boolean isNull = in.readBoolean(); if (isNull) { throw new NullPointerException("Parent field is null: " + fieldNames[i]); } reader = serializer.createReader(in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != type) { throw new HazelcastSerializationException("Not a '" + type + "' field: " + fieldName); } return reader.readPosition(fd); } throw throwUnknownFieldException(fieldName); }
public Portable readPortable(String fieldName) throws IOException { FieldDefinition fd = cd.getField(fieldName); if (fd == null) { throw throwUnknownFieldException(fieldName); } if (fd.getType() != FieldType.PORTABLE) { throw new HazelcastSerializationException("Not a Portable field: " + fieldName); } final int currentPos = in.position(); try { int pos = readPosition(fd); in.position(pos); final boolean isNull = in.readBoolean(); if (!isNull) { return serializer.readAndInitialize( in, fd.getFactoryId(), fd.getClassId(), fd.getVersion()); } return null; } finally { in.position(currentPos); } }