-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathHeaderFactory.cs
More file actions
26 lines (23 loc) · 830 Bytes
/
Copy pathHeaderFactory.cs
File metadata and controls
26 lines (23 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Buffers;
namespace ServerApplication.Framing.VariableSized.LengthFielded
{
internal class HeaderFactory
{
public Header CreateHeader(int payloadLength, int someCustomData) => new Header(payloadLength, someCustomData);
public Header CreateHeader(in ReadOnlySequence<byte> headerSequence)
{
if (headerSequence.IsSingleSegment)
{
return CreateHeader(headerSequence.FirstSpan);
}
else
{
Span<byte> headerData = stackalloc byte[Helper.HeaderLength];
headerSequence.CopyTo(headerData);
return CreateHeader(headerData);
}
}
public Header CreateHeader(in ReadOnlySpan<byte> headerData) => new Header(headerData);
}
}