IRpcChannel class abstract

Raw bidirectional byte channel -- the minimal transport primitive.

Transports that move bytes over a single connection (WebSocket, raw TCP, Unix socket, QUIC, etc.) implement this interface. The framework wraps it with RpcChannelTransport which adds stream-ID multiplexing, metadata encoding, and the full IRpcTransport contract automatically.

Extend it to get the default closeFor; a class that implements it writes every member. Implementors only need ~50 lines of code:

class WebSocketChannel extends IRpcChannel {
  final WebSocket _ws;
  final _ctl = StreamController<Uint8List>();
  late final StreamSubscription<dynamic> _sub;
  bool _closed = false;

  WebSocketChannel(this._ws) {
    _sub = _ws.listen(
      (data) => _ctl.add(data is Uint8List ? data : Uint8List.fromList(data)),
      onDone: () { _closed = true; _ctl.close(); },
    );
    // Forward a consumer's pause to the socket, or a paused `incoming`
    // still reads every chunk off the wire into `_ctl`.
    _ctl
      ..onPause = _sub.pause
      ..onResume = _sub.resume;
  }

  @override bool get isClosed => _closed;
  @override Stream<Uint8List> get incoming => _ctl.stream;
  @override Future<void> send(Uint8List data) async => _ws.add(data);
  @override Future<void> close() async { _closed = true; await _ws.close(); await _ctl.close(); }
}

Constructors

IRpcChannel()

Properties

hashCode → int
The hash code for this object.
no setterinherited
incoming → Stream<Uint8List>
Incoming raw frames from the remote side.
no setter
isClosed → bool
Whether the channel has been closed.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
Close the channel and release all resources.
closeFor(RpcChannelCloseReason reason) → Future<void>
Closes the channel because the peer broke a rule, telling the peer why where the protocol underneath can say so.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
send(Uint8List data) → Future<void>
Send a raw frame to the remote side.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited