tkalkirill commented on code in PR #4152:
URL: https://github.com/apache/ignite-3/pull/4152#discussion_r1697089898
##########
modules/network-annotation-processor/src/main/java/org/apache/ignite/internal/network/processor/serialization/MessageDeserializerGenerator.java:
##########
@@ -181,9 +186,33 @@ private CodeBlock readMessageCodeBlock(ExecutableElement
getter) {
varType = TypeName.get(getter.getReturnType());
}
- return CodeBlock.builder()
- .add("$T tmp = reader.", varType)
- .add(methodResolver.resolveReadMethod(getter))
- .build();
+ if (typeUtils.isEnum(getter.getReturnType())) {
+ checkFromOrdinalMethodExists(getter.getReturnType());
+
+ return CodeBlock.builder()
+ .add("int ordinal = reader.readInt($S);",
getter.getSimpleName().toString())
+ .add("\n")
+ .add("$T tmp = ordinal <= 0 ? null : $T.$L(ordinal - 1)",
varType, varType, FROM_ORDINAL_METHOD_NAME)
Review Comment:
> Can't we just use <Type>.values()[ordinal]?
It would be possible to do this, but each time `Enum#values` is called, a
new array is created, we want to write the code as optimally as possible, so
let there be a separate method for conversion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]