Class AdapterControlChannel

Namespace
MirrorPulse.Adapter.Sdk
Assembly
MirrorPulse.Adapter.Sdk.dll

Frames control and binary messages for one MirrorPulse Worker session.

public sealed class AdapterControlChannel : IAsyncDisposable
Inheritance
AdapterControlChannel
Implements
Inherited Members

Remarks

The caller must serialize writes and keep a single reader. Validate the Host's Ready response before selecting its protocol.

Constructors

AdapterControlChannel(AdapterNamedPipeClient, Guid, Guid)

public AdapterControlChannel(AdapterNamedPipeClient pipe, Guid instanceId, Guid workerSessionId)

Parameters

pipe AdapterNamedPipeClient
instanceId Guid
workerSessionId Guid

Properties

ProtocolVersion

The current envelope version. A new channel starts at version 1 for Hello.

public int ProtocolVersion { get; }

Property Value

int

Methods

DisposeAsync()

public ValueTask DisposeAsync()

Returns

ValueTask

ReadAsync(CancellationToken)

Reads and validates one control frame when the next message is expected to be JSON.

public ValueTask<AdapterControlFrame> ReadAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<AdapterControlFrame>

Remarks

Match the returned request ID and message type to the exchange. Use ReadNextAsync(CancellationToken) during v2 uploads.

ReadChunkAsync(CancellationToken)

Reads one binary chunk when the protocol exchange expects binary data next.

public ValueTask<AdapterBinaryChunk> ReadChunkAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<AdapterBinaryChunk>

ReadNextAsync(CancellationToken)

Reads the next control message or upload chunk on a negotiated v2 channel.

public ValueTask<AdapterWorkerFrame> ReadNextAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<AdapterWorkerFrame>

Remarks

Use the same reader for both frame kinds so a Cancel command can be handled between upload chunks.

SelectProtocol(int)

Selects the protocol from the validated Ready response for this session.

public void SelectProtocol(int version)

Parameters

version int

Exceptions

InvalidDataException

The selected version is outside the supported set.

InvalidOperationException

A different version has already been selected.

SendAsync(string, Guid, bool, object, CancellationToken)

Sends a JSON control envelope using the current version, instance and session identifiers.

public ValueTask SendAsync(string messageType, Guid requestId, bool isResponse, object payload, CancellationToken cancellationToken = default)

Parameters

messageType string
requestId Guid
isResponse bool
payload object
cancellationToken CancellationToken

Returns

ValueTask

Remarks

Use the incoming request ID for its response and a fresh nonempty ID for an independent request or event.

SendChunkAsync(AdapterBinaryChunk, CancellationToken)

Sends a binary chunk with the encoding selected for the session.

public ValueTask SendChunkAsync(AdapterBinaryChunk chunk, CancellationToken cancellationToken = default)

Parameters

chunk AdapterBinaryChunk
cancellationToken CancellationToken

Returns

ValueTask