54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using MxGateway.Contracts;
|
|
|
|
namespace MxGateway.Server.Workers;
|
|
|
|
public sealed class WorkerFrameProtocolOptions
|
|
{
|
|
public const int DefaultMaxMessageBytes = 16 * 1024 * 1024;
|
|
|
|
public WorkerFrameProtocolOptions(string sessionId)
|
|
: this(
|
|
sessionId,
|
|
GatewayContractInfo.WorkerProtocolVersion,
|
|
DefaultMaxMessageBytes)
|
|
{
|
|
}
|
|
|
|
public WorkerFrameProtocolOptions(
|
|
string sessionId,
|
|
uint protocolVersion,
|
|
int maxMessageBytes)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sessionId))
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.InvalidConfiguration,
|
|
"Worker frame protocol requires a session id.");
|
|
}
|
|
|
|
if (protocolVersion == 0)
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.InvalidConfiguration,
|
|
"Worker frame protocol requires a non-zero protocol version.");
|
|
}
|
|
|
|
if (maxMessageBytes <= 0)
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.InvalidConfiguration,
|
|
"Worker frame protocol max message size must be greater than zero.");
|
|
}
|
|
|
|
SessionId = sessionId;
|
|
ProtocolVersion = protocolVersion;
|
|
MaxMessageBytes = maxMessageBytes;
|
|
}
|
|
|
|
public string SessionId { get; }
|
|
|
|
public uint ProtocolVersion { get; }
|
|
|
|
public int MaxMessageBytes { get; }
|
|
}
|