transit_dart 0.8.112 copy "transit_dart: ^0.8.112" to clipboard
transit_dart: ^0.8.112 copied to clipboard

This library provides support for marshalling Transit data to/from Dart.

example/transit_dart_example.dart

import 'package:collection/collection.dart';
import 'package:transit_dart/transit_dart.dart';

/// Encodes and decodes some objects. Note that although the objects are stored
/// in a list, they are encoded and decoded separately, each one treated as a
/// top-level object. This is expected behavior for transit and is an example of
/// how transit brokers in not just one, but _streams_ of JSON objects.
Future<void> main() async {
  // Some objects to work with.
  var objects = <dynamic>[
    "hello",
    ["A", "B", null, true, 3.4],
    {42: "the answer"}
  ];
  print('objects: $objects');

  var transit = TransitJsonCodec();

  // Encode the objects to a List<String>;
  var encoded =
      await Stream.fromIterable(objects).transform(transit.encoder).toList();
  print('encoded: ${encoded.join()}');

  // Decode the objects to a List<dynamic>
  var decoded =
      await Stream.fromIterable(encoded).transform(transit.decoder).toList();
  print('decoded: $decoded');

  // Did everything come back same as we sent it?
  var test = DeepCollectionEquality().equals(objects, decoded);
  print('Round trip success? ${test ? 'YES' : 'NO'}');
}
1
likes
150
points
74
downloads

Publisher

unverified uploader

Weekly Downloads

This library provides support for marshalling Transit data to/from Dart.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

collection, hex, typed_data

More

Packages that depend on transit_dart