tree: c154124dd50f0ea11106970c4616615dd1d926fc
  1. packages/
  2. test/
  3. .gitignore
  4. analysis_options.yaml
  5. build.yaml
  6. CHANGELOG.md
  7. pubspec.yaml
  8. README.md
dart/README.md

Apache Fory™ Dart

Apache Fory™ Dart is the Dart xlang runtime for Apache Fory™. It reads and writes Fory's cross-language wire format and works in both Dart and Flutter applications. Because Flutter prohibits dart:mirrors, the runtime uses static code generation for type handling.

The publishable package lives at packages/fory/. See its README for the full user-facing documentation including getting started, API reference, and code examples.

Project Structure

DirectoryDescription
packages/fory/lib/Core runtime and public API
packages/fory/lib/src/codegen/Build-runner code generator
packages/fory/example/Annotated example with generated output
packages/fory/test/Unit and integration tests
test/Cross-language integration tests

Type Mapping

Fory xlang typeDart type
boolbool
int8int + @ForyField(type: Int8Type())
int16int + @ForyField(type: Int16Type())
int32int + @ForyField(type: Int32Type())
int64int or Int64
uint8int + @ForyField(type: Uint8Type())
uint16int + @ForyField(type: Uint16Type())
uint32int + @ForyField(type: Uint32Type())
uint64int or Uint64
float16double + @ForyField(type: Float16Type())
bfloat16double + @ForyField(type: Bfloat16Type())
float32fory.Float32 (wrapper)
float64double
stringString
binaryUint8List
local_dateLocalDate
timestampTimestamp
listList
setSet
mapMap
enumenum
named_structclass
arrayBoolList + @ArrayField(element: BoolType())
arrayInt8List
arrayInt16List
arrayInt32List
arrayInt64List
arrayUint8List
arrayUint16List
arrayUint32List
arrayUint64List
arrayFloat16List
arrayBfloat16List
arrayFloat32List
arrayFloat64List

Quick Start

Annotate your model and run the code generator:

import 'package:fory/fory.dart';

part 'person.fory.dart';

@ForyStruct()
class Person {
  Person();

  String name = '';

  @ForyField(type: Int32Type())
  int age = 0;
}
dart run build_runner build --delete-conflicting-outputs

Serialize and deserialize:

final fory = Fory();
PersonForyModule.register(fory, Person, namespace: 'example', typeName: 'Person');

final bytes = fory.serialize(Person()..name = 'Ada'..age = 36);
final roundTrip = fory.deserialize<Person>(bytes);

Development

Run tests from the workspace root:

cd packages/fory
dart test

Run the code generator on the example:

cd packages/fory
dart run build_runner build --delete-conflicting-outputs