LiangliangSui commented on code in PR #2146:
URL: https://github.com/apache/fury/pull/2146#discussion_r2050531274


##########
java/fury-core/src/main/java/org/apache/fury/resolver/ClassResolver.java:
##########
@@ -2032,6 +2040,74 @@ public void setCodeGenerator(ClassLoader[] loaders, 
CodeGenerator codeGenerator)
     extRegistry.codeGeneratorMap.put(Arrays.asList(loaders), codeGenerator);
   }
 
+  public DescriptorGrouper createDescriptorGrouper(
+      Collection<Descriptor> descriptors, boolean descriptorsGroupedOrdered) {
+    return createDescriptorGrouper(descriptors, descriptorsGroupedOrdered, 
null);
+  }
+
+  public DescriptorGrouper createDescriptorGrouper(
+      Collection<Descriptor> descriptors,
+      boolean descriptorsGroupedOrdered,
+      Function<Descriptor, Descriptor> descriptorUpdator) {
+    if (fury.isCrossLanguage()) {
+      return DescriptorGrouper.createDescriptorGrouper(
+          c -> {
+            if (TypeUtils.unwrap(c).isPrimitive()) {
+              return true;
+            } else if (c == String.class) {
+              return true;
+            }
+            if (c.isArray() && TypeUtils.getArrayComponent(c).isPrimitive()) {
+              return true;
+            }
+            // TODO(chaokunyang) add more types.
+            return false;
+          },
+          descriptors,
+          descriptorsGroupedOrdered,
+          descriptorUpdator,
+          fury.compressInt(),
+          fury.compressLong(),
+          (o1, o2) -> {
+            int xtypeId = getXtypeId(o1.getRawType());
+            int xtypeId2 = getXtypeId(o2.getRawType());
+            if (xtypeId == xtypeId2) {
+              return o1.getSnakeCaseName().compareTo(o2.getSnakeCaseName());
+            } else {
+              return xtypeId - xtypeId2;
+            }
+          });
+    }
+    return DescriptorGrouper.createDescriptorGrouper(
+        fury.getClassResolver()::isMonomorphic,
+        descriptors,
+        descriptorsGroupedOrdered,
+        descriptorUpdator,
+        fury.compressInt(),
+        fury.compressLong(),
+        DescriptorGrouper.COMPARATOR_BY_TYPE_AND_NAME);
+  }
+
+  private int getXtypeId(Class<?> cls) {
+    if (isCollection(cls)) {
+      return Types.LIST;
+    }
+    if (cls.isArray() && !cls.getComponentType().isPrimitive()) {
+      return Types.LIST;
+    }
+    if (isMap(cls)) {
+      return Types.MAP;
+    }
+    if (fury.getXtypeResolver().isRegistered(cls)) {
+      return fury.getXtypeResolver().getClassInfo(cls).getXtypeId();
+    } else {
+      if (ReflectionUtils.isMonomorphic(cls)) {
+        throw new UnsupportedOperationException(cls + " is not supported for 
xlang serialization");
+      }
+      return 128;

Review Comment:
   What does 128 represent? Could you explain it?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to