This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury-site.git
The following commit(s) were added to refs/heads/main by this push:
new 0988234 docs: translate start folder content (#167)
0988234 is described below
commit 09882340a5f4a16a8f968cf92faed927bd2f43f6
Author: YuLuo <[email protected]>
AuthorDate: Thu Aug 22 20:08:31 2024 +0800
docs: translate start folder content (#167)
Signed-off-by: yuluo-yx <[email protected]>
Co-authored-by: Shawn Yang <[email protected]>
---
.../current/start/install.md | 25 +++
.../current/start/usage.md | 191 +++++++++++++++++++++
2 files changed, 216 insertions(+)
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/install.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/install.md
new file mode 100644
index 0000000..edcb489
--- /dev/null
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/install.md
@@ -0,0 +1,25 @@
+---
+id: install
+title: 安装 Apache Fury
+sidebar_position: 0
+---
+
+Apache Fury 源码下载请参见 Apache Fury
[download](https://github.com/apache/fury/releases)页面。
+
+### Java 版本
+
+要使用 Maven 添加对 Apache Fury 的依赖项,请使用以下命令:
+
+```xml
+<dependency>
+ <groupId>org.apache.fury</groupId>
+ <artifactId>fury-core</artifactId>
+ <version>0.7.0</version>
+</dependency>
+<!-- row/arrow format support -->
+<!-- <dependency>
+ <groupId>org.apache.fury</groupId>
+ <artifactId>fury-format</artifactId>
+ <version>0.7.0</version>
+</dependency> -->
+```
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/usage.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/usage.md
new file mode 100644
index 0000000..8f7b3a5
--- /dev/null
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/start/usage.md
@@ -0,0 +1,191 @@
+---
+id: usage
+title: Apache Fury 使用
+sidebar_position: 1
+---
+
+本章节演示不同编程语言使用 Apache Fury 进行序列化。
+
+## Java 序列化
+
+```java
+import java.util.List;
+import java.util.Arrays;
+import io.fury.*;
+
+public class Example {
+ public static void main(String[] args) {
+ SomeClass object = new SomeClass();
+ // Note that Fury instances should be reused between
+ // multiple serializations of different objects.
+ Fury fury = Fury.builder().withLanguage(Language.JAVA)
+ // Allow to deserialize objects unknown types,
+ // more flexible but less secure.
+ // .withSecureMode(false)
+ .build();
+ // Registering types can reduce class name serialization overhead, but not
mandatory.
+ // If secure mode enabled, all custom types must be registered.
+ fury.register(SomeClass.class);
+ byte[] bytes = fury.serialize(object);
+ System.out.println(fury.deserialize(bytes));
+ }
+}
+```
+
+## 跨语言序列化
+
+### Java
+
+```java
+import com.google.common.collect.ImmutableMap;
+import io.fury.*;
+
+import java.util.Map;
+
+public class ReferenceExample {
+ public static class SomeClass {
+ SomeClass f1;
+ Map<String, String> f2;
+ Map<String, String> f3;
+ }
+
+ public static Object createObject() {
+ SomeClass obj = new SomeClass();
+ obj.f1 = obj;
+ obj.f2 = ImmutableMap.of("k1", "v1", "k2", "v2");
+ obj.f3 = obj.f2;
+ return obj;
+ }
+
+ // mvn exec:java -Dexec.mainClass="io.fury.examples.ReferenceExample"
+ public static void main(String[] args) {
+ Fury fury = Fury.builder().withLanguage(Language.XLANG)
+ .withRefTracking(true).build();
+ fury.register(SomeClass.class, "example.SomeClass");
+ byte[] bytes = fury.serialize(createObject());
+ // bytes can be data serialized by other languages.
+ System.out.println(fury.deserialize(bytes));
+ ;
+ }
+}
+```
+
+### Python
+
+```python
+from typing import Dict
+import pyfury
+
+class SomeClass:
+ f1: "SomeClass"
+ f2: Dict[str, str]
+ f3: Dict[str, str]
+
+fury = pyfury.Fury(ref_tracking=True)
+fury.register_class(SomeClass, "example.SomeClass")
+obj = SomeClass()
+obj.f2 = {"k1": "v1", "k2": "v2"}
+obj.f1, obj.f3 = obj, obj.f2
+data = fury.serialize(obj)
+# bytes can be data serialized by other languages.
+print(fury.deserialize(data))
+```
+
+### Golangs
+
+```go
+package main
+
+import (
+ "fmt"
+ furygo "github.com/apache/fury/go/fury"
+)
+
+func main() {
+ type SomeClass struct {
+ F1 *SomeClass
+ F2 map[string]string
+ F3 map[string]string
+ }
+ fury := furygo.NewFury(true)
+ if err := fury.RegisterTagType("example.SomeClass", SomeClass{}); err != nil {
+ panic(err)
+ }
+ value := &SomeClass{F2: map[string]string{"k1": "v1", "k2": "v2"}}
+ value.F3 = value.F2
+ value.F1 = value
+ bytes, err := fury.Marshal(value)
+ if err != nil {
+ }
+ var newValue interface{}
+ // bytes can be data serialized by other languages.
+ if err := fury.Unmarshal(bytes, &newValue); err != nil {
+ panic(err)
+ }
+ fmt.Println(newValue)
+}
+```
+
+### JavaScript
+
+```typescript
+import Fury, { Type } from '@furyjs/fury';
+
+/**
+ * @furyjs/hps use v8's fast-calls-api that can be called directly by jit,
ensure that the version of Node is 20 or above.
+ * Experimental feature, installation success cannot be guaranteed at this
moment
+ * If you are unable to install the module, replace it with `const hps = null;`
+ **/
+import hps from '@furyjs/hps';
+
+// Now we describe data structures using JSON, but in the future, we will use
more ways.
+const description = Type.object('example.foo', {
+ foo: Type.string(),
+});
+const fury = new Fury({ hps });
+const { serialize, deserialize } = fury.registerSerializer(description);
+const input = serialize({ foo: 'hello fury' });
+const result = deserialize(input);
+console.log(result);
+```
+
+### Rust
+
+```rust
+use fury::{from_buffer, to_buffer, Fury};
+
+#[derive(Fury, Debug, PartialEq)]
+#[tag("example.foo")]
+struct Animal {
+ name: String,
+ category: String,
+}
+
+#[derive(Fury, Debug, PartialEq)]
+#[tag("example.bar")]
+struct Person {
+ name: String,
+ age: u32,
+ pets: Vec<Animal>,
+}
+
+fn main() {
+ let penson = Person {
+ name: "hello".to_string(),
+ age: 12,
+ pets: vec![
+ Animal {
+ name: "world1".to_string(),
+ category: "cat".to_string(),
+ },
+ Animal {
+ name: "world2".to_string(),
+ category: "dog".to_string(),
+ },
+ ],
+ };
+ let bin = to_buffer(&penson);
+ let obj: Person = from_buffer(&bin).expect("should success");
+ assert_eq!(obj, penson);
+}
+```
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]