Protocol & Messages
aiosignalr.protocol
IHubProtocol
Interface implemented by JSONProtocol and MessagePackProtocol.
name—"json"/"messagepack".version— protocol version (2).transfer_format—TransferFormat.TEXT/BINARY.write_message(message) -> bytes— serialize one message into a frame.feed(data) -> list[HubMessage | None]— parse complete frames from a byte stream.create_parser() -> IHubProtocol— fresh connection-bound instance.
JSONProtocol
Text protocol. Each message is one JSON object terminated by 0x1E.
MessagePackProtocol
Binary protocol. Each message is a MessagePack array prefixed by a VarInt length.
Handshake helpers
encode_handshake_request(protocol, version) -> bytesencode_handshake_response(error=None) -> bytesHandshakeParser— incremental, record-separator-delimited parser.parse_handshake(frame)→HandshakeRequestMessage | HandshakeResponseMessage.
aiosignalr.messages
Immutable (frozen, slots) data classes for every hub message:
| Class | message_type | Fields |
|---|---|---|
InvocationMessage | INVOCATION | target, arguments, invocation_id, stream_ids, headers |
StreamInvocationMessage | STREAM_INVOCATION | target, arguments, invocation_id, stream_ids, headers |
StreamItemMessage | STREAM_ITEM | invocation_id, item |
CompletionMessage | COMPLETION | invocation_id, error, result, has_result |
CancelInvocationMessage | CANCEL_INVOCATION | invocation_id |
PingMessage | PING | — |
CloseMessage | CLOSE | error, allow_reconnect |
AckMessage | ACK | sequence_id |
SequenceMessage | SEQUENCE | sequence_id |
HandshakeRequestMessage | — | protocol, version |
HandshakeResponseMessage | — | error |
aiosignalr.message_buffer.MessageBuffer
The shared stateful-reconnect buffer (see Stateful Reconnect). Used by both client and server.
MessageBuffer(
protocol: IHubProtocol,
write: Callable[[bytes], Awaitable[None]],
*,
buffer_size: int = 100_000,
ack_interval: float = 1.0,
)
| Method | Description |
|---|---|
async send(message, data) | Buffer a trackable message and write it |
async send_serialized(data) | Buffer a pre-encoded frame (broadcast fanout) |
should_process(message) -> bool | Dedupe / gate inbound messages |
ack(message) | Drop buffered messages ≤ ack sequence id |
disconnected() | Enter reconnect state (ignore non-sequence messages) |
async resend() | Send Sequence + replay the buffer |
dispose() | Cancel the pending ack timer |
aiosignalr.framing
encode_text_message(data) -> bytes— append0x1E.TextMessageParser(max_size)— incremental0x1E-delimited parser.encode_binary_message(payload) -> bytes— VarInt length prefix.BinaryMessageParser(max_size)— incremental length-prefixed parser.