Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,9 @@ val fory = ForyKotlin.builder()

Fory IDL is Fory's schema language for shared data models. It supports
references, nullable fields, lists, maps, arrays, enums, messages, and unions,
and generates native data structures for supported languages. Use it when
multiple languages need one shared contract.
and generates native data structures for Java, Python, C++, Go, Rust,
JavaScript/TypeScript, C#, Swift, Dart, Scala, and Kotlin. Use it when multiple
languages need one shared contract.

```protobuf
package tree;
Expand Down
20 changes: 17 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# User Guide

- For xlang serialization, see the [xlang guide](guide/xlang/index.md).
- For Java serialization, see the [Java guide](guide/java/index.md).
- For language-specific serialization, see the [Java](guide/java/index.md),
[Python](guide/python/index.md), [C++](guide/cpp/index.md),
[Go](guide/go/index.md), [Rust](guide/rust/index.md),
[JavaScript/TypeScript](guide/javascript/index.md),
[C#](guide/csharp/index.md), [Swift](guide/swift/index.md),
[Dart](guide/dart/index.md), [Scala](guide/scala/index.md), and
[Kotlin](guide/kotlin/index.md) guides.
- For row format, see the [row format spec](specification/row_format_spec.md).
- For Scala serialization, see the [Scala guide](guide/scala/index.md).
- For using Apache Fory™ with GraalVM native image, see [graalvm support](guide/java/graalvm-support.md) doc.

## Fory IDL Schema
Expand All @@ -28,10 +33,19 @@ Define cross-language data structures with Fory IDL and generate native code for
- Benchmark source code:
- Java: [Java Benchmarks Source](../benchmarks/java)
- Python: [Python Benchmarks Source](../benchmarks/python)
- C++: [C++ Benchmarks Source](../benchmarks/cpp)
- Go: [Go Benchmarks Source](../benchmarks/go)
- Rust: [Rust Benchmarks Source](../benchmarks/rust/)
- Benchmark result:
- Java: [Java Benchmarks](benchmarks/java/)
- Rust: [Rust Benchmarks](benchmarks/rust).
- Python: [Python Benchmarks](benchmarks/python/)
- C++: [C++ Benchmarks](benchmarks/cpp/)
- Go: [Go Benchmarks](benchmarks/go/)
- Rust: [Rust Benchmarks](benchmarks/rust/)
- JavaScript/TypeScript: [JavaScript Benchmarks](benchmarks/javascript/)
- C#: [C# Benchmarks](benchmarks/csharp/)
- Swift: [Swift Benchmarks](benchmarks/swift/)
- Dart: [Dart Benchmarks](benchmarks/dart/)

## Development

Expand Down
53 changes: 36 additions & 17 deletions docs/compiler/compiler-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Compile options:
| `--go_out=DST_DIR` | Generate Go code in DST_DIR | (none) |
| `--rust_out=DST_DIR` | Generate Rust code in DST_DIR | (none) |
| `--csharp_out=DST_DIR` | Generate C# code in DST_DIR | (none) |
| `--javascript_out=DST_DIR` | Generate JavaScript code in DST_DIR | (none) |
| `--javascript_out=DST_DIR` | Generate JavaScript/TypeScript code in DST_DIR | (none) |
| `--swift_out=DST_DIR` | Generate Swift code in DST_DIR | (none) |
| `--dart_out=DST_DIR` | Generate Dart code in DST_DIR | (none) |
| `--scala_out=DST_DIR` | Generate Scala 3 code in DST_DIR | (none) |
Expand Down Expand Up @@ -123,7 +123,7 @@ foryc --scan-generated --root ./src --dry-run
foryc schema.fdl
```

**Compile for specific languages:**
**Compile for a selected subset of languages:**

```bash
foryc schema.fdl --lang java,python,csharp,javascript,swift,dart,kotlin
Expand Down Expand Up @@ -185,7 +185,7 @@ foryc src/main.fdl -I libs/common,libs/types --proto_path third_party/
foryc schema.fdl --java_out=./src/main/java

# Generate multiple languages to different directories
foryc schema.fdl --java_out=./java/gen --python_out=./python/src --go_out=./go/gen --csharp_out=./csharp/gen --javascript_out=./javascript/src --swift_out=./swift/gen --dart_out=./dart/gen --kotlin_out=./kotlin/gen
foryc schema.fdl --java_out=./java/gen --python_out=./python/src --cpp_out=./cpp/gen --go_out=./go/gen --rust_out=./rust/gen --csharp_out=./csharp/gen --javascript_out=./javascript/src --swift_out=./swift/gen --dart_out=./dart/gen --scala_out=./scala/gen --kotlin_out=./kotlin/gen

# Combine with import paths
foryc schema.fdl --java_out=./gen/java -I proto/ -I common/
Expand Down Expand Up @@ -260,19 +260,19 @@ Compiling src/main.fdl...

## Supported Languages

| Language | Flag | Output Extension | Description |
| ---------- | ------------ | ---------------- | -------------------------------------- |
| Java | `java` | `.java` | POJOs with Fory annotations |
| Python | `python` | `.py` | Dataclasses with type hints |
| Go | `go` | `.go` | Structs with struct tags |
| Rust | `rust` | `.rs` | Structs with derive macros |
| C++ | `cpp` | `.h` | Structs with FORY macros |
| C# | `csharp` | `.cs` | Classes with Fory attributes |
| JavaScript | `javascript` | `.ts` | Interfaces with registration function |
| Swift | `swift` | `.swift` | Fory Swift model macros |
| Dart | `dart` | `.dart` | `@ForyStruct` classes with annotations |
| Scala | `scala` | `.scala` | Scala 3 models with macro derivation |
| Kotlin | `kotlin` | `.kt` | Kotlin models with KSP serializers |
| Language | Flag | Output Extension | Description |
| --------------------- | ------------ | ---------------- | -------------------------------------- |
| Java | `java` | `.java` | POJOs with Fory annotations |
| Python | `python` | `.py` | Dataclasses with type hints |
| Go | `go` | `.go` | Structs with struct tags |
| Rust | `rust` | `.rs` | Structs with derive macros |
| C++ | `cpp` | `.h` | Structs with FORY macros |
| C# | `csharp` | `.cs` | Classes with Fory attributes |
| JavaScript/TypeScript | `javascript` | `.ts` | Interfaces with registration function |
| Swift | `swift` | `.swift` | Fory Swift model macros |
| Dart | `dart` | `.dart` | `@ForyStruct` classes with annotations |
| Scala | `scala` | `.scala` | Scala 3 models with macro derivation |
| Kotlin | `kotlin` | `.kt` | Kotlin models with KSP serializers |

## Output Structure

Expand Down Expand Up @@ -342,7 +342,7 @@ generated/
- Namespace matches package (dots to `::`)
- Header guards and forward declarations

### JavaScript
### JavaScript/TypeScript

```
generated/
Expand Down Expand Up @@ -422,6 +422,25 @@ generated/
- Unions use Scala 3 ADT `enum` with `@ForyUnion`, `@ForyCase`, and an `UnknownCase`
- Schema module object included

### Kotlin

```
generated/
└── kotlin/
└── example/
├── User.kt
├── Status.kt
├── Animal.kt
└── ExampleForyModule.kt
```

- One Kotlin source file per generated type
- Package structure uses `kotlin_package` when set, otherwise the Fory IDL package
- Messages use `@ForyStruct` and KSP-generated serializers
- Enums use stable Fory enum IDs
- Unions use sealed classes with `@ForyUnion`, `@ForyCase`, and an unknown-case carrier
- Schema module object included

### C# IDL Matrix Verification

Run the end-to-end C# IDL matrix (FDL/IDL/Proto/FBS generation plus roundtrip tests):
Expand Down
6 changes: 4 additions & 2 deletions docs/compiler/flatbuffers-idl.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ table Node {
Using `.fbs` as input to Fory still produces normal Fory-generated code, not
FlatBuffers `ByteBuffer`-style APIs.

- Java: POJOs/records with Fory metadata
- Java, Scala, and Kotlin: JVM model types with Fory metadata and registration helpers
- Python: dataclasses plus registration helpers
- Go/Rust/C++: native structs and Fory metadata
- C++, Go, and Rust: native structs and Fory metadata
- JavaScript/TypeScript: TypeScript interfaces and registration helpers
- C#, Swift, and Dart: annotated or macro-based model types with registration helpers

The serialization format is Fory binary protocol, not FlatBuffers wire format.

Expand Down
54 changes: 28 additions & 26 deletions docs/compiler/generated-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,11 @@ public static class AddressbookForyRegistration
When explicit type IDs are not provided, generated registration uses computed
numeric IDs (same behavior as other targets).

## JavaScript
## JavaScript/TypeScript

### Output Layout

JavaScript output is one `.ts` file per schema, for example:
JavaScript/TypeScript output is one `.ts` file per schema, for example:

- `<javascript_out>/addressbook.ts`

Expand Down Expand Up @@ -1376,30 +1376,32 @@ object AddressbookForyModule extends org.apache.fory.ForyModule {

### Nested Type Shape

| Language | Nested type form |
| ---------- | ------------------------------ |
| Java | `Person.PhoneNumber` |
| Python | `Person.PhoneNumber` |
| Rust | `person::PhoneNumber` |
| C++ | `Person::PhoneNumber` |
| Go | `Person_PhoneNumber` (default) |
| C# | `Person.PhoneNumber` |
| JavaScript | `Person.PhoneNumber` |
| Swift | `Person.PhoneNumber` |
| Dart | `Person_PhoneNumber` |
| Language | Nested type form |
| --------------------- | ------------------------------ |
| Java | `Person.PhoneNumber` |
| Python | `Person.PhoneNumber` |
| Rust | `person::PhoneNumber` |
| C++ | `Person::PhoneNumber` |
| Go | `Person_PhoneNumber` (default) |
| C# | `Person.PhoneNumber` |
| JavaScript/TypeScript | `Person.PhoneNumber` |
| Swift | `Person.PhoneNumber` |
| Dart | `Person_PhoneNumber` |
| Kotlin | `PersonPhoneNumber` |
| Scala | `Person.PhoneNumber` |

### Byte Helper Naming

| Language | Helpers |
| ---------- | ------------------------- |
| Java | `toBytes` / `fromBytes` |
| Kotlin | `toBytes` / `fromBytes` |
| Scala | `toBytes` / `fromBytes` |
| Python | `to_bytes` / `from_bytes` |
| Rust | `to_bytes` / `from_bytes` |
| C++ | `to_bytes` / `from_bytes` |
| Go | `ToBytes` / `FromBytes` |
| C# | `ToBytes` / `FromBytes` |
| JavaScript | (via `fory.serialize()`) |
| Swift | `toBytes` / `fromBytes` |
| Dart | (via `fory.serialize()`) |
| Language | Helpers |
| --------------------- | ------------------------- |
| Java | `toBytes` / `fromBytes` |
| Kotlin | `toBytes` / `fromBytes` |
| Scala | `toBytes` / `fromBytes` |
| Python | `to_bytes` / `from_bytes` |
| Rust | `to_bytes` / `from_bytes` |
| C++ | `to_bytes` / `from_bytes` |
| Go | `ToBytes` / `FromBytes` |
| C# | `ToBytes` / `FromBytes` |
| JavaScript/TypeScript | (via `fory.serialize()`) |
| Swift | `toBytes` / `fromBytes` |
| Dart | (via `fory.serialize()`) |
21 changes: 11 additions & 10 deletions docs/compiler/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ license: |

Fory IDL is a schema definition language for Apache Fory that enables type-safe
cross-language serialization. Define your data structures once and generate
native data structure code for Java, Python, Go, Rust, C++, C#, Swift,
JavaScript, Dart, Scala, and Kotlin. Fory IDL can also describe RPC services;
for Java and Python, the compiler can generate gRPC service companions that use
Fory serialization for request and response payloads.
native data structure code for Java, Python, C++, Go, Rust,
JavaScript/TypeScript, C#, Swift, Dart, Scala, and Kotlin. Fory IDL can also
describe RPC services; for Java and Python, the compiler can generate gRPC
service companions that use Fory serialization for request and response
payloads.

## Example Schema

Expand Down Expand Up @@ -128,7 +129,7 @@ Generated code uses native language constructs:
- Rust: Structs with `#[derive(ForyObject)]`
- C++: Structs with `FORY_STRUCT` macros
- C#: Classes with `[ForyObject]` and registration helpers
- JavaScript: Interfaces with registration function
- JavaScript/TypeScript: Interfaces with registration function
- Swift: Fory model macros with field/case metadata and registration helpers
- Dart: `@ForyStruct` classes with `@ForyField` annotations and registration helpers
- Scala: Scala 3 `case class`, normal class, enum, and ADT enum models with macro-derived serializers
Expand Down Expand Up @@ -227,11 +228,11 @@ message Example {

Fory IDL types map to native types in each language:

| Fory IDL Type | Java | Python | Go | Rust | C++ | C# | JavaScript | Swift | Dart | Scala |
| ------------- | --------- | -------------- | -------- | -------- | ------------- | -------- | ---------- | -------- | -------- | --------- |
| `int32` | `int` | `pyfory.Int32` | `int32` | `i32` | `int32_t` | `int` | `number` | `Int32` | `int` | `Int` |
| `string` | `String` | `str` | `string` | `String` | `std::string` | `string` | `string` | `String` | `String` | `String` |
| `bool` | `boolean` | `bool` | `bool` | `bool` | `bool` | `bool` | `boolean` | `Bool` | `bool` | `Boolean` |
| Fory IDL Type | Java | Python | C++ | Go | Rust | JavaScript/TypeScript | C# | Swift | Dart | Scala | Kotlin |
| ------------- | --------- | -------------- | ------------- | -------- | -------- | --------------------- | -------- | -------- | -------- | --------- | --------- |
| `int32` | `int` | `pyfory.Int32` | `int32_t` | `int32` | `i32` | `number` | `int` | `Int32` | `int` | `Int` | `Int` |
| `string` | `String` | `str` | `std::string` | `string` | `String` | `string` | `string` | `String` | `String` | `String` | `String` |
| `bool` | `boolean` | `bool` | `bool` | `bool` | `bool` | `boolean` | `bool` | `Bool` | `bool` | `Boolean` | `Boolean` |

See [Type System](schema-idl.md#type-system) for complete mappings.

Expand Down
Loading
Loading