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:
   > Why is ordinal <= 0 needed here?
   
   No need, I'll fix it.
   
   > 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.
   
   > Please add a comment explaining why we need to do -1 (probably because we 
use 0 to pass null and need to shift 'real' values?)
   
   I tried to leave comments in the generator code.



-- 
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]

Reply via email to