### Install Go Package Source: https://github.com/apache/fory/blob/main/README.md Use 'go get' to install the Go client library for Apache Fory. ```bash go get github.com/apache/fory/go/fory ``` -------------------------------- ### Pyfory Python Development Setup Source: https://github.com/apache/fory/blob/main/docs/guide/python/troubleshooting.md Clone the Pyfory repository, navigate to the python directory, and install dependencies using pip. Run tests with pytest and format code using ruff. ```bash git clone https://github.com/apache/fory.git cd fory/python # Install dependencies pip install -e ".[dev,format]" # Run tests pytest -v -s . # Run specific test pytest -v -s pyfory/tests/test_serializer.py # Format code ruff format . ruff check --fix . ``` -------------------------------- ### Quick Start: Basic Serialization with pyfory Source: https://github.com/apache/fory/blob/main/docs/guide/python/index.md A basic example demonstrating how to serialize and deserialize a Python dataclass using pyfory in xlang mode. ```python import pyfory from dataclasses import dataclass @dataclass class Person: name: str age: int # Create an xlang Fory instance fory = pyfory.Fory(xlang=True, ref=True) fory.register(Person) person = Person("Alice", 30) data = fory.serialize(person) result = fory.deserialize(data) print(result) # Person(name='Alice', age=30) ``` -------------------------------- ### Benchmark Examples Source: https://github.com/apache/fory/blob/main/benchmarks/swift/README.md Examples of running the benchmark script with specific configurations for data types, serializers, and duration. ```bash # Run only NumericStruct benchmarks ./run.sh --data struct ``` ```bash # Run only protobuf benchmarks ./run.sh --serializer protobuf ``` ```bash # Run a single serializer and datatype ./run.sh --data sample --serializer json --duration 5 ``` ```bash # Skip report generation ./run.sh --no-report ``` -------------------------------- ### Build and Run Hello Row Example (Bazel) Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_row/README.md Build and run the hello_row example directly from the Fory repository using Bazel commands. ```bash bazel build //examples/cpp/hello_row:hello_row bazel run //examples/cpp/hello_row:hello_row ``` -------------------------------- ### Install pyfory with optional dependencies Source: https://github.com/apache/fory/blob/main/python/README.md Install pyfory with optional dependencies for row format support, which requires Apache Arrow. Also shows how to install from source for development. ```bash # Install with row format support (requires Apache Arrow) pip install pyfory[format] # Install from source for development git clone https://github.com/apache/fory.git cd fory/python pip install -e ".[dev,format]" ``` -------------------------------- ### Install Fory Generator Binary Source: https://github.com/apache/fory/blob/main/docs/guide/go/codegen.md Install the `fory` generator binary using `go install`. Ensure your `$GOBIN` or `$GOPATH/bin` is in your system's `PATH`. ```bash go install github.com/apache/fory/go/fory/cmd/fory@latest ``` ```bash GO111MODULE=on go get -u github.com/apache/fory/go/fory/cmd/fory ``` -------------------------------- ### Install pyfory with Format Support Source: https://github.com/apache/fory/blob/main/python/README.md Install the pyfory library with optional format support using pip. Alternatively, install from source with format support. ```bash pip install pyfory[format] ``` ```bash pip install -e ".[format]" ``` -------------------------------- ### Go Usage Example Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md A practical example demonstrating how to create, serialize, and deserialize a Go Person object. ```go person := &Person{ Name: "Alice", Pet: DogAnimal(&Dog{Name: "Rex"}), } data, err := person.ToBytes() if err != nil { panic(err) } var restored Person if err := restored.FromBytes(data); err != nil { panic(err) } ``` -------------------------------- ### Install pyfory from Source Source: https://github.com/apache/fory/blob/main/docs/guide/python/index.md Clone the repository and install pyfory from source for development, including optional dependencies. ```bash git clone https://github.com/apache/fory.git cd fory/python pip install -e ".[dev,format]" ``` -------------------------------- ### Run Hello Row Example (Bazel Script) Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_row/README.md Execute the provided run_bazel.sh script to build and run the hello_row example using Bazel. ```bash ./run_bazel.sh ``` -------------------------------- ### GitHub Actions Example for Fory IDL Generation Source: https://github.com/apache/fory/blob/main/docs/compiler/compiler-guide.md Demonstrates a GitHub Actions workflow step for installing the Fory compiler and generating types. ```yaml # GitHub Actions example steps: - name: Install Fory IDL Compiler run: pip install ./compiler - name: Generate Types run: foryc fdl/*.fdl --output src/generated - name: Build run: ./gradlew build ``` -------------------------------- ### Install @apache-fory/core Source: https://github.com/apache/fory/blob/main/javascript/packages/core/README.md Install the core package using npm. For optional Node.js string-detection acceleration, also install @apache-fory/hps. ```bash npm install @apache-fory/core ``` ```bash npm install @apache-fory/hps ``` -------------------------------- ### Build and Run Hello Row Example (CMake) Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_row/README.md Steps to build the hello_row example using CMake and then execute it. This includes creating a build directory, configuring with CMake, and building the project. ```bash cd examples/cpp/hello_row mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --parallel ./hello_row ``` -------------------------------- ### Install Benchmark Dependencies Source: https://github.com/apache/fory/blob/main/benchmarks/cpp/README.md Installs necessary Python packages for generating benchmark reports. Run this before generating reports. ```bash pip install matplotlib numpy psutil ``` -------------------------------- ### Quick Start: Scala Serialization Example Source: https://github.com/apache/fory/blob/main/docs/guide/scala/index.md Demonstrates basic Fory Scala serialization and deserialization of case classes using xlang mode. Ensure Fory Scala and Fory are imported, and the case classes are registered with the Fory builder. ```scala import org.apache.fory.Fory import org.apache.fory.scala.ForyScala case class Person(name: String, id: Long, github: String) case class Point(x: Int, y: Int, z: Int) object ScalaExample { val fory: Fory = ForyScala.builder() .withXlang(true) .build() fory.register(classOf[Person]) fory.register(classOf[Point]) def main(args: Array[String]): Unit = { val p = Person("Shawn Yang", 1, "https://github.com/chaokunyang") println(fory.deserialize(fory.serialize(p))) println(fory.deserialize(fory.serialize(Point(1, 2, 3)))) } } ``` -------------------------------- ### Install FDL Compiler Source: https://github.com/apache/fory/blob/main/compiler/README.md Install the FDL compiler using pip. Navigate to the compiler directory first. ```bash cd compiler pip install -e . ``` -------------------------------- ### Python Installation Source: https://github.com/apache/fory/blob/main/README.md Install the pyfory package for Python using pip. ```bash pip install pyfory ``` -------------------------------- ### Quick Start: Serialize and Deserialize User Data Source: https://github.com/apache/fory/blob/main/javascript/README.md Demonstrates how to define a user type, register it with Fory, serialize a user object to bytes, and deserialize it back. This example uses the core Fory runtime. ```typescript import Fory, { Type } from "@apache-fory/core"; // Optional: import hps for Node.js string performance boost // import hps from "@apache-fory/hps"; const userType = Type.struct( { typeName: "example.user" }, { id: Type.int64(), name: Type.string(), age: Type.int32(), }, ); const fory = new Fory(); // With hps: const fory = new Fory({ hps }); const { serialize, deserialize } = fory.register(userType); const bytes = serialize({ id: 1n, name: "Alice", age: 30 }); const user = deserialize(bytes); console.log(user); // { id: 1n, name: 'Alice', age: 30 } ``` -------------------------------- ### Multiple Options Example Source: https://github.com/apache/fory/blob/main/docs/compiler/schema-idl.md Demonstrates setting multiple language-specific options and a deprecated option within a package. ```protobuf package payment; option java_package = "com.mycorp.payment.v1"; option go_package = "github.com/mycorp/apis/gen/payment/v1;paymentv1"; option deprecated = true; message Payment { string id = 1; } ``` -------------------------------- ### Python Installation with Row-Format Support Source: https://github.com/apache/fory/blob/main/README.md Install pyfory with optional row-format support for Python. ```bash pip install "pyfory[format]" ``` -------------------------------- ### Go Complete Example: Schema Evolution with V1 and V2 Source: https://github.com/apache/fory/blob/main/docs/guide/go/schema-evolution.md A complete Go example demonstrating serialization of a V1 struct and deserialization into a V2 struct using Fory with Xlang enabled, showing how new fields are handled. ```go package main import ( "fmt" "github.com/apache/fory/go/fory" ) // V1: Initial schema type ProductV1 struct { ID int64 Name string Price float64 } // V2: Added fields type ProductV2 struct { ID int64 Name string Price float64 Description string // New InStock bool // New } func main() { // Serialize with V1 f1 := fory.New(fory.WithXlang(true)) f1.RegisterStruct(ProductV1{}, 1) product := &ProductV1{ID: 1, Name: "Widget", Price: 9.99} data, _ := f1.Serialize(product) fmt.Printf("V1 serialized: %d bytes\n", len(data)) // Deserialize with V2 f2 := fory.New(fory.WithXlang(true)) f2.RegisterStruct(ProductV2{}, 1) var productV2 ProductV2 if err := f2.Deserialize(data, &productV2); err != nil { panic(err) } fmt.Printf("ID: %d\n", productV2.ID) fmt.Printf("Name: %s\n", productV2.Name) fmt.Printf("Price: %.2f\n", productV2.Price) fmt.Printf("Description: %q (zero value)\n", productV2.Description) fmt.Printf("InStock: %v (zero value)\n", productV2.InStock) } ``` -------------------------------- ### Verify Fory Compiler Installation Source: https://github.com/apache/fory/blob/main/docs/compiler/compiler-guide.md Check if the Fory compiler is installed correctly by running the help command. ```bash foryc --help ``` -------------------------------- ### Navigate to JavaScript Benchmark Directory Source: https://github.com/apache/fory/blob/main/benchmarks/javascript/README.md Change the current directory to the JavaScript benchmark folder to begin setup. ```bash cd benchmarks/javascript ``` -------------------------------- ### Profile All Benchmarks Source: https://github.com/apache/fory/blob/main/benchmarks/cpp/README.md Starts the profiling process for all available benchmarks using the default settings. ```bash # Profile all benchmarks ./profile.sh ``` -------------------------------- ### Install @apache-fory/hps Source: https://github.com/apache/fory/blob/main/javascript/packages/hps/README.md Install the package using npm. If installation fails due to missing build tools or an unsupported platform, the core functionality of @apache-fory/core will still work without this optimization. ```bash npm install @apache-fory/hps ``` -------------------------------- ### Install Java Artifacts and Run Gradle Tests Source: https://github.com/apache/fory/blob/main/integration_tests/android_tests/README.md Installs the necessary Java artifacts from the Maven repository and then executes the Android instrumented tests using Gradle. ```bash cd ../../java mvn -T16 --no-transfer-progress -pl fory-core,fory-annotation-processor -am install -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true cd ../integration_tests/android_tests gradle --no-daemon connectedCheck ``` -------------------------------- ### Install Pyfory with Format Support Source: https://github.com/apache/fory/blob/main/docs/guide/python/troubleshooting.md Install the Pyfory library with support for row formats. This is necessary to resolve `ImportError` related to format features. Alternatively, install from source with format support. ```python # Solution: Install Row format support pip install pyfory[format] # Or install from source with format support pip install -e ".[format]" ``` -------------------------------- ### Complete Fory Serialization Example Source: https://github.com/apache/fory/blob/main/docs/guide/go/basic-serialization.md A full example demonstrating Fory serialization and deserialization of a custom struct with nested collections. Includes type registration and error checking. ```go package main import ( "fmt" "github.com/apache/fory/go/fory" ) type Order struct { ID int64 Customer string Items []Item Total float64 } type Item struct { Name string Quantity int32 Price float64 } func main() { f := fory.New(fory.WithXlang(true)) f.RegisterStruct(Order{}, 1) f.RegisterStruct(Item{}, 2) order := &Order{ ID: 12345, Customer: "Alice", Items: []Item{ {Name: "Widget", Quantity: 2, Price: 9.99}, {Name: "Gadget", Quantity: 1, Price: 24.99}, }, Total: 44.97, } // Serialize data, err := f.Serialize(order) if err != nil { panic(err) } fmt.Printf("Serialized %d bytes\n", len(data)) // Deserialize var result Order if err := f.Deserialize(data, &result); err != nil { panic(err) } fmt.Printf("Order ID: %d\n", result.ID) fmt.Printf("Customer: %s\n", result.Customer) fmt.Printf("Items: %d\n", len(result.Items)) fmt.Printf("Total: %.2f\n", result.Total) } ``` -------------------------------- ### Install Node.js Core Package Source: https://github.com/apache/fory/blob/main/README.md Use 'npm install' to add the core Apache Fory package for JavaScript/TypeScript projects. ```bash npm install @apache-fory/core ``` -------------------------------- ### Format Python Code with Ruff Source: https://github.com/apache/fory/blob/main/CONTRIBUTING.md Install Ruff and format Python code. ```bash cd python # install dependencies for formatting pip install ruff # format python code ruff format ``` -------------------------------- ### Java Usage Example Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Example of creating, populating, serializing, and deserializing a Java object generated from a Fory schema. ```java Person person = new Person(); person.setName("Alice"); person.setPet(Animal.ofDog(new Dog())); byte[] data = person.toBytes(); Person restored = Person.fromBytes(data); ``` -------------------------------- ### Compile Demo Schema Source: https://github.com/apache/fory/blob/main/compiler/README.md Example command to compile a demo FDL schema using the foryc CLI. ```bash # Compile the demo schema foryc examples/demo.fdl --output examples/generated ``` -------------------------------- ### Build and Run Hello World with Bazel Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_world/README.md Build and run the C++ hello_world example using Bazel. This command is executed from the repository root. ```bash bazel build //examples/cpp/hello_world:hello_world bazel run //examples/cpp/hello_world:hello_world ``` -------------------------------- ### Build and Run Hello World with CMake Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_world/README.md Steps to build and execute the C++ hello_world example using CMake. Ensure you have a Release build type for optimal performance. ```bash cd examples/cpp/hello_world mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --parallel ./hello_world ``` -------------------------------- ### Install Fory Compiler using pip Source: https://github.com/apache/fory/blob/main/docs/compiler/index.md Install the Fory compiler package using pip. This is the recommended way to get the latest stable version. ```bash pip install fory-compiler ``` -------------------------------- ### Rust: Usage Example Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Demonstrates creating a Person object, serializing it to bytes, and deserializing it back. ```rust let person = Person { name: "Alice".into(), pet: Animal::Dog(self::Dog::default()), ..Default::default() }; let bytes = person.to_bytes()?; let restored = Person::from_bytes(&bytes)?; ``` -------------------------------- ### Example: Run Protobuf Benchmarks Source: https://github.com/apache/fory/blob/main/benchmarks/rust/README.md Execute the benchmark script to specifically target benchmarks using the 'protobuf' serializer. ```bash # Run only Protobuf benchmarks ./run.sh --serializer protobuf ``` -------------------------------- ### Format C++ Code with Clang-Format Source: https://github.com/apache/fory/blob/main/CONTRIBUTING.md Install clang-format and format C++ source files in place. ```bash pip install clang-format==18.1.8 git ls-files -- '*.cc' '*.h' | xargs -P 5 clang-format -i ``` -------------------------------- ### Configure Type Checker for Class Registration Source: https://github.com/apache/fory/blob/main/docs/guide/java/type-registration.md Disable class registration check and configure a custom type checker to control allowed classes during serialization. This example allows classes starting with 'org.example.'. ```java Fory fory = Fory.builder().withXlang(false) .requireClassRegistration(false) .withTypeChecker((typeResolver, className) -> className.startsWith("org.example.")) .build(); ``` -------------------------------- ### Kotlin Data Class Default Values Example Source: https://github.com/apache/fory/blob/main/docs/guide/kotlin/default-values.md Demonstrates serializing with an old schema and deserializing with a new schema that includes a default value for a new field. The missing field automatically gets its default value. ```kotlin import org.apache.fory.kotlin.ForyKotlin // Original data class data class User(val name: String, val age: Int) // Evolved data class with new field and default value data class UserV2(val name: String, val age: Int, val email: String = "default@example.com") fun main() { val fory = ForyKotlin.builder().withXlang(false) .withCompatible(true) .build() fory.register(User::class.java) fory.register(UserV2::class.java) // Serialize with old schema val oldUser = User("John", 30) val serialized = fory.serialize(oldUser) // Deserialize with new schema - missing field gets default value val newUser = fory.deserialize(serialized) as UserV2 println(newUser) // UserV2(name=John, age=30, email=default@example.com) } ``` -------------------------------- ### Example: Run Specific Data and Serializer Benchmarks Source: https://github.com/apache/fory/blob/main/benchmarks/rust/README.md Execute the benchmark script to target 'sample' and 'mediacontent' data types using the 'protobuf' serializer. ```bash # Run only Sample and MediaContent benchmarks for Protobuf ./run.sh --data sample,mediacontent --serializer protobuf ``` -------------------------------- ### Quick Start: Serialize and Deserialize User Data Source: https://github.com/apache/fory/blob/main/docs/guide/javascript/index.md Demonstrates defining a user type schema, registering it with Fory, and then serializing a JavaScript object to bytes and deserializing it back. This example uses `Type.struct`, `Type.int64`, `Type.string`, and `Type.int32`. ```typescript import Fory, { Type } from "@apache-fory/core"; const userType = Type.struct( { typeName: "example.user" }, { id: Type.int64(), name: Type.string(), age: Type.int32(), }, ); const fory = new Fory(); const { serialize, deserialize } = fory.register(userType); const bytes = serialize({ id: 1n, name: "Alice", age: 30, }); const user = deserialize(bytes); console.log(user); // { id: 1n, name: 'Alice', age: 30 } ``` -------------------------------- ### Maven Build Commands Source: https://github.com/apache/fory/blob/main/java/README.md Common Maven commands for building, testing, installing, and formatting Fory Java projects. ```bash # Build mvn -T16 clean package # Run tests mvn -T16 test # Install locally mvn -T16 install -DskipTests # Code formatting mvn -T16 spotless:apply # Code style check mvn -T16 checkstyle:check ``` -------------------------------- ### Maven Build and Execute Benchmark Source: https://github.com/apache/fory/blob/main/benchmarks/java/README.md Commands to perform a Maven installation and then execute a benchmark using `exec:java` with specific arguments. ```bash cd .. && mvn -T10 install -DskipTests -Dcheckstyle.skip -Dlicense.skip -Dmaven.javadoc.skip mvn exec:java -Dexec.args="-f 3 -wi 5 -i 15 -t 1 -w 2s -r 2s -rf csv" ``` -------------------------------- ### Java Hello World Example: Serialization Source: https://github.com/apache/fory/blob/main/docs/guide/xlang/getting-started.md Serializes a Person object to a binary file using Fory. Ensure Fory and necessary configuration are set up. ```java import org.apache.fory.*; import org.apache.fory.config.*; import java.nio.file.*; public class Person { public String name; public int age; } public class HelloWorld { public static void main(String[] args) throws Exception { Fory fory = Fory.builder().withXlang(true).build(); fory.register(Person.class, "example.Person"); Person person = new Person(); person.name = "Alice"; person.age = 30; byte[] bytes = fory.serialize(person); Files.write(Path.of("person.bin"), bytes); System.out.println("Serialized to person.bin"); } } ``` -------------------------------- ### Install Java Artifacts Source: https://github.com/apache/fory/blob/main/kotlin/fory-kotlin-ksp/README.md If Java artifacts have changed, install them first before building the Kotlin modules. This command installs Java artifacts with parallel builds and skips tests. ```bash cd ../../java mvn -T16 install -DskipTests ``` -------------------------------- ### Swift Module Installation Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Installs Fory modules and registers types with explicit IDs in Swift. ```swift public enum ForyModule { public static func install(_ fory: Fory) throws { try ComplexPb.ForyModule.install(fory) fory.register(Addressbook.Person.self, id: 100) fory.register(Addressbook.Animal.self, id: 106) } } ``` -------------------------------- ### C# Module Installation Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Installs imported modules and registers local schema types in C#. ```csharp public static class AddressbookForyModule { public static void Install(Fory fory) { fory.Register((uint)106); fory.Register((uint)100); // ... } } ``` -------------------------------- ### Display Benchmark Help Information Source: https://github.com/apache/fory/blob/main/benchmarks/javascript/README.md View available options and arguments for the benchmark script. ```bash ./run.sh --help ``` -------------------------------- ### Schema Evolution Example with Optional Field Source: https://github.com/apache/fory/blob/main/docs/compiler/compiler-guide.md Illustrates best practices for schema evolution, including not reusing field numbers and using optional fields for backward compatibility. ```protobuf message User [id=100] { string id = 1; string name = 2; // Field 3 was removed, don't reuse optional string email = 4; // New field } ``` -------------------------------- ### Create Fory Instance with Default Configuration Source: https://github.com/apache/fory/blob/main/docs/guide/go/configuration.md Instantiate Fory with default settings. The `WithXlang(true)` option enables cross-language compatibility by default. ```go import "github.com/apache/fory/go/fory" f := fory.New(fory.WithXlang(true)) ``` -------------------------------- ### Create and Use Sets in Go Source: https://github.com/apache/fory/blob/main/docs/guide/go/supported-types.md Shows how to create a generic set of strings using Fory's `NewSet` function, add elements, check for membership, and serialize the set. ```go // Create a set of strings s := fory.NewSet[string]() s.Add("a", "b", "c") // Check membership if s.Contains("a") { fmt.Println("found") } // Serialize data, _ := f.Serialize(s) ``` -------------------------------- ### Install Fory Compiler in Development Mode Source: https://github.com/apache/fory/blob/main/compiler/README.md Command to install the Fory compiler in development mode using pip. ```bash # Install in development mode pip install -e . ``` -------------------------------- ### Create and Use Maps in Go Source: https://github.com/apache/fory/blob/main/docs/guide/go/supported-types.md Demonstrates the creation of different map types in Go, including string-keyed, integer-keyed, and dynamic maps, for use with Fory. ```go f := fory.New(fory.WithXlang(true)) // String key maps m1 := map[string]string{"key": "value"} m2 := map[string]int64{"count": 42} // Integer key maps m3 := map[int32]int32{1: 100, 2: 200} // Dynamic maps m4 := map[string]any{ "name": "Alice", "age": int64(30), } ``` -------------------------------- ### Install Generated Module and Serialize/Deserialize Source: https://github.com/apache/fory/blob/main/docs/guide/swift/xlang-serialization.md After generating Swift models, install the module into the Fory runtime and use the generated types for serialization and deserialization. ```swift let fory = Fory(ref: true) try Addressbook.ForyModule.install(fory) let payload = try fory.serialize(book) let decoded: Addressbook.AddressBook = try fory.deserialize(payload) ``` -------------------------------- ### C++: Usage Example Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Demonstrates creating a Person object, setting its fields, serializing it to bytes, and deserializing it back. ```cpp addressbook::Person person; person.set_name("Alice"); *person.mutable_pet() = addressbook::Animal::dog(addressbook::Dog{}); auto bytes = person.to_bytes(); auto restored = addressbook::Person::from_bytes(bytes.value()); ``` -------------------------------- ### Run Complete Rust Benchmark Source: https://github.com/apache/fory/blob/main/benchmarks/rust/README.md Navigate to the Rust benchmark directory and execute the main benchmark script. ```bash cd benchmarks/rust ./run.sh ``` -------------------------------- ### Install Node.js Core and HPS Packages Source: https://github.com/apache/fory/blob/main/README.md Install both the core Apache Fory package and the HPS (High Performance Serialization) package for Node.js. ```bash npm install @apache-fory/core @apache-fory/hps ``` -------------------------------- ### Programmatic Schema Creation and Access Source: https://github.com/apache/fory/blob/main/docs/guide/cpp/row-format.md Demonstrates how to create a schema programmatically using field definitions and how to iterate through schema fields to access their names and types. ```cpp #include "fory/row/schema.h" using namespace fory::row; // Create schema programmatically auto person_schema = schema({ field("id", int32()), field("name", utf8()), field("score", float32()), field("active", boolean()) }); // Access schema info for (const auto& f : person_schema->fields()) { std::cout << f->name() << ": " << f->type()->name() << std::endl; } ``` -------------------------------- ### Enum with All Features Example Source: https://github.com/apache/fory/blob/main/docs/compiler/schema-idl.md An example showcasing all features of enum definitions, including type options, reserved statements, and explicit value assignments. ```protobuf // HTTP status code categories enum HttpCategory [id=200] { reserved 10 to 20; // Reserved for future use reserved "UNKNOWN"; // Reserved name INFORMATIONAL = 1; SUCCESS = 2; REDIRECTION = 3; CLIENT_ERROR = 4; SERVER_ERROR = 5; } ``` -------------------------------- ### Dart Module Installation Source: https://github.com/apache/fory/blob/main/docs/compiler/generated-code.md Generated Dart IDL libraries include a module owner that installs imported modules and registers local schema types. ```dart abstract final class AddressbookForyModule { static void install(Fory fory) { complex_pb.ComplexPbForyModule.install(fory); _registerType(fory, Person); _registerType(fory, Dog); } static Fory getFory() { ... } static void _registerType(Fory fory, Type type) { if (type == Person) { registerGeneratedStruct(fory, _personForySchema, id: 100, namespace: null, typeName: null); return; } // ... other types } } ``` -------------------------------- ### Install Protocol Buffers Compiler Source: https://github.com/apache/fory/blob/main/benchmarks/go/README.md Installs the Protocol Buffers compiler (`protoc`) on macOS or Ubuntu/Debian systems. Alternatively, download from the official releases page. ```bash # macOS brew install protobuf # Ubuntu/Debian apt-get install protobuf-compiler # Or download from https://github.com/protocolbuffers/protobuf/releases ``` -------------------------------- ### Benchmark Report Generation Options Source: https://github.com/apache/fory/blob/main/benchmarks/cpp/README.md Displays help information for the benchmark report generation script, showing available command-line options. ```bash python benchmark_report.py --help Options: --json-file Benchmark JSON output file (default: benchmark_results.json) --output-dir Output directory for plots and report --plot-prefix Image path prefix in Markdown report ``` -------------------------------- ### Cross-language Struct Registration by Name (Rust Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by name in Rust for cross-language compatibility. Ensure the same name is used in other languages. ```rust use fory::{Fory, ForyStruct}; #[derive(ForyStruct)] struct User { id: i64, name: String, } let mut fory = Fory::default(); fory.register_by_name::("example", "User")?; ``` -------------------------------- ### Fory IDL Go Package Option Source: https://github.com/apache/fory/blob/main/docs/compiler/schema-idl.md Example of specifying the Go import path and package name using a file-level option. ```protobuf package payment; option go_package = "github.com/mycorp/apis/gen/payment/v1;paymentv1"; message Payment { string id = 1; } ``` -------------------------------- ### Cross-language Struct Registration by Name (Python Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by name in Python for cross-language compatibility. Ensure the same name is used in other languages. ```python fory.register(User, typename="example.User") ``` -------------------------------- ### Run Complete Benchmark Pipeline Source: https://github.com/apache/fory/blob/main/benchmarks/cpp/README.md Execute the full benchmark process including build, run, and report generation. Navigate to the benchmark directory first. ```bash cd benchmarks/cpp ./run.sh ``` -------------------------------- ### Cross-language Struct Registration by Name (Java Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by name in Java for cross-language compatibility. Ensure the same name is used in other languages. ```java fory.register(User.class, "example.User"); ``` -------------------------------- ### Cross-language Struct Registration by Name (Go Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by name in Go for cross-language compatibility. Ensure the same name is used in other languages. ```go f.RegisterStructByName(User{}, "example.User") ``` -------------------------------- ### Cross-language Struct Registration by ID (Python Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by ID in Python for cross-language compatibility. Ensure the same ID is used in other languages. ```python fory.register(User, type_id=1) ``` -------------------------------- ### Standalone Bazel Project Setup (BUILD) Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_row/README.md Define your C++ binary target in the BUILD file, specifying the sources and dependencies on Fory's row format and encoder libraries. ```bazel cc_binary( name = "my_app", srcs = ["main.cc"], deps = [ "@fory//cpp/fory/encoder:fory_encoder", "@fory//cpp/fory/row:fory_row_format", ], ) ``` -------------------------------- ### Fory IDL File Structure Example Source: https://github.com/apache/fory/blob/main/docs/compiler/schema-idl.md Illustrates a typical Fory IDL file structure including package declaration, options, imports, type definitions, and service definitions. ```protobuf // Optional package declaration package com.example.models; // Optional file-level options option java_package = "com.example.models"; // Import statements import "common/types.fdl"; // Type definitions enum Color [id=100] { ... } message User [id=101] { ... } message OrderRequest [id=102] { ... } message Order [id=103] { ... } union Event [id=104] { ... } // Service definitions service OrderService { rpc GetOrder (OrderRequest) returns (Order); } ``` -------------------------------- ### Cross-language Struct Registration by ID (Java Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by ID in Java for cross-language compatibility. Ensure the same ID is used in other languages. ```java fory.register(User.class, 1); ``` -------------------------------- ### Cross-language Struct Registration by ID (Go Example) Source: https://github.com/apache/fory/blob/main/docs/guide/go/type-registration.md Example of registering a struct by ID in Go for cross-language compatibility. Ensure the same ID is used in other languages. ```go f.RegisterStruct(User{}, 1) ``` -------------------------------- ### Build Benchmark Source: https://github.com/apache/fory/blob/main/benchmarks/swift/README.md Compile the benchmark executable in release mode using Swift Package Manager. ```bash swift build -c release ``` -------------------------------- ### Install Fory Compiler via Pip Source: https://github.com/apache/fory/blob/main/docs/compiler/compiler-guide.md Command to install the Fory IDL compiler using pip, often used for local development or CI environments. ```bash pip install -e ./compiler # Or add to PATH export PATH=$PATH:~/.local/bin ``` -------------------------------- ### Manual Buffer Control with Fory Source: https://github.com/apache/fory/blob/main/docs/guide/go/configuration.md Illustrates manual buffer management using `fory.NewByteBuffer` for high-throughput scenarios, including serialization to an existing buffer and resetting the buffer for reuse. ```go f := fory.New(fory.WithXlang(true)) buf := fory.NewByteBuffer(nil) // Serialize to existing buffer err := f.SerializeTo(buf, value) // Get serialized data data := buf.GetByteSlice(0, buf.WriterIndex()) // Process data... // Reset for next use buf.Reset() ``` -------------------------------- ### Build and Link Executable Source: https://github.com/apache/fory/blob/main/examples/cpp/hello_world/CMakeLists.txt Defines the main executable 'hello_world' and links it against the Fory serialization library. Ensure Fory is available either via FetchContent or find_package. ```cmake # Build the example executable add_executable(hello_world ${CMAKE_CURRENT_SOURCE_DIR}/main.cc ) target_link_libraries(hello_world PRIVATE fory::serialization) ``` -------------------------------- ### Install Development Environment Source: https://github.com/apache/fory/blob/main/python/CONTRIBUTING.md Installs the pyfory package in editable mode with development and formatting dependencies. Ensure numpy is uninstalled first for compatibility with Python versions less than 3.13. ```bash cd python pip uninstall -y numpy pip install -v -e ".[dev,format]" ``` -------------------------------- ### Fory Go Configuration Options Source: https://github.com/apache/fory/blob/main/go/fory/README.md Illustrates various configuration options for Fory Go, including enabling reference tracking, native mode, compatible mode, and setting maximum nesting depth. ```go // Enable reference tracking for circular references f := fory.New(fory.WithXlang(true), fory.WithTrackRef(true)) ``` ```go // Native mode for Go-only payloads. Use this when both sides are Go and the // payload should follow Go's native type system. f := fory.New(fory.WithXlang(false)) ``` ```go // Enable compatible mode for schema evolution in native mode f := fory.New(fory.WithXlang(false), fory.WithCompatible(true)) ``` ```go // Set maximum nesting depth f := fory.New(fory.WithXlang(true), fory.WithMaxDepth(20)) ``` ```go // Combine multiple options f := fory.New( fory.WithXlang(true), fory.WithTrackRef(true), fory.WithMaxDepth(20), ) ``` -------------------------------- ### Install Plotting Libraries and Analyze Data Source: https://github.com/apache/fory/blob/main/benchmarks/java/README.md Commands to install the necessary Python libraries (pandas and matplotlib) for data analysis and plotting, followed by the command to run the analysis script. ```bash pip install pandas matplotlib python analyze.py ``` -------------------------------- ### Go API Response Struct Example Source: https://github.com/apache/fory/blob/main/docs/guide/go/schema-metadata.md Example of a Go struct for an API response, demonstrating the use of `json` and `fory` tags for status, message, data, and ignored fields. ```go type APIResponse struct { Status int32 `json:"status" fory:"id=0"` Message string `json:"message" fory:"id=1"` Data any `json:"data" fory:"id=2"` Internal string `json:"-" fory:"-"` // Ignored in both JSON and Fory } ``` -------------------------------- ### Native Mode Setup Source: https://github.com/apache/fory/blob/main/docs/guide/kotlin/configuration.md Use this for same-language Kotlin/JVM payloads that need native JVM object behavior. Requires class registration to be enabled. ```kotlin import org.apache.fory.kotlin.ForyKotlin val fory = ForyKotlin.builder().withXlang(false) .requireClassRegistration(true) .build() ``` -------------------------------- ### Run Code Generator on Example Source: https://github.com/apache/fory/blob/main/dart/README.md Generate Fory code specifically for the example directory within the Fory package. This is useful for testing the code generation process on sample data. ```bash cd packages/fory dart run build_runner build --delete-conflicting-outputs ```