chaokunyang commented on code in PR #2765:
URL: https://github.com/apache/fory/pull/2765#discussion_r2429589383
##########
rust/fory-core/src/serializer/rc.rs:
##########
@@ -20,45 +20,58 @@ use crate::fory::Fory;
use crate::resolver::context::{ReadContext, WriteContext};
use crate::serializer::{ForyDefault, Serializer};
use crate::types::RefFlag;
-use anyhow::anyhow;
use std::rc::Rc;
impl<T: Serializer + ForyDefault + 'static> Serializer for Rc<T> {
fn fory_is_shared_ref() -> bool {
true
}
- fn fory_write(&self, fory: &Fory, context: &mut WriteContext, is_field:
bool) {
+ fn fory_write(
+ &self,
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
if !context
.ref_writer
.try_write_rc_ref(&mut context.writer, self)
{
- T::fory_write_data(self.as_ref(), fory, context, is_field);
- }
+ T::fory_write_data(self.as_ref(), fory, context, is_field)?
+ };
+ Ok(())
}
- fn fory_write_data(&self, fory: &Fory, context: &mut WriteContext,
is_field: bool) {
+ fn fory_write_data(
+ &self,
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
// When Rc is nested inside another shared ref (like Arc<Rc<T>>),
// the outer ref calls fory_write_data on the inner Rc.
// We still need to track the Rc's own references here.
- self.fory_write(fory, context, is_field);
+ self.fory_write(fory, context, is_field)
}
- fn fory_write_type_info(fory: &Fory, context: &mut WriteContext, is_field:
bool) {
- T::fory_write_type_info(fory, context, is_field);
+ fn fory_write_type_info(
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
+ T::fory_write_type_info(fory, context, is_field)
}
fn fory_read(fory: &Fory, context: &mut ReadContext, is_field: bool) ->
Result<Self, Error> {
- let ref_flag = context.ref_reader.read_ref_flag(&mut context.reader);
-
+ let ref_flag = context.ref_reader.read_ref_flag(&mut context.reader)?;
match ref_flag {
- RefFlag::Null => Err(anyhow!("Rc cannot be null").into()),
+ RefFlag::Null => Err(Error::msg("Rc cannot be null")),
Review Comment:
this should return `InvalidRef` error
##########
rust/fory-core/src/serializer/rc.rs:
##########
@@ -20,45 +20,58 @@ use crate::fory::Fory;
use crate::resolver::context::{ReadContext, WriteContext};
use crate::serializer::{ForyDefault, Serializer};
use crate::types::RefFlag;
-use anyhow::anyhow;
use std::rc::Rc;
impl<T: Serializer + ForyDefault + 'static> Serializer for Rc<T> {
fn fory_is_shared_ref() -> bool {
true
}
- fn fory_write(&self, fory: &Fory, context: &mut WriteContext, is_field:
bool) {
+ fn fory_write(
+ &self,
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
if !context
.ref_writer
.try_write_rc_ref(&mut context.writer, self)
{
- T::fory_write_data(self.as_ref(), fory, context, is_field);
- }
+ T::fory_write_data(self.as_ref(), fory, context, is_field)?
+ };
+ Ok(())
}
- fn fory_write_data(&self, fory: &Fory, context: &mut WriteContext,
is_field: bool) {
+ fn fory_write_data(
+ &self,
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
// When Rc is nested inside another shared ref (like Arc<Rc<T>>),
// the outer ref calls fory_write_data on the inner Rc.
// We still need to track the Rc's own references here.
- self.fory_write(fory, context, is_field);
+ self.fory_write(fory, context, is_field)
}
- fn fory_write_type_info(fory: &Fory, context: &mut WriteContext, is_field:
bool) {
- T::fory_write_type_info(fory, context, is_field);
+ fn fory_write_type_info(
+ fory: &Fory,
+ context: &mut WriteContext,
+ is_field: bool,
+ ) -> Result<(), Error> {
+ T::fory_write_type_info(fory, context, is_field)
}
fn fory_read(fory: &Fory, context: &mut ReadContext, is_field: bool) ->
Result<Self, Error> {
- let ref_flag = context.ref_reader.read_ref_flag(&mut context.reader);
-
+ let ref_flag = context.ref_reader.read_ref_flag(&mut context.reader)?;
match ref_flag {
- RefFlag::Null => Err(anyhow!("Rc cannot be null").into()),
+ RefFlag::Null => Err(Error::msg("Rc cannot be null")),
RefFlag::Ref => {
- let ref_id = context.ref_reader.read_ref_id(&mut
context.reader);
+ let ref_id = context.ref_reader.read_ref_id(&mut
context.reader)?;
context
.ref_reader
.get_rc_ref::<T>(ref_id)
- .ok_or_else(|| anyhow!("Rc reference {} not found",
ref_id).into())
+ .ok_or_else(|| Error::msg(format!("Rc reference {ref_id}
not found")))
Review Comment:
this should return `InvalidRef` error
--
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]