team-ljyzipelo

공개
81줄1.8 KB
1namespace Zipelo.Runtime.Streaming;
2
3public enum WorkerStreamFrameKind : ushort
4{
5 BeginJob = 1,
6 BeginItem = 2,
7 Data = 3,
8 EndItem = 4,
9 EndJob = 5
10}
11
12public enum WorkerStreamTerminalStatus : byte
13{
14 Completed = 1,
15 Failed = 2,
16 Cancelled = 3
17}
18
19public enum WorkerStreamPhase
20{
21 Ready,
22 BetweenItems,
23 InItem,
24 Terminal,
25 InputCompleted,
26 Faulted
27}
28
29public enum WorkerStreamDirection
30{
31 Read,
32 Write
33}
34
35public enum WorkerStreamError
36{
37 InvalidHeader,
38 InvalidLength,
39 UnexpectedFrame,
40 IdMismatch,
41 SequenceMismatch,
42 BudgetExceeded,
43 Truncated,
44 TrailingData,
45 Faulted
46}
47
48public sealed class WorkerStreamException(WorkerStreamError error) : IOException(error.ToString())
49{
50 public WorkerStreamError Error { get; } = error;
51}
52
53public readonly record struct WorkerStreamHeader(
54 WorkerStreamFrameKind Kind,
55 Guid JobId,
56 Guid ItemId,
57 ulong Sequence,
58 int PayloadLength);
59
60public sealed record WorkerStreamFrame(WorkerStreamHeader Header, ReadOnlyMemory<byte> Payload);
61
62public sealed record WorkerStreamLimits
63{
64 public long MaxDataBytes { get; init; } = 16 * 1024 * 1024;
65 public long MaxWireBytes { get; init; } = 21 * 1024 * 1024;
66 public int MaxItems { get; init; } = 1024;
67 public int MaxFrames { get; init; } = 65536;
68 public TimeSpan MaxDuration { get; init; } = TimeSpan.FromMinutes(5);
69
70 internal void Validate()
71 {
72 if (MaxDataBytes is < 0 or > 16 * 1024 * 1024 ||
73 MaxWireBytes is < 129 or > 21 * 1024 * 1024 ||
74 MaxItems is < 0 or > 1024 ||
75 MaxFrames is < 2 or > 65536 ||
76 MaxDuration <= TimeSpan.Zero || MaxDuration > TimeSpan.FromMinutes(5))
77 {
78 throw new ArgumentOutOfRangeException(nameof(WorkerStreamLimits));
79 }
80 }
81}