network (1.0.0)

Published 2026-08-22 12:16:58 +00:00 by Platform

Installation

dart pub add network:1.0.0 --hosted-url=

About this package

WebSocket-based client networking: protocols, event/request dispatch, and connection management.

Dart.Package.Network

WebSocket-based client networking: a binary protocol layer (event/targeted event/request/response), client-side dispatch managers, connection handling, and small utilities (Mapping, UshortGenerator) — ported from the old platform.

Quick start

import 'dart:typed_data';
import 'package:network/network.dart';

final event = EventProtocol(1, Uint8List.fromList([1, 2, 3]));
final bytes = event.serialize().toArray();

final decoded = ProtocolFactory.deserialize(Uint8List.fromList(bytes)) as EventProtocol;
print(decoded.eventId); // 1

Every protocol (EventProtocol, TargetEventProtocol, RequestProtocol, ResponseProtocol) extends BaseProtocol and serializes to/from Dart.Package.Serializers' ByteWriter/ByteReader. ProtocolFactory.deserialize reads the leading command byte and dispatches to the right protocol class.

Depends on Dart.Package.Logging for logging and Dart.Package.Observables for change notification in its managers.

Note from the migration

ProtocolFactory.deserialize's empty-data guard called Log.error(...) without throwException: false, so — since Log.error throws by default — it never actually reached its own return null; on empty input; it always threw instead. Fixed to pass throwException: false, matching the two other error paths in the same method (which already do this correctly) and the function's own return type (BaseProtocol?, implying a normal null return path is expected).

Project structure

pubspec.yaml
Version.txt
lib/
├── network.dart                public API — exports
└── src/
    ├── command.dart               Command enum
    ├── mapping.dart               Mapping<T1, T2> — bidirectional map
    ├── ushort_generator.dart      UshortGenerator — recyclable ushort ids
    ├── serializable.dart          Serializable interface
    ├── protocol_factory.dart      ProtocolFactory.deserialize
    ├── protocols/                 BaseProtocol + Event/TargetEvent/Request/Response
    ├── event_manager.dart, network_manager.dart, network_event.dart,
    │   network_request.dart, registration_manager.dart, request_manager.dart,
    │   response_manager.dart, sync.dart
    ├── client/                    ClientManager, ClientAuthenticator,
    │                              ClientEventManager, ClientRequestManager
    └── transports/                Transport, Connection, Channel,
                                    WebSocketTransport, async_utils
test/
└── network_test.dart          Mapping, UshortGenerator, and protocol
                                round-trip tests (pure logic — the transport/
                                connection layer needs a real socket and
                                isn't covered here, matching the old
                                platform's test coverage, which was none)
example/
└── example.dart

Versioning and publishing

Version.txt is the exact version that gets published — a push to main publishes it only when that version isn't on the feed yet. Pushes to any other branch only resolve and test.

Depends on dajno_logging (renamed from logging to avoid a pub.dev name collision), observables, and serializers (this migration's sibling Dart packages) — pinned to ^1.0.0 on the Forge Pub feed, not the old platform's git: dependencies on git.coldpixl.com.

CI

.forgejo/workflows/build.yml installs the Dart SDK, resolves dependencies, and runs dart test on every push. On main, it also publishes via dart pub publish, tags the commit v<version>, and creates a matching Release — via the shared Platform/Forgejo.Package.Actions/dart-publish composite action. .forgejo/workflows/cleanup.yml removes prerelease Pub versions when their branch is deleted.

Because this package depends on other private packages on the Forge Pub feed, build.yml has an extra step before dart-publish that installs a throwaway Dart SDK just to run dart pub token add against the feed with PACKAGES_TOKEN — the dart-publish action itself doesn't configure pub credentials, so dart pub get 401s on any private dependency without this.

Details
Pub
2026-08-22 12:16:58 +00:00
0
14 KiB
Assets (1)
1.0.0.tar.gz 14 KiB
Versions (2) View all
2.0.0 2026-09-12
1.0.0 2026-08-22