use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DefaultPortableReader method readPortable.
@Override
@Nullable
@SuppressWarnings("unchecked")
public Portable readPortable(@Nonnull String fieldName) throws IOException {
int currentPos = in.position();
try {
FieldDefinition fd = cd.getField(fieldName);
if (fd == null) {
throw throwUnknownFieldException(fieldName);
}
if (fd.getType() != FieldType.PORTABLE) {
throw new HazelcastSerializationException("Not a Portable field: " + fieldName);
}
int pos = readPosition(fd);
in.position(pos);
boolean isNull = in.readBoolean();
int factoryId = in.readInt();
int classId = in.readInt();
checkFactoryAndClass(fd, factoryId, classId);
if (!isNull) {
return serializer.read(in, factoryId, classId);
}
return null;
} finally {
in.position(currentPos);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DefaultPortableReader method readPortableArray.
@Override
@Nullable
public Portable[] readPortableArray(@Nonnull String fieldName) throws IOException {
int currentPos = in.position();
try {
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);
}
int position = readPosition(fd);
in.position(position);
int len = in.readInt();
int factoryId = in.readInt();
int classId = in.readInt();
if (len == Bits.NULL_ARRAY_LENGTH) {
return null;
}
checkFactoryAndClass(fd, factoryId, classId);
Portable[] portables = new Portable[len];
if (len > 0) {
int offset = in.position();
for (int i = 0; i < len; i++) {
int start = in.readInt(offset + i * Bits.INT_SIZE_IN_BYTES);
in.position(start);
portables[i] = serializer.read(in, factoryId, classId);
}
}
return portables;
} finally {
in.position(currentPos);
}
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class PortableGenericRecordBuilder method set.
private GenericRecordBuilder set(@Nonnull String fieldName, Object value, FieldType fieldType) {
FieldDefinition fd = check(fieldName, fieldType);
int index = fd.getIndex();
if (isSet[index]) {
if (!isClone) {
throw new HazelcastSerializationException("It is illegal to the overwrite the field");
} else {
throw new HazelcastSerializationException("Field can only overwritten once with `cloneWithBuilder`");
}
}
objects[index] = value;
isSet[index] = true;
return this;
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class ClassDefinitionWriter method writeNullPortable.
@Override
public void writeNullPortable(@Nonnull String fieldName, int factoryId, int classId) {
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);
}
use of com.hazelcast.nio.serialization.HazelcastSerializationException in project hazelcast by hazelcast.
the class DefaultPortableWriter method setPosition.
private FieldDefinition setPosition(@Nonnull String fieldName, @Nonnull FieldType fieldType) throws IOException {
if (raw) {
throw new HazelcastSerializationException("Cannot write Portable fields after getRawDataOutput() is called!");
}
FieldDefinition fd = cd.getField(fieldName);
if (fd == null) {
throw new HazelcastSerializationException("Invalid field name: '" + fieldName + "' for ClassDefinition {id: " + cd.getClassId() + ", version: " + cd.getVersion() + "}");
}
if (writtenFields.add(fieldName)) {
int pos = out.position();
int index = fd.getIndex();
out.writeInt(offset + index * INT_SIZE_IN_BYTES, pos);
out.writeShort(fieldName.length());
out.writeBytes(fieldName);
out.writeByte(fieldType.getId());
} else {
throw new HazelcastSerializationException("Field '" + fieldName + "' has already been written!");
}
return fd;
}
Aggregations