bolt 0.1.0-dev.2 copy "bolt: ^0.1.0-dev.2" to clipboard
bolt: ^0.1.0-dev.2 copied to clipboard

Bolt, a lightning fast, strongly typed network protocol

bolt logo

Bolt is a network protocol to send and receive strongly typed data objects

pub package bolt coverage style: very good analysis License: MIT


Documentation 📝 #

For documentation about Bolt, see the docs section.

An example of Bolt can be found in the example directory.

Quick Start 🚀 #

Prerequisites 📝 #

In order to start using Bolt you must have the Dart SDK installed on your machine.

Installing 🧑‍💻 #

Add bolt to your pubspec.yaml:

# 📦 Install bolt from pub.dev
dart pub add bolt

Creating a shared Data Object 💿 #

Create a shared DataObject for the client and server:

class Ping extends DataObject {
  const Ping(this.timestamp);

  final int timestamp;

  @override
  List<Object?> get props => [timestamp];

  static void register(BoltRegistry registry) {
    registry.registerObject(
      100,
      DataResolver<Ping>(Ping.new, [
        Argument.positional<Ping, int>((d) => d.timestamp, type: uint32),
      ]),
    );
  }
}

Creating a Server 🏁 #

Define a server, register the data object and listen to messages:

class ExampleServer extends BoltServer {
  ExampleServer(super.address, {required super.bindings}) {
    Ping.register(registry);

    on(_onPinged);
  }

  void _onPinged(Message<Ping> message) {
    // Do something on ping ...
  }

  @override
  Future<bool> verifyAuth(Connection connection, String token) async {
    return token == 'super_secure_token';
  }
}

Creating a Client ✨ #

Define the client, register the data object and implement the onConnected method:

class ExampleClient extends BoltClient {
  ExampleClient(super.address, {super.server, required super.binding}) {
    Ping.register(registry);
  }

  @override
  void onConnected() {
    send(Ping(DateTime.now().millisecondsSinceEpoch));
  }
}
15
likes
110
pub points
0%
popularity

Publisher

verified publisherwolfenra.in

Bolt, a lightning fast, strongly typed network protocol

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

async, binarize, collection, equatable, mason_logger, meta

More

Packages that depend on bolt