chaokunyang commented on code in PR #3234:
URL: https://github.com/apache/fory/pull/3234#discussion_r2739912689


##########
javascript/packages/fory/lib/fory.ts:
##########
@@ -148,7 +169,7 @@ export default class {
     // reserve fixed size
     this.binaryWriter.reserve(serializer.fixedSize);
     // start write
-    serializer.write(data);
+    serializer.writeRef(data);

Review Comment:
   could we provide write/writeRef/read/readRef methods? the write/read methods 
only handle value, and writeRef/readRef handle cases where ref tracking may be 
needed for morphic types in field/collection/map.
   
   You can take this as reference:
   ```java
     /**
      * Write value to buffer, this method may write ref/null flags based 
passed {@code refMode}, and
      * the passed value can be null. Note that this method don't write type 
info, this method is
      * mostly be used in cases the context has already knows the value type 
when deserialization.
      */
     public void write(MemoryBuffer buffer, RefMode refMode, T value) {
       // noinspection Duplicates
       if (refMode == RefMode.TRACKING) {
         if (refResolver.writeRefOrNull(buffer, value)) {
           return;
         }
       } else if (refMode == RefMode.NULL_ONLY) {
         if (value == null) {
           buffer.writeByte(Fory.NULL_FLAG);
           return;
         } else {
           buffer.writeByte(Fory.NOT_NULL_VALUE_FLAG);
         }
       }
       write(buffer, value);
     }
   
     /**
      * Write value to buffer, this method do not write ref/null flags and the 
passed value must not be
      * null
      */
     public void write(MemoryBuffer buffer, T value) {
       throw new UnsupportedOperationException("Please implement serialization 
for " + type);
     }
   
   
     /**
      * Read value from buffer, this method may read ref/null flags based 
passed {@code refMode}, and
      * the read value can be null. Note that this method don't read type info, 
this method is mostly
      * be used in cases the context has already knows the value type for 
deserialization.
      */
     public T read(MemoryBuffer buffer, RefMode refMode) {
       if (refMode == RefMode.TRACKING) {
         T obj;
         int nextReadRefId = refResolver.tryPreserveRefId(buffer);
         if (nextReadRefId >= Fory.NOT_NULL_VALUE_FLAG) {
           obj = read(buffer);
           refResolver.setReadObject(nextReadRefId, obj);
           return obj;
         } else {
           return (T) refResolver.getReadObject();
         }
       } else if (refMode != RefMode.NULL_ONLY || buffer.readByte() != 
Fory.NULL_FLAG) {
         if (needToWriteRef) {
           // in normal case, the xread implementation may invoke 
`refResolver.reference` to
           // support circular reference, so we still need this `-1`
           refResolver.preserveRefId(-1);
         }
         return read(buffer);
       }
       return null;
     }
   
     /**
      * Read value from buffer, this method wont read ref/null flags and the 
read value won't be null.
      */
     public T read(MemoryBuffer buffer) {
       throw new UnsupportedOperationException("Please implement serialization 
for " + type);
     }
   ```



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