Skip to content

ConnectionFrameHelper Methods

Provides framing utilities for connection middleware authors.

Wire format per frame: [4-byte LE length] [1-byte frame type] [payload]. The length field equals 1 + payload.Length.

Connection middlewares should follow the Microsoft.AspNetCore.Connections.ConnectionDelegate pipeline pattern (like TLS) and register via SiloConnectionOptions or ClientConnectionOptions. Use these helpers for structured frame I/O within your middleware.

This helper is optional. Middleware authors who need custom protocols can read/write directly from context.Transport.Input (PipeReader) and context.Transport.Output (PipeWriter) without using this class.

ReadFrameAsync(ConnectionContext, CancellationToken, int)

static
View source
public static ValueTask<(byte FrameType, byte[] Payload)> ConnectionFrameHelper.ReadFrameAsync(ConnectionContext connection, CancellationToken cancellationToken, int maxFrameLength = 1048576)
Reads a single frame from the connection.

Parameters

connectionConnectionContext
cancellationTokenCancellationToken
maxFrameLengthint

WriteFrameAsync(ConnectionContext, byte, Action<IBufferWriter<byte>>, CancellationToken)

static
View source
public static ValueTask WriteFrameAsync(ConnectionContext connection, byte frameType, Action<IBufferWriter<byte>> writePayload, CancellationToken cancellationToken)
Writes a frame using zero-copy framing via Orleans.Runtime.Messaging.PrefixingBufferWriter. The writePayload delegate writes payload directly into the transport pipe buffer.

Parameters

connectionConnectionContext
frameTypebyte
writePayloadAction<IBufferWriter<byte>>
cancellationTokenCancellationToken