chaokunyang commented on issue #2658:
URL: https://github.com/apache/fory/issues/2658#issuecomment-3341309652

   > Currently, only write and write_data are instance methods; the others are 
all static methods. If users want to perform read/write directly on an 
instance, ForySerializer::read() is the only way. We just need to decide on 
whether write/write_data should be ForySerializer::write(xx) or xx.fory_write().
   
   If methods are named as `fory_read`,  one can just invoke `let foo = 
Foo.fory_read(buffer)` to get the value. `read` will never be invoked on an 
instance, read don't accept `instance` as a parameter. 
   
   `read/write` is more elegant, but such names are very common and easy to 
conflict. I prefer using `fory_read/fory_write` in `Serializer` trait, since 
users will only invoke those methods when implement ext serializer by impl 
`Serializer` directly, which is rare, and such verbosity looks acceptable to 
me. And we can provide util to mitigate this:
   
   ```rust
   pub fn write<T: Serializer>(value: &T, context: &mut WriteContext) -> 
Result<()> {
       value.fory_write(value, context)
   }
   
   pub fn read<T: Serializer>(context: &mut ReadContext) -> Result<T> {
       T::fory_read(context)
   }
   ```
   
   Users can just import those functions, and write like:
   ```rust
   use fory::{read, write};
   
   impl Serializer for Foo {
      fn write(&self, context: &mut WriteContext) {
        write(foo.bar, context);
        write(foo.name, context):
        //.......
      }
   }
   ```
   
   This is still short and nice
   


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