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

◆ EncodeValueString() [1/2]

static bool System.Net.Http.QPack.QPackEncoder.EncodeValueString ( ReadOnlySpan< string > values,
string separator,
Encoding valueEncoding,
Span< byte > buffer,
out int length )
inlinestatic

Definition at line 142 of file QPackEncoder.cs.

143 {
144 if (values.Length == 1)
145 {
146 return EncodeValueString(values[0], valueEncoding, buffer, out length);
147 }
148 if (values.Length == 0)
149 {
150 return EncodeValueString(string.Empty, null, buffer, out length);
151 }
152 if (buffer.Length > 0)
153 {
154 int num;
155 if (valueEncoding == null || valueEncoding == Encoding.Latin1)
156 {
157 num = separator.Length * (values.Length - 1);
158 ReadOnlySpan<string> readOnlySpan = values;
159 for (int i = 0; i < readOnlySpan.Length; i++)
160 {
161 string text = readOnlySpan[i];
162 num += text.Length;
163 }
164 }
165 else
166 {
167 num = valueEncoding.GetByteCount(separator) * (values.Length - 1);
168 ReadOnlySpan<string> readOnlySpan2 = values;
169 for (int j = 0; j < readOnlySpan2.Length; j++)
170 {
171 string s = readOnlySpan2[j];
172 num += valueEncoding.GetByteCount(s);
173 }
174 }
175 buffer[0] = 0;
176 if (IntegerEncoder.Encode(num, 7, buffer, out var bytesWritten))
177 {
178 buffer = buffer.Slice(bytesWritten);
179 if (buffer.Length >= num)
180 {
181 if (valueEncoding == null)
182 {
183 string text2 = values[0];
185 buffer = buffer.Slice(text2.Length);
186 for (int k = 1; k < values.Length; k++)
187 {
188 EncodeValueStringPart(separator, buffer);
189 buffer = buffer.Slice(separator.Length);
190 text2 = values[k];
192 buffer = buffer.Slice(text2.Length);
193 }
194 }
195 else
196 {
197 int bytes = valueEncoding.GetBytes(values[0], buffer);
198 buffer = buffer.Slice(bytes);
199 for (int l = 1; l < values.Length; l++)
200 {
201 bytes = valueEncoding.GetBytes(separator, buffer);
202 buffer = buffer.Slice(bytes);
203 bytes = valueEncoding.GetBytes(values[l], buffer);
204 buffer = buffer.Slice(bytes);
205 }
206 }
207 length = bytesWritten + num;
208 return true;
209 }
210 }
211 }
212 length = 0;
213 return false;
214 }
static bool Encode(int value, int numBits, Span< byte > destination, out int bytesWritten)
static bool EncodeValueString(string s, Encoding valueEncoding, Span< byte > buffer, out int length)
static void EncodeValueStringPart(string s, Span< byte > buffer)
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.buffer, System.bytes, System.Net.Http.HPack.IntegerEncoder.Encode(), System.Net.Http.QPack.QPackEncoder.EncodeValueString(), System.Net.Http.QPack.QPackEncoder.EncodeValueStringPart(), System.Text.Encoding.GetByteCount(), System.Text.Encoding.GetBytes(), System.Text.Encoding.Latin1, System.length, System.ReadOnlySpan< T >.Length, System.s, System.text, and System.values.