chaokunyang commented on code in PR #1616:
URL: https://github.com/apache/incubator-fury/pull/1616#discussion_r1596619197
##########
java/fury-core/src/main/java/org/apache/fury/serializer/collection/CollectionSerializers.java:
##########
@@ -433,28 +436,18 @@ public SetFromMapSerializer(Fury fury, Class<Set<?>>
type) {
}
@Override
- public Collection newCollection(MemoryBuffer buffer) {
- int numElements = buffer.readVarUint32Small7();
- setNumElements(numElements);
- final ClassInfo mapClassInfo =
fury.getClassResolver().readClassInfo(buffer);
- final MethodHandle methodHandle =
ReflectionUtils.getCtrHandle(mapClassInfo.getCls(), true);
- Map map;
- try {
- map = (Map) methodHandle.invoke();
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- final Set set = Collections.newSetFromMap(map);
- fury.getRefResolver().reference(set);
- return set;
+ public void write(MemoryBuffer buffer, Set<?> value) {
+ Object fieldValue = Platform.getObject(value, MAP_FIELD_OFFSET);
+ fury.writeRef(buffer, fieldValue);
}
@Override
- public Collection onCollectionWrite(MemoryBuffer buffer, Set<?> value) {
- buffer.writeVarUint32Small7(value.size());
- final Map<?, Boolean> map = (Map<?, Boolean>) Platform.getObject(value,
MAP_FIELD_OFFSET);
- fury.getClassResolver().writeClassAndUpdateCache(buffer, map.getClass());
- return value;
+ public Set<?> read(MemoryBuffer buffer) {
+ final Map map = (Map) fury.readRef(buffer);
+ final Set set = Collections.newSetFromMap(Collections.emptyMap());
Review Comment:
How about:
```java
final Map map = (Map) fury.readRef(buffer);
return 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]