-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFoo.cs
156 lines (151 loc) · 6.68 KB
/
Foo.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Text;
namespace SpanTest
{
public interface IFoo { }
public class Foo : IFoo
{
public string Field1 { get; set; }
public string Field2 { get; set; }
public string Field3 { get; set; }
public string Field4 { get; set; }
public string Field5 { get; set; }
public string Field6 { get; set; }
public string Field7 { get; set; }
public string Field8 { get; set; }
public string Field9 { get; set; }
public string Field10 { get; set; }
public string Field11 { get; set; }
public string Field12 { get; set; }
public string Field13 { get; set; }
public string Field14 { get; set; }
public string Field15 { get; set; }
public string Field16 { get; set; }
public string Field17 { get; set; }
public string Field18 { get; set; }
public string Field19 { get; set; }
public string Field20 { get; set; }
public string Field21 { get; set; }
public string Field22 { get; set; }
public string Field23 { get; set; }
public string Field24 { get; set; }
public string Field25 { get; set; }
public string Field26 { get; set; }
public string Field27 { get; set; }
public string Field28 { get; set; }
public string Field29 { get; set; }
public string Field30 { get; set; }
/// <summary>
/// Creates a Foo by using a traditional Substring approach.
/// </summary>
public static Foo Read(string buffer)
=> new Foo
{
Field1 = buffer.Read(0, 2),
Field2 = buffer.Read(3, 4),
Field3 = buffer.Read(5, 6),
Field4 = buffer.Read(7, 11),
Field5 = buffer.Read(12, 17),
Field6 = buffer.Read(20, 21),
Field7 = buffer.Read(22, 25),
Field8 = buffer.Read(26, 30),
Field9 = buffer.Read(37, 40),
Field10 = buffer.Read(49, 53),
Field11 = buffer.Read(54, 81),
Field12 = buffer.Read(82, 89),
Field13 = buffer.Read(90, 90),
Field14 = buffer.Read(91, 93),
Field15 = buffer.Read(94, 100),
Field16 = buffer.Read(101, 107),
Field17 = buffer.Read(108, 108),
Field18 = buffer.Read(109, 111),
Field19 = buffer.Read(112, 114),
Field20 = buffer.Read(115, 117),
Field21 = buffer.Read(118, 120),
Field22 = buffer.Read(121, 130),
Field23 = buffer.Read(131, 158),
Field24 = buffer.Read(159, 186),
Field25 = buffer.Read(187, 206),
Field26 = buffer.Read(207, 210),
Field27 = buffer.Read(211, 213),
Field28 = buffer.Read(214, 241),
Field29 = buffer.Read(242, 244),
Field30 = buffer.Read(246, 249)
};
/// <summary>
/// Creates a Foo using Span of byte, and converting the bytes to string for each slice using encoding.GetString(ReadOnlySpan<byte>)
/// </summary>
public static Foo ReadWithSpan(ReadOnlySpan<byte> buffer, Encoding encoding)
=> new Foo
{
Field1 = buffer.Read(0, 2, encoding),
Field2 = buffer.Read(3, 4, encoding),
Field3 = buffer.Read(5, 6, encoding),
Field4 = buffer.Read(7, 11, encoding),
Field5 = buffer.Read(12, 17, encoding),
Field6 = buffer.Read(20, 21, encoding),
Field7 = buffer.Read(22, 25, encoding),
Field8 = buffer.Read(26, 30, encoding),
Field9 = buffer.Read(37, 40, encoding),
Field10 = buffer.Read(49, 53, encoding),
Field11 = buffer.Read(54, 81, encoding),
Field12 = buffer.Read(82, 89, encoding),
Field13 = buffer.Read(90, 90, encoding),
Field14 = buffer.Read(91, 93, encoding),
Field15 = buffer.Read(94, 100, encoding),
Field16 = buffer.Read(101, 107, encoding),
Field17 = buffer.Read(108, 108, encoding),
Field18 = buffer.Read(109, 111, encoding),
Field19 = buffer.Read(112, 114, encoding),
Field20 = buffer.Read(115, 117, encoding),
Field21 = buffer.Read(118, 120, encoding),
Field22 = buffer.Read(121, 130, encoding),
Field23 = buffer.Read(131, 158, encoding),
Field24 = buffer.Read(159, 186, encoding),
Field25 = buffer.Read(187, 206, encoding),
Field26 = buffer.Read(207, 210, encoding),
Field27 = buffer.Read(211, 213, encoding),
Field28 = buffer.Read(214, 241, encoding),
Field29 = buffer.Read(242, 244, encoding),
Field30 = buffer.Read(246, 249, encoding)
};
/// <summary>
/// Creates a Foo using Span of char, and assebmles the char's as strings
/// </summary>
public static Foo ReadWithSpan(ReadOnlySpan<char> buffer)
=> new Foo
{
Field1 = buffer.Read(0, 2),
Field2 = buffer.Read(3, 4),
Field3 = buffer.Read(5, 6),
Field4 = buffer.Read(7, 11),
Field5 = buffer.Read(12, 17),
Field6 = buffer.Read(20, 21),
Field7 = buffer.Read(22, 25),
Field8 = buffer.Read(26, 30),
Field9 = buffer.Read(37, 40),
Field10 = buffer.Read(49, 53),
Field11 = buffer.Read(54, 81),
Field12 = buffer.Read(82, 89),
Field13 = buffer.Read(90, 90),
Field14 = buffer.Read(91, 93),
Field15 = buffer.Read(94, 100),
Field16 = buffer.Read(101, 107),
Field17 = buffer.Read(108, 108),
Field18 = buffer.Read(109, 111),
Field19 = buffer.Read(112, 114),
Field20 = buffer.Read(115, 117),
Field21 = buffer.Read(118, 120),
Field22 = buffer.Read(121, 130),
Field23 = buffer.Read(131, 158),
Field24 = buffer.Read(159, 186),
Field25 = buffer.Read(187, 206),
Field26 = buffer.Read(207, 210),
Field27 = buffer.Read(211, 213),
Field28 = buffer.Read(214, 241),
Field29 = buffer.Read(242, 244),
Field30 = buffer.Read(246, 249)
};
}
}