mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-12 18:17:02 +00:00
perf[reflect]: use default value in compatible field
This commit is contained in:
1 parent
22c4295717
commit
fc1f9d55c9
1 file changed
+4
-3
@@ -155,14 +155,15 @@ public class ProtocolRegistration implements IProtocolRegistration {
|
||||
object = ReflectionUtils.newInstance(constructor);
|
||||
for (int i = 0, j = fields.length; i < j; i++) {
|
||||
Field field = fields[i];
|
||||
IFieldRegistration packetFieldRegistration = fieldRegistrations[i];
|
||||
ISerializer serializer = packetFieldRegistration.serializer();
|
||||
// 协议向后兼容
|
||||
if (field.isAnnotationPresent(Compatible.class)) {
|
||||
if (length == -1 || byteBuf.readerIndex() - readIndex >= length) {
|
||||
break;
|
||||
ReflectionUtils.setField(field, object, packetFieldRegistration.defaultValue());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
IFieldRegistration packetFieldRegistration = fieldRegistrations[i];
|
||||
ISerializer serializer = packetFieldRegistration.serializer();
|
||||
Object fieldValue = serializer.readObject(byteBuf, packetFieldRegistration);
|
||||
ReflectionUtils.setField(field, object, fieldValue);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user