This is an automated email from the ASF dual-hosted git repository. chaokunyang pushed a commit to branch update_docs in repository https://gitbox.apache.org/repos/asf/fory-site.git
commit d4a07a2334f7e12c45c2d33356812f3d1067ccb4 Author: chaokunyang <[email protected]> AuthorDate: Tue Aug 4 11:51:26 2026 +0800 docs: use Rust in xlang example --- docs/object-serialization/xlang.md | 28 ++++++++++++---------- .../current/object-serialization/xlang.md | 28 ++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/docs/object-serialization/xlang.md b/docs/object-serialization/xlang.md index 8a900b9ae9..bfd8ea7b4f 100644 --- a/docs/object-serialization/xlang.md +++ b/docs/object-serialization/xlang.md @@ -64,21 +64,25 @@ Python pickle-compatible objects. Register the same logical type identity and compatible fields on every peer. The following example uses a shared type name. -Java producer: +Rust producer: -```java -public class Person { - public String name; - public int age; +```rust +use fory::{Fory, ForyStruct}; + +#[derive(ForyStruct)] +struct Person { + name: String, + age: i32, } -Fory fory = Fory.builder().withXlang(true).build(); -fory.register(Person.class, "example.Person"); +let mut fory = Fory::builder().xlang(true).build(); +fory.register_by_name::<Person>("example.Person").unwrap(); -Person person = new Person(); -person.name = "Alice"; -person.age = 30; -byte[] bytes = fory.serialize(person); +let person = Person { + name: "Alice".to_string(), + age: 30, +}; +let bytes = fory.serialize(&person).unwrap(); ``` Python consumer: @@ -94,7 +98,7 @@ class Person: fory = pyfory.Fory(xlang=True) fory.register_type(Person, name="example.Person") -person = fory.deserialize(bytes_from_java) +person = fory.deserialize(bytes_from_rust) ``` Although xlang is the default, examples often select it explicitly so the transport contract is diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/object-serialization/xlang.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/object-serialization/xlang.md index 57ca6f5da7..06401304ed 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/object-serialization/xlang.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/object-serialization/xlang.md @@ -61,21 +61,25 @@ pickle 兼容对象等语言特有行为,请改用[原生序列化](native.md) 每个通信方都必须为同一个逻辑类型注册相同的类型标识和兼容字段。下面的示例使用共享类型名称。 -Java 写入端: +Rust 写入端: -```java -public class Person { - public String name; - public int age; +```rust +use fory::{Fory, ForyStruct}; + +#[derive(ForyStruct)] +struct Person { + name: String, + age: i32, } -Fory fory = Fory.builder().withXlang(true).build(); -fory.register(Person.class, "example.Person"); +let mut fory = Fory::builder().xlang(true).build(); +fory.register_by_name::<Person>("example.Person").unwrap(); -Person person = new Person(); -person.name = "Alice"; -person.age = 30; -byte[] bytes = fory.serialize(person); +let person = Person { + name: "Alice".to_string(), + age: 30, +}; +let bytes = fory.serialize(&person).unwrap(); ``` Python 读取端: @@ -91,7 +95,7 @@ class Person: fory = pyfory.Fory(xlang=True) fory.register_type(Person, name="example.Person") -person = fory.deserialize(bytes_from_java) +person = fory.deserialize(bytes_from_rust) ``` 虽然 xlang 是默认模式,示例通常仍会显式选择它,以便在应用代码中明确表达传输约定。 --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
