ZhiQiang-Tiger opened a new issue, #2093:
URL: https://github.com/apache/fury/issues/2093

   ### Question
   
   `public class FuryUtils {
       private static final ThreadSafeFury fury_1;
       private static final ThreadSafeFury fury_2;
       public static <T> byte[] serialize2(T t) {
           return fury_1.serialize(t);
       }
   
       public static <T> Object zeroCopyDeserialize2(byte[] byteBuffer) {
           return fury_2.deserialize(byteBuffer);
       }
       static {
           fury_1 = Fury.builder()
                   .withLanguage(Language.JAVA)
                   .withRefTracking(true)
                   .requireClassRegistration(false)
                   .withCodegen(true)
                   .withCompatibleMode(CompatibleMode.COMPATIBLE)
                   .build();
   
           fury_2 = Fury.builder()
                   .withLanguage(Language.JAVA)
                   .withRefTracking(true)
                   .requireClassRegistration(false)
                   .withCodegen(true)
                   .withCompatibleMode(CompatibleMode.COMPATIBLE)
                   .build();
           writeAndRegisterFury(fury_1);
           readAndRegisterFury(fury_2);
       }
     // 写入classId和注册的class映射
       public static void writeAndRegisterFury(Fury fury){
           List<Class<?>> objectList = Lists.newArrayList();
           objectList.add(Parent.class);
           // 获取需要注册类的列表,按simpleName排序
           TreeMap<String, Class<?>> registerClazz = 
FuryTest.getRegisterClazz(objectList);
           Map<String, Short> class2ClassId = new HashMap<>();
           // 存储类注册的顺序
           Short sortId = 1000;
           for (Class<?> value : registerClazz.values()) {
               System.out.println(value.getSimpleName() + ":" + sortId);
               class2ClassId.put(value.getSimpleName(), sortId);
               fury.register(value, sortId++);
           }
           // 把类注册的顺序
           File file = new File("clazz.txt");
           try(BufferedWriter writer = new BufferedWriter(new 
FileWriter(file))){
               String jsonString = JSONObject.toJSONString(class2ClassId);
               writer.write(jsonString);
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
       }
       // 写入classId和
       public static void readAndRegisterFury(Fury fury){
           // 将需要序列化的类注册
           File file = new File("clazz.txt");
           Map<String, Short> class2ClassId;
           try(BufferedReader reader = new BufferedReader(new 
FileReader(file))){
               String class2Id = reader.readLine();
               class2ClassId = JSONObject.parseObject(class2Id, new 
TypeReference<HashMap<String, Short>>() {
               });
           } catch (Exception e) {
               throw new RuntimeException(e);
           }
           List<Class<?>> objectList = Lists.newArrayList();
           objectList.add(Parent.class);
           TreeMap<String, Class<?>> registerClazz = 
FuryTest.getRegisterClazz(objectList);
           // 假如文件为空
           if (class2ClassId.isEmpty()){
               for (Class<?> value : registerClazz.values()) {
                   fury.register(value);
               }
           }else {
               Map<Short, Class<?>> classIdClassTreeMap = new TreeMap<>();
               for (Class<?> value : registerClazz.values()) {
                   Short classId = class2ClassId.get(value.getSimpleName());
                   classIdClassTreeMap.put(classId, value);
               }
               for (Map.Entry<Short, Class<?>> entry : 
classIdClassTreeMap.entrySet()) {
                   System.out.println(entry.getValue().getSimpleName());
                   fury.register(entry.getValue(), entry.getKey());
               }
           }
       }
     
   }`
   
   
![Image](https://github.com/user-attachments/assets/8ab6e8b3-8bae-4028-9742-b6beb0258e21)
   这是序列化时注册类的顺序
   
   
![Image](https://github.com/user-attachments/assets/04b9a5ec-142a-4e9d-b793-2b2b9ba18e46)
   
   我把A、B两个类的路径修改一下,但是它们的注册顺序不变
   
   
![Image](https://github.com/user-attachments/assets/5f3d335c-7602-4275-abef-c1fcd53ae2ce)
   结果是:
   
   
![Image](https://github.com/user-attachments/assets/3439380a-f485-45f6-843e-f50d4ab8db46)
   


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