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/09/26 17:28:31 UTC
[PR] refactor(Rust): Refine api name [fory]
urlyy opened a new pull request, #2671:
URL: https://github.com/apache/fory/pull/2671
## What does this PR do?
1. Use `read/write_xxx` style APIs for Buffer methods to align with Java API naming.
2. Add `fory_` prefix to `Serializer` and `StructSerializer` trait methods, to avoid name conflict in user struct when it implement other trait with same method name.
3. Organize the APIs on the trait with hierarchical naming `fory_read`,`fory_read_type_info`,`fory_read_data`. The same applies to the write API. Separate it from Fory’s `serialize`/`deserialize` methods.
## Related issues
- #2658
## Does this PR introduce any user-facing change?
If users wan't to call methods on user-defined struct instance, they need to use methods whose prefix is `fory_`.
--
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] refactor(Rust): Refine api name [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2671:
URL: https://github.com/apache/fory/pull/2671#issuecomment-3346585762
Btw,a struct without use Fory derive but only impl Serializer trait,only can be registered by calling register_serializer
--
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] refactor(Rust): Refine api name [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2671:
URL: https://github.com/apache/fory/pull/2671#issuecomment-3346497337
User now can customize Serializer:
```rust
#[test]
fn test_use() {
use fory_core::fory::{read, write};
#[derive(Debug, PartialEq, Default)]
struct Item {
f1: i32,
f2: i8,
}
impl Serializer for Item {
fn fory_write_data(&self, context: &mut WriteContext, is_field: bool) {
write(&self.f1, context, is_field);
}
fn fory_read_data(context: &mut ReadContext, is_field: bool) -> Result<Self, Error> {
Ok(Self {
f1: read(context, is_field)?,
f2: 0,
})
}
}
let mut fory = Fory::default().mode(Compatible).xlang(true);
fory.register_serializer::<Item>(100);
let item = Item { f1: 1, f2: 2 };
let bytes = fory.serialize(&item);
let new_item: Item = fory.deserialize(&bytes).unwrap();
assert_eq!(new_item.f1, item.f1);
assert_eq!(new_item.f2, 0);
}
```
--
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] refactor(Rust): Refine api name [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on PR #2671:
URL: https://github.com/apache/fory/pull/2671#issuecomment-3346613704
Do not use varian, it's a type for values of different types
--
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] refactor(Rust): Refine api name [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on code in PR #2671:
URL: https://github.com/apache/fory/pull/2671#discussion_r2383821945
##########
rust/fory-core/src/meta/type_meta.rs:
##########
@@ -504,11 +504,11 @@ impl TypeMeta {
}
let meta_hash = murmurhash3_x64_128(layers_writer.dump().as_slice(), 47).0 as i64;
header |= (meta_hash << (64 - NUM_HASH_BITS)).abs();
- result.i64(header);
+ result.write_i64(header);
if meta_size >= META_SIZE_MASK {
- result.var_uint32((meta_size - META_SIZE_MASK) as u32);
+ result.write_var_uint32((meta_size - META_SIZE_MASK) as u32);
Review Comment:
Ok, I will replace other.
--
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] refactor(Rust): Refine api name [fory]
Posted by "urlyy (via GitHub)" <gi...@apache.org>.
urlyy commented on PR #2671:
URL: https://github.com/apache/fory/pull/2671#issuecomment-3346493663
The new commit includes the following changes:
1. Previously, `metastring_encoder` converted `string -> MetaString`, but the decoder converted `bytes -> string`. This commit aligns the decoder with the encoder, now converting `bytes -> MetaString`, providing support for future enhancements to `named_enum`, `named_ext`, and `named_struct`.
2. Renamed `var_uint` and `var_int` to `variant` and `varint`.
--
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] refactor(Rust): Refine api name [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on code in PR #2671:
URL: https://github.com/apache/fory/pull/2671#discussion_r2383775943
##########
rust/fory-core/src/meta/type_meta.rs:
##########
@@ -504,11 +504,11 @@ impl TypeMeta {
}
let meta_hash = murmurhash3_x64_128(layers_writer.dump().as_slice(), 47).0 as i64;
header |= (meta_hash << (64 - NUM_HASH_BITS)).abs();
- result.i64(header);
+ result.write_i64(header);
if meta_size >= META_SIZE_MASK {
- result.var_uint32((meta_size - META_SIZE_MASK) as u32);
+ result.write_var_uint32((meta_size - META_SIZE_MASK) as u32);
Review Comment:
```suggestion
result.write_varuint32((meta_size - META_SIZE_MASK) as u32);
```
`varuint32` is more idiomatic
--
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] refactor(Rust): Refine api name [fory]
Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang merged PR #2671:
URL: https://github.com/apache/fory/pull/2671
--
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