SkillAgentSearch skills...

Bolt

Lightning fast, strongly typed network protocol

Install / Use

/learn @wolfenrain/Bolt
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<p align="center"> <img src="https://raw.githubusercontent.com/wolfenrain/bolt/main/assets/bolt_full.png" height="320" alt="bolt logo" /> </p> <p align="center"> <a href="https://github.com/wolfenrain/bolt/actions"><img src="https://github.com/wolfenrain/bolt/actions/workflows/main.yaml/badge.svg" alt="bolt"></a> <a href="https://github.com/wolfenrain/bolt/actions"><img src="https://raw.githubusercontent.com/wolfenrain/bolt/main/coverage_badge.svg" alt="coverage"></a> <a href="https://pub.dev/packages/very_good_analysis"><img src="https://img.shields.io/badge/style-very_good_analysis-B22C89.svg" alt="style: very good analysis"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-purple.svg" alt="License: MIT"></a> </p>

What is Bolt

Bolt is a network protocol written in Dart to send and receive strongly typed data objects. It is designed to be easy to use and to be as fast as possible.

Bolt is split into two parts, the BoltClient and the BoltServer. They both implement the BoltProtocol, which handles settings up the connection, verifying the connection is secure and sending/receiving data objects.

Everything is abstracted away in these classes, this means that you can implement your own abstraction on top of Bolt by just extending from BoltClient and BoltServer.

Bolt works on the principal of shared code, this means that you write common code that is shared between both server and client.

Packages

| Package | Pub | | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | | bolt | pub package | | bolt_udp_binding | pub package | | bolt_websocket_binding | pub package |

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 Data Object 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) {
    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}) {
    Ping.register(registry);
  }

  @override
  void onConnected() {
    send(Ping(DateTime.now().millisecondsSinceEpoch));
  }
}

Related Skills

View on GitHub
GitHub Stars44
CategoryDevelopment
Updated1y ago
Forks0

Languages

Dart

Security Score

80/100

Audited on Mar 20, 2025

No findings