tree: db26e975ce329526dca2498299f2a86b1e99c78f
  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 implementation 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, Fory Dart uses static code generation for annotated models and external structural serializers.

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 implementation 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
packages/external-type-test-models/Fory-free dependency models for external-type tests
packages/inheritance-test-models/Cross-library inheritance test providers
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

Serialize and deserialize:

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

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

Ordinary annotated classes serialize one flattened view of their concrete superclass and applied-mixin storage. See Struct Inheritance for details.

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