fory 1.1.0-rc1 copy "fory: ^1.1.0-rc1" to clipboard
fory: ^1.1.0-rc1 copied to clipboard

Cross-language Apache Fory runtime for Dart with generated serializers, schema evolution, and custom type support.

example/example.dart

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import 'package:fory/fory.dart';

part 'example.fory.dart';

enum Color { red, blue }

@ForyStruct()
class Person {
  Person();

  String name = '';
  @ForyField(type: Int32Type())
  int age = 0;
  Color favoriteColor = Color.red;
  List<String> tags = <String>[];
}

void main() {
  final fory = Fory();
  ExampleForyModule.register(
    fory,
    Color,
    namespace: 'example',
    typeName: 'Color',
  );
  ExampleForyModule.register(
    fory,
    Person,
    namespace: 'example',
    typeName: 'Person',
  );

  final person =
      Person()
        ..name = 'Ada'
        ..age = 36
        ..favoriteColor = Color.blue
        ..tags = <String>['engineer', 'mathematician'];

  final bytes = fory.serialize(person);
  final roundTrip = fory.deserialize<Person>(bytes);

  print('${roundTrip.name} ${roundTrip.age} ${roundTrip.favoriteColor}');
  print(roundTrip.tags);
}
0
likes
160
points
198
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Cross-language Apache Fory runtime for Dart with generated serializers, schema evolution, and custom type support.

Homepage
Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

Dependencies

analyzer, build, build_config, meta, source_gen

More

Packages that depend on fory