34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
using System;
|
|
using MxGateway.Contracts.Proto;
|
|
|
|
namespace MxGateway.Worker.Ipc;
|
|
|
|
internal static class WorkerEnvelopeValidator
|
|
{
|
|
public static void Validate(
|
|
WorkerEnvelope envelope,
|
|
WorkerFrameProtocolOptions options)
|
|
{
|
|
if (envelope.ProtocolVersion != options.ProtocolVersion)
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.ProtocolVersionMismatch,
|
|
$"Worker envelope protocol version {envelope.ProtocolVersion} does not match expected version {options.ProtocolVersion}.");
|
|
}
|
|
|
|
if (!string.Equals(envelope.SessionId, options.SessionId, StringComparison.Ordinal))
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.SessionMismatch,
|
|
"Worker envelope session id does not match the owning worker session.");
|
|
}
|
|
|
|
if (envelope.BodyCase == WorkerEnvelope.BodyOneofCase.None)
|
|
{
|
|
throw new WorkerFrameProtocolException(
|
|
WorkerFrameProtocolErrorCode.InvalidEnvelope,
|
|
"Worker envelope must include a typed body.");
|
|
}
|
|
}
|
|
}
|