chaokunyang commented on code in PR #1616:
URL: https://github.com/apache/incubator-fury/pull/1616#discussion_r1596562488


##########
java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java:
##########
@@ -411,6 +415,66 @@ public ConcurrentSkipListSet newCollection(MemoryBuffer 
buffer) {
     }
   }
 
+  public static final class SetFromMapSerializer extends 
CollectionSerializer<Set<?>> {
+
+    private static final long MAP_FIELD_OFFSET;
+
+    static {
+      try {
+        Field mapField = 
Class.forName("java.util.Collections$SetFromMap").getDeclaredField("m");
+        MAP_FIELD_OFFSET = Platform.objectFieldOffset(mapField);
+      } catch (final Exception e) {
+        throw new RuntimeException(e);
+      }
+    }
+
+    public SetFromMapSerializer(Fury fury, Class<Set<?>> type) {
+      super(fury, type, false);
+    }
+
+    @Override
+    public Collection newCollection(MemoryBuffer buffer) {

Review Comment:
   I just found that this method should not be used if collection `codegen` is 
false. 
   We can just implement serialization like this:
   ```java
   
       @Override
       public void write(MemoryBuffer buffer, Collection value) {
         Object fieldValue = Platform.getObject(value, offset);
         fury.writeRef(buffer, fieldValue);
       }
   
       @Override
       public Collection read(MemoryBuffer buffer) {
         final Map map = (Map) fury.readRef(buffer);
         return (Collection) Collections.newSetFromMap(map);
       }
   ```



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