Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 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

Directory Description
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
test/ Cross-language integration tests

Type Mapping

Fory xlang type Dart type
bool bool
int8 int + @ForyField(type: Int8Type())
int16 int + @ForyField(type: Int16Type())
int32 int + @ForyField(type: Int32Type())
int64 int or Int64
uint8 int + @ForyField(type: Uint8Type())
uint16 int + @ForyField(type: Uint16Type())
uint32 int + @ForyField(type: Uint32Type())
uint64 int or Uint64
float16 double + @ForyField(type: Float16Type())
bfloat16 double + @ForyField(type: Bfloat16Type())
float32 fory.Float32 (wrapper)
float64 double
string String
binary Uint8List
local_date LocalDate
timestamp Timestamp
list List
set Set
map Map
enum enum
named_struct class
array BoolList + @ArrayField(element: BoolType())
array Int8List
array Int16List
array Int32List
array Int64List
array Uint8List
array Uint16List
array Uint32List
array Uint64List
array Float16List
array Bfloat16List
array Float32List
array Float64List

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, name: 'example.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