Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ EncodeStringLiterals()

static bool System.Net.Http.HPack.HPackEncoder.EncodeStringLiterals ( ReadOnlySpan< string > values,
string separator,
Encoding valueEncoding,
Span< byte > destination,
out int bytesWritten )
inlinestatic

Definition at line 143 of file HPackEncoder.cs.

144 {
145 bytesWritten = 0;
146 if (values.Length == 0)
147 {
148 return EncodeStringLiteral("", null, destination, out bytesWritten);
149 }
150 if (values.Length == 1)
151 {
152 return EncodeStringLiteral(values[0], valueEncoding, destination, out bytesWritten);
153 }
154 if (destination.Length != 0)
155 {
156 int num;
157 checked
158 {
159 if (valueEncoding == null || valueEncoding == Encoding.Latin1)
160 {
161 num = (values.Length - 1) * separator.Length;
162 ReadOnlySpan<string> readOnlySpan = values;
163 for (int i = 0; i < readOnlySpan.Length; i = unchecked(i + 1))
164 {
165 string text = readOnlySpan[i];
166 num += text.Length;
167 }
168 }
169 else
170 {
171 num = (values.Length - 1) * valueEncoding.GetByteCount(separator);
172 ReadOnlySpan<string> readOnlySpan2 = values;
173 for (int j = 0; j < readOnlySpan2.Length; j = unchecked(j + 1))
174 {
175 string s = readOnlySpan2[j];
176 num += valueEncoding.GetByteCount(s);
177 }
178 }
179 destination[0] = 0;
180 }
181 if (IntegerEncoder.Encode(num, 7, destination, out var bytesWritten2))
182 {
183 destination = destination.Slice(bytesWritten2);
184 if (destination.Length >= num)
185 {
186 if (valueEncoding == null)
187 {
188 string text2 = values[0];
190 destination = destination.Slice(text2.Length);
191 for (int k = 1; k < values.Length; k++)
192 {
194 destination = destination.Slice(separator.Length);
195 text2 = values[k];
197 destination = destination.Slice(text2.Length);
198 }
199 }
200 else
201 {
202 int bytes = valueEncoding.GetBytes(values[0], destination);
204 for (int l = 1; l < values.Length; l++)
205 {
206 bytes = valueEncoding.GetBytes(separator, destination);
208 bytes = valueEncoding.GetBytes(values[l], destination);
210 }
211 }
212 bytesWritten = bytesWritten2 + num;
213 return true;
214 }
215 }
216 }
217 return false;
218 }
static void EncodeValueStringPart(string value, Span< byte > destination)
static bool EncodeStringLiteral(string value, Encoding valueEncoding, Span< byte > destination, out int bytesWritten)
static Encoding Latin1
Definition Encoding.cs:513
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
virtual int GetByteCount(char[] chars)
Definition Encoding.cs:713

References System.bytes, System.destination, System.Net.Http.HPack.IntegerEncoder.Encode(), System.Net.Http.HPack.HPackEncoder.EncodeStringLiteral(), System.Net.Http.HPack.HPackEncoder.EncodeValueStringPart(), System.Text.Encoding.GetByteCount(), System.Text.Encoding.GetBytes(), System.Text.Encoding.Latin1, System.ReadOnlySpan< T >.Length, System.s, System.text, and System.values.

Referenced by System.Net.Http.HPack.HPackEncoder.EncodeLiteralHeaderFieldWithoutIndexingNewName(), and System.Net.Http.Http2Connection.WriteLiteralHeaderValues().