chaokunyang commented on PR #2791:
URL: https://github.com/apache/fory/pull/2791#issuecomment-3424465566

   > @chaokunyang Currently has a usage limitation: register must be called in 
a specific order — field type must be registered first.
   
   We can do a two-stage type resolve:
   ```rust
   pub fn serialize<T: Serializer>(&self, record: &T) -> Result<Vec<u8>, Error> 
{
           let pool = self.write_context_pool.get_or_init(|| {
               let type_resolver = self.type_resolver.clone();
               let compatible = self.compatible;
               let share_meta = self.share_meta;
               let compress_string = self.compress_string;
               let xlang = self.xlang;
   
               let factory = move || {
                   let writer = Writer::default();
                   WriteContext::new(
                       writer,
                       type_resolver.clone(),
                       compatible,
                       share_meta,
                       compress_string,
                       xlang,
                   )
               };
               Pool::new(factory)
           });
           let mut context = pool.get();
           let result = self.serialize_with_context(record, &mut context)?;
           context.reset();
           pool.put(context);
           Ok(result)
       }
   ```
   @urlyy How about creating a new method named `finalizeRegistration` method 
on `TypeResolver`, which returns a new TypeResolver with correct typeinfo.
   When creating `WriteContext`, we pass resulf of `finalizeRegistration` 
instead.
   
   


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