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/fory-site.git
The following commit(s) were added to refs/heads/main by this push:
new a5f42fd3c4 🔄 synced local 'docs/compiler/' with remote 'docs/compiler/'
a5f42fd3c4 is described below
commit a5f42fd3c47fec247c0de010785dc2ba862721c4
Author: chaokunyang <[email protected]>
AuthorDate: Thu Jan 29 11:32:30 2026 +0000
🔄 synced local 'docs/compiler/' with remote 'docs/compiler/'
---
docs/compiler/compiler-guide.md | 27 ++++++++++
docs/compiler/generated-code.md | 112 +++++++++++++++++++++++-----------------
2 files changed, 93 insertions(+), 46 deletions(-)
diff --git a/docs/compiler/compiler-guide.md b/docs/compiler/compiler-guide.md
index 3885a683e6..983ccc2e48 100644
--- a/docs/compiler/compiler-guide.md
+++ b/docs/compiler/compiler-guide.md
@@ -44,6 +44,10 @@ fory compile --help
fory compile [OPTIONS] FILES...
```
+```bash
+fory scan-generated [OPTIONS]
+```
+
### Options
| Option | Description
| Default |
@@ -59,6 +63,29 @@ fory compile [OPTIONS] FILES...
| `--rust_out=DST_DIR` | Generate Rust code in DST_DIR
| (none) |
| `--go_nested_type_style` | Go nested type naming: `camelcase`
or `underscore` | (none) |
+### Scan Generated Files
+
+Use `scan-generated` to find files produced by the Fory compiler. The scanner
walks
+the tree recursively, skips `build/`, `target/`, and hidden directories, and
prints
+each generated file as it is found.
+
+```bash
+# Scan current directory
+fory scan-generated
+
+# Scan a specific root
+fory scan-generated --root ./src
+
+# Print paths relative to the scan root
+fory scan-generated --root ./src --relative
+
+# Delete scanned generated files
+fory scan-generated --root ./src --delete
+
+# Dry-run (scan and print only)
+fory scan-generated --root ./src --dry-run
+```
+
### Examples
**Compile for all languages:**
diff --git a/docs/compiler/generated-code.md b/docs/compiler/generated-code.md
index 11c91348c8..92708c9bdc 100644
--- a/docs/compiler/generated-code.md
+++ b/docs/compiler/generated-code.md
@@ -367,9 +367,24 @@ public class Order {
package demo;
import org.apache.fory.Fory;
+import org.apache.fory.ThreadSafeFory;
+import org.apache.fory.pool.SimpleForyPool;
public class DemoForyRegistration {
+ private static ThreadSafeFory createFory() {
+ ThreadSafeFory fory = new SimpleForyPool(c -> Fory.builder()
+ .withXlang(true)
+ .withRefTracking(true)
+ .build());
+ fory.registerCallback(f -> registerAllTypes(f));
+ return fory;
+ }
+
+ private static void registerAllTypes(Fory fory) {
+ register(fory);
+ }
+
public static void register(Fory fory) {
fory.register(Status.class, 100);
fory.register(User.class, 101);
@@ -378,22 +393,16 @@ public class DemoForyRegistration {
}
```
+`register` only contains types defined in the current file. The generated
+`registerAllTypes` registers imported types first and then calls `register`.
+
### Usage
```java
import demo.*;
-import org.apache.fory.Fory;
-import org.apache.fory.config.Language;
public class Example {
public static void main(String[] args) {
- Fory fory = Fory.builder()
- .withLanguage(Language.XLANG)
- .withRefTracking(true)
- .build();
-
- DemoForyRegistration.register(fory);
-
User user = new User();
user.setId("u123");
user.setName("Alice");
@@ -404,8 +413,8 @@ public class Example {
order.setCustomer(user);
order.setStatus(Status.ACTIVE);
- byte[] bytes = fory.serialize(order);
- Order restored = (Order) fory.deserialize(bytes);
+ byte[] bytes = order.toBytes();
+ Order restored = Order.fromBytes(bytes);
}
}
```
@@ -450,16 +459,20 @@ def register_demo_types(fory: pyfory.Fory):
fory.register_type(Status, type_id=100)
fory.register_type(User, type_id=101)
fory.register_type(Order, type_id=102)
+
+
+def _register_all_types(fory: pyfory.Fory):
+ register_demo_types(fory)
```
+`register_demo_types` only contains types defined in the current file. The
+generated `_register_all_types` registers imported types first and then calls
+`register_demo_types`.
+
### Usage
```python
-import pyfory
-from demo import User, Order, Status, register_demo_types
-
-fory = pyfory.Fory(ref_tracking=True)
-register_demo_types(fory)
+from demo import User, Order, Status
user = User(id="u123", name="Alice", age=30)
order = Order(
@@ -470,8 +483,8 @@ order = Order(
status=Status.ACTIVE
)
-data = fory.serialize(order)
-restored = fory.deserialize(data)
+data = order.to_bytes()
+restored = Order.from_bytes(data)
```
## Go
@@ -522,8 +535,18 @@ func RegisterTypes(f *fory.Fory) error {
}
return nil
}
+
+func registerAllTypes(f *fory.Fory) error {
+ if err := RegisterTypes(f); err != nil {
+ return err
+ }
+ return nil
+}
```
+`RegisterTypes` only contains types defined in the current file. The generated
+`registerAllTypes` registers imported types first and then calls
`RegisterTypes`.
+
### Usage
```go
@@ -531,16 +554,9 @@ package main
import (
"demo"
- fory "github.com/apache/fory/go/fory"
)
func main() {
- f := fory.NewFory(true) // Enable ref tracking
-
- if err := demo.RegisterTypes(f); err != nil {
- panic(err)
- }
-
email := "[email protected]"
user := &demo.User{
Id: "u123",
@@ -559,14 +575,12 @@ func main() {
},
Status: demo.StatusActive,
}
-
- bytes, err := f.Marshal(order)
+ bytes, err := order.ToBytes()
if err != nil {
panic(err)
}
-
var restored demo.Order
- if err := f.Unmarshal(bytes, &restored); err != nil {
+ if err := restored.FromBytes(bytes); err != nil {
panic(err)
}
}
@@ -616,8 +630,17 @@ pub fn register_types(fory: &mut Fory) -> Result<(),
fory::Error> {
fory.register::<Order>(102)?;
Ok(())
}
+
+fn register_all_types(fory: &mut Fory) -> Result<(), fory::Error> {
+ register_types(fory)?;
+ Ok(())
+}
```
+`register_types` only contains types defined in the current file. The generated
+`register_all_types` registers imported types first and then calls
+`register_types`.
+
**Note:** Rust uses `Arc` by default for `ref` fields. In FDL, use
`ref(thread_safe = false)` to generate `Rc`, and `ref(weak = true)` to generate
`ArcWeak`/`RcWeak`. For protobuf/IDL extensions, use
@@ -626,15 +649,11 @@ pub fn register_types(fory: &mut Fory) -> Result<(),
fory::Error> {
### Usage
```rust
-use demo::{User, Order, Status, register_types};
-use fory::Fory;
+use demo::{User, Order, Status};
use std::sync::Arc;
use std::collections::HashMap;
fn main() -> Result<(), fory::Error> {
- let mut fory = Fory::default();
- register_types(&mut fory)?;
-
let user = Arc::new(User {
id: "u123".to_string(),
name: "Alice".to_string(),
@@ -654,8 +673,8 @@ fn main() -> Result<(), fory::Error> {
status: Status::Active,
};
- let bytes = fory.serialize(&order)?;
- let restored: Order = fory.deserialize(&bytes)?;
+ let bytes = order.to_bytes()?;
+ let restored = Order::from_bytes(&bytes)?;
Ok(())
}
@@ -721,17 +740,25 @@ struct Order {
};
FORY_STRUCT(Order, id, customer, items, quantities, status);
-inline void RegisterTypes(fory::serialization::Fory& fory) {
+inline void register_types(fory::serialization::BaseFory& fory) {
fory.register_enum<Status>(100);
fory.register_struct<User>(101);
fory.register_struct<Order>(102);
}
+inline void register_all_types(fory::serialization::BaseFory& fory) {
+ register_types(fory);
+}
+
} // namespace demo
#endif // DEMO_H_
```
+`register_types` only contains types defined in the current file. The generated
+`register_all_types` registers imported types first and then calls
+`register_types`.
+
### Usage
```cpp
@@ -739,13 +766,6 @@ inline void RegisterTypes(fory::serialization::Fory& fory)
{
#include <iostream>
int main() {
- fory::serialization::Fory fory = fory::serialization::Fory::builder()
- .xlang(true)
- .ref_tracking(true)
- .build();
-
- demo::RegisterTypes(fory);
-
auto user = std::make_shared<demo::User>();
user->id = "u123";
user->name = "Alice";
@@ -759,8 +779,8 @@ int main() {
order.quantities = {{"item1", 2}, {"item2", 1}};
order.status = demo::Status::ACTIVE;
- auto bytes = fory.serialize(order);
- auto restored = fory.deserialize<demo::Order>(bytes);
+ auto bytes = order.to_bytes();
+ auto restored = demo::Order::from_bytes(bytes.value());
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]