You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "urlyy (via GitHub)" <gi...@apache.org> on 2025/10/06 17:20:45 UTC
[PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
urlyy opened a new pull request, #2712:
URL: https://github.com/apache/fory/pull/2712
## What does this PR do?
1. support `NamedXx` se/de
2. support `EXT`/`NAMEDEXT` se/de
3. fullfil unit test
## Related issues
close #2710
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2712:
URL: https://github.com/apache/fory/pull/2712
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3372960573
@chaokunyang cannot pass test in `test_rc_arc_trait_object.rs` and `test_object.rs` . Could you help me. I'm going to fix #2713
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376675954
```rust
#[derive(Debug, PartialEq, Default)]
struct ExtItem {
id: i32,
}
impl ForyDefault for ExtItem {
fn fory_default() -> Self {
Self::default()
}
}
impl Serializer for ExtItem {
fn fory_write_data(&self, context: &mut WriteContext, is_field: bool) {
write_data(&self.id, context, is_field);
}
fn fory_read_data(context: &mut ReadContext, is_field: bool) -> Result<Self, Error> {
Ok(Self {
id: read_data(context, is_field)?,
})
}
fn fory_type_id_dyn(&self, fory: &Fory) -> u32 {
Self::fory_get_type_id(fory)
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
```
A bit inconvenient for users, isn't it?
@chaokunyang
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376880330
I'm not sure whether can be added on impl block. If this is feasible, the whole issue can be resolved by a macro
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376868756
I didn't find a better way. Do you have any suggestions?
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2712:
URL: https://github.com/apache/fory/pull/2712#discussion_r2412363873
##########
rust/fory-core/src/resolver/type_resolver.rs:
##########
@@ -549,17 +521,17 @@ impl TypeResolver {
self.name_serializer_map.get(&key)
}
- pub fn get_ext_harness(&self, id: u32) -> Option<&ExtHarness> {
- self.ext_serializer_map.get(&id)
+ pub fn get_ext_harness(&self, id: u32) -> &Harness {
+ self.serializer_map
+ .get(&id)
+ .unwrap_or_else(|| panic!("ext type must be registered in both peers"))
}
- pub fn get_ext_name_harness(
- &self,
- namespace: &MetaString,
- type_name: &MetaString,
- ) -> Option<&ExtHarness> {
+ pub fn get_ext_name_harness(&self, namespace: &MetaString, type_name: &MetaString) -> &Harness {
let key = (namespace.clone(), type_name.clone());
- self.ext_name_serializer_map.get(&key)
+ self.name_serializer_map
+ .get(&key)
+ .unwrap_or_else(|| panic!("named_ext type must be registered in both peers"))
Review Comment:
```suggestion
.expect("named_ext type must be registered in both peers")
```
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376708438
```rust
fn fory_type_id_dyn(&self, fory: &Fory) -> u32 {
Self::fory_get_type_id(fory)
}
```
can be made as default impl in `Serializer` trait to make ext type impl more convenient
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376355397
For `as_any` on ext, it's just same as other types:
```rust
fn as_any(&self) -> &dyn std::any::Any {
self
}
```
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2712:
URL: https://github.com/apache/fory/pull/2712#discussion_r2412366228
##########
rust/fory-core/src/serializer/enum_.rs:
##########
@@ -59,13 +59,19 @@ pub fn write_type_info<T: Serializer>(context: &mut WriteContext, is_field: bool
let meta_index = context.push_meta(rs_type_id) as u32;
context.writer.write_varuint32(meta_index);
} else {
- let resolver = context.get_fory().get_type_resolver();
- let type_info = resolver.get_type_info(rs_type_id);
- let _namespace = type_info.get_namespace().to_owned();
- let _type_name = type_info.get_type_name().to_owned();
- unimplemented!("unimplement NamedEnum::write_type_info when non-share_meta")
- // context.writer.write_bytes(namespace.bytes.as_slice());
- // context.writer.write_bytes(type_name.bytes.as_slice());
+ let type_info = context
+ .get_fory()
+ .get_type_resolver()
+ .get_type_info(rs_type_id);
+ let namespace = type_info.get_namespace().to_owned();
+ let type_name = type_info.get_type_name().to_owned();
+ let resolver = context.get_fory().get_metastring_resolver();
Review Comment:
could we submit a new pr to split `metastring_resolver` into `metastring_write_resolver` and `metastring_read_resolver`, then put it into `ReadContext`/`WriteContext`?
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376361540
And the `fory_type_id_dyn` should be same as `fory_get_type_id`.
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3373019920
@chaokunyang Now cannot pass test in `test_rc_arc_trait_object.rs` and `test_object.rs`. What's more, now EXT seems need to implement `as_any` and `fory_type_id_dyn`, and I can't quickly know how to pass test in the tail of file `test_struct_enum.rs` and `test_cross_language.rs`. Could you help me? I'm going to fix #2713.
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376703013
@urlyy it's a little inconvenient, but it's necessary. We can't provide a blanket impl for `ForyDefault` trait to forward to rust `Default` trait, due to the limit that we can't provide `default` for `Rc<dyn Any>`.
You can provide a new macro `ForyDefault` which can be used to generate `ForyDefault` impl for a ext type. The impl can check whether `Default` is implemented. If true, then forward to that trait, otherwise, let `ForyDefault` to generate both `ForyDefault` and `Default` impl, which is exactly `ForyObject` did.
For `fn as_any(&self) -> &dyn std::any::Any`, I think it's acceptable, not too much code for user to write
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org
Re: [PR] feat(Rust): named_xx se/de && ext se/de && add unittest [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2712:
URL: https://github.com/apache/fory/pull/2712#issuecomment-3376743708
> ```rust
> fn fory_type_id_dyn(&self, fory: &Fory) -> u32 {
> Self::fory_get_type_id(fory)
> }
> ```
>
> can be made as default impl in `Serializer` trait to make ext type impl more convenient
No, it must implement as
```rust
fn fory_type_id_dyn(&self, fory: &Fory) -> u32 where Self: Sized {
Self::fory_get_type_id(fory)
}
```
Because:
<img width="641" height="245" alt="image" src="https://github.com/user-attachments/assets/9d66765f-bcaf-4680-b61e-ba2ca7b40a37" />
And after doing so, the \<dyn Serializer\>will have some error.
<img width="805" height="493" alt="image" src="https://github.com/user-attachments/assets/bf35514e-278a-480a-ba9c-fef47da467a3" />
--
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: commits-unsubscribe@fory.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org