using System; using ZB.MOM.WW.MxGateway.Contracts.Proto; namespace ZB.MOM.WW.MxGateway.Worker.Ipc; /// Validates worker envelope frames against protocol options. internal static class WorkerEnvelopeValidator { /// Validates a worker envelope for protocol compliance. /// The envelope to validate. /// The frame protocol configuration. 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."); } } }