in java/fury-core/src/main/java/org/apache/fury/builder/CompatibleCodecBuilder.java [787:864]
private Expression readObjectField(
FieldInfo fieldInfo,
Expression bean,
Expression buffer,
Descriptor descriptor,
Expression partFieldInfo) {
Expression readAction =
invokeGenerated(
ctx,
() -> {
TypeRef<?> typeRef = descriptor.getTypeRef();
Expression refId = tryPreserveRefId(buffer);
// indicates that the object is first read.
Expression needDeserialize =
ExpressionUtils.egt(
refId, new Literal(Fury.NOT_NULL_VALUE_FLAG, PRIMITIVE_BYTE_TYPE));
byte type = fieldInfo.getFieldType();
// check `FieldTypes` byte value.
Expression expectType = new Literal(type, PRIMITIVE_BYTE_TYPE);
ListExpression deserializedValue =
new ListExpression(
new Invoke(
fieldResolverRef,
"checkFieldType",
inlineInvoke(buffer, "readByte", PRIMITIVE_BYTE_TYPE),
expectType));
if (type == FieldTypes.OBJECT) {
deserializedValue.add(readForNotNullNonFinal(buffer, typeRef, null));
} else {
if (type == FieldTypes.COLLECTION_ELEMENT_FINAL) {
deserializedValue.add(
skipFinalClassInfo(
((CollectionFieldInfo) fieldInfo).getElementType(), buffer));
} else if (type == FieldTypes.MAP_KV_FINAL) {
deserializedValue.add(
skipFinalClassInfo(((MapFieldInfo) fieldInfo).getKeyType(), buffer));
deserializedValue.add(
skipFinalClassInfo(((MapFieldInfo) fieldInfo).getValueType(), buffer));
} else if (type == FieldTypes.MAP_KEY_FINAL) {
deserializedValue.add(
skipFinalClassInfo(((MapFieldInfo) fieldInfo).getKeyType(), buffer));
} else {
Preconditions.checkArgument(type == FieldTypes.MAP_VALUE_FINAL, fieldInfo);
deserializedValue.add(
skipFinalClassInfo(((MapFieldInfo) fieldInfo).getValueType(), buffer));
}
Class<?> clz = getRawType(typeRef);
if (ReflectionUtils.isMonomorphic(clz)) {
// deserializeForNotNull won't read field type if it's final
deserializedValue.add(skipFinalClassInfo(clz, buffer));
}
deserializedValue.add(deserializeForNotNull(buffer, typeRef, null));
}
Expression setReadObject =
new Invoke(refResolverRef, "setReadObject", refId, deserializedValue);
// use false to ignore null
return new If(
needDeserialize,
new ListExpression(
refId,
deserializedValue,
setReadObject,
setFieldValue(bean, descriptor, tryInlineCast(deserializedValue, typeRef))),
setFieldValue(
bean,
descriptor,
tryInlineCast(
new Invoke(refResolverRef, "getReadObject", OBJECT_TYPE, false),
typeRef)),
false,
PRIMITIVE_VOID_TYPE);
},
"readField",
fieldInfo.getEncodedFieldInfo());
return new ListExpression(
new Expression.ForceEvaluate(readAction),
new Assign(partFieldInfo, inlineInvoke(buffer, readLongFunc(), PRIMITIVE_LONG_TYPE)));
}