Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlChars.cs
Go to the documentation of this file.
1using System.IO;
3using System.Xml;
6
8
9[XmlSchemaProvider("GetXsdType")]
11{
12 internal char[] _rgchBuf;
13
14 private long _lCurLen;
15
17
19
20 private char[] _rgchWorkBuf;
21
22 public bool IsNull => _state == SqlBytesCharsState.Null;
23
24 public char[]? Buffer
25 {
26 get
27 {
28 if (FStream())
29 {
31 }
32 return _rgchBuf;
33 }
34 }
35
36 public long Length => _state switch
37 {
40 _ => _lCurLen,
41 };
42
43 public long MaxLength
44 {
45 get
46 {
48 if (state == SqlBytesCharsState.Stream)
49 {
50 return -1L;
51 }
52 return (_rgchBuf == null) ? (-1) : _rgchBuf.Length;
53 }
54 }
55
56 public char[] Value
57 {
58 get
59 {
60 char[] array;
61 switch (_state)
62 {
63 case SqlBytesCharsState.Null:
64 throw new SqlNullValueException();
65 case SqlBytesCharsState.Stream:
66 if (_stream.Length > int.MaxValue)
67 {
69 }
70 array = new char[_stream.Length];
71 if (_stream.Position != 0L)
72 {
73 _stream.Seek(0L, SeekOrigin.Begin);
74 }
76 break;
77 default:
78 array = new char[_lCurLen];
80 break;
81 }
82 return array;
83 }
84 }
85
86 public char this[long offset]
87 {
88 get
89 {
91 {
92 throw new ArgumentOutOfRangeException("offset");
93 }
94 if (_rgchWorkBuf == null)
95 {
96 _rgchWorkBuf = new char[1];
97 }
98 Read(offset, _rgchWorkBuf, 0, 1);
99 return _rgchWorkBuf[0];
100 }
101 set
102 {
103 if (_rgchWorkBuf == null)
104 {
105 _rgchWorkBuf = new char[1];
106 }
107 _rgchWorkBuf[0] = value;
108 Write(offset, _rgchWorkBuf, 0, 1);
109 }
110 }
111
112 public StorageState Storage => _state switch
113 {
117 _ => StorageState.UnmanagedBuffer,
118 };
119
120 public static SqlChars Null => new SqlChars((char[]?)null);
121
122 public SqlChars()
123 {
124 SetNull();
125 }
126
127 public SqlChars(char[]? buffer)
128 {
130 _stream = null;
131 if (_rgchBuf == null)
132 {
134 _lCurLen = -1L;
135 }
136 else
137 {
138 _state = SqlBytesCharsState.Buffer;
139 _lCurLen = _rgchBuf.Length;
140 }
141 _rgchWorkBuf = null;
142 }
143
145 : this(value.IsNull ? null : value.Value.ToCharArray())
146 {
147 }
148
149 public void SetNull()
150 {
151 _lCurLen = -1L;
152 _stream = null;
154 }
155
156 public void SetLength(long value)
157 {
158 if (value < 0)
159 {
160 throw new ArgumentOutOfRangeException("value");
161 }
162 if (FStream())
163 {
165 return;
166 }
167 if (_rgchBuf == null)
168 {
170 }
171 if (value > _rgchBuf.Length)
172 {
173 throw new ArgumentOutOfRangeException("value");
174 }
175 if (IsNull)
176 {
177 _state = SqlBytesCharsState.Buffer;
178 }
179 _lCurLen = value;
180 }
181
182 public long Read(long offset, char[] buffer, int offsetInBuffer, int count)
183 {
184 if (IsNull)
185 {
186 throw new SqlNullValueException();
187 }
188 if (buffer == null)
189 {
190 throw new ArgumentNullException("buffer");
191 }
192 if (offset > Length || offset < 0)
193 {
194 throw new ArgumentOutOfRangeException("offset");
195 }
196 if (offsetInBuffer > buffer.Length || offsetInBuffer < 0)
197 {
198 throw new ArgumentOutOfRangeException("offsetInBuffer");
199 }
201 {
202 throw new ArgumentOutOfRangeException("count");
203 }
204 if (count > Length - offset)
205 {
206 count = (int)(Length - offset);
207 }
208 if (count != 0)
209 {
211 if (state == SqlBytesCharsState.Stream)
212 {
213 if (_stream.Position != offset)
214 {
216 }
218 }
219 else
220 {
222 }
223 }
224 return count;
225 }
226
227 public void Write(long offset, char[] buffer, int offsetInBuffer, int count)
228 {
229 if (FStream())
230 {
231 if (_stream.Position != offset)
232 {
234 }
236 return;
237 }
238 if (buffer == null)
239 {
240 throw new ArgumentNullException("buffer");
241 }
242 if (_rgchBuf == null)
243 {
245 }
246 if (offset < 0)
247 {
248 throw new ArgumentOutOfRangeException("offset");
249 }
250 if (offset > _rgchBuf.Length)
251 {
253 }
255 {
256 throw new ArgumentOutOfRangeException("offsetInBuffer");
257 }
259 {
260 throw new ArgumentOutOfRangeException("count");
261 }
262 if (count > _rgchBuf.Length - offset)
263 {
265 }
266 if (IsNull)
267 {
268 if (offset != 0L)
269 {
271 }
272 _lCurLen = 0L;
273 _state = SqlBytesCharsState.Buffer;
274 }
275 else if (offset > _lCurLen)
276 {
278 }
279 if (count != 0)
280 {
282 if (_lCurLen < offset + count)
283 {
285 }
286 }
287 }
288
290 {
291 if (!IsNull)
292 {
293 return new string(Value);
294 }
295 return SqlString.Null;
296 }
297
298 public static explicit operator SqlString(SqlChars value)
299 {
300 return value.ToSqlString();
301 }
302
303 public static explicit operator SqlChars(SqlString value)
304 {
305 return new SqlChars(value);
306 }
307
308 internal bool FStream()
309 {
310 return _state == SqlBytesCharsState.Stream;
311 }
312
313 private void CopyStreamToBuffer()
314 {
315 long length = _stream.Length;
316 if (length >= int.MaxValue)
317 {
319 }
320 if (_rgchBuf == null || _rgchBuf.Length < length)
321 {
322 _rgchBuf = new char[length];
323 }
324 if (_stream.Position != 0L)
325 {
326 _stream.Seek(0L, SeekOrigin.Begin);
327 }
328 _stream.Read(_rgchBuf, 0, (int)length);
329 _stream = null;
331 _state = SqlBytesCharsState.Buffer;
332 }
333
334 private void SetBuffer(char[] buffer)
335 {
337 _lCurLen = ((_rgchBuf == null) ? (-1) : _rgchBuf.Length);
338 _stream = null;
339 _state = ((_rgchBuf != null) ? SqlBytesCharsState.Buffer : SqlBytesCharsState.Null);
340 }
341
343 {
344 return null;
345 }
346
348 {
349 char[] array = null;
350 string attribute = r.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
351 if (attribute != null && XmlConvert.ToBoolean(attribute))
352 {
353 r.ReadElementString();
354 SetNull();
355 }
356 else
357 {
358 array = r.ReadElementString().ToCharArray();
360 }
361 }
362
364 {
365 if (IsNull)
366 {
367 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
368 return;
369 }
370 char[] buffer = Buffer;
371 writer.WriteString(new string(buffer, 0, (int)Length));
372 }
373
375 {
376 return new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
377 }
378
383}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
void SetBuffer(char[] buffer)
Definition SqlChars.cs:334
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlChars.cs:374
void Write(long offset, char[] buffer, int offsetInBuffer, int count)
Definition SqlChars.cs:227
long Read(long offset, char[] buffer, int offsetInBuffer, int count)
Definition SqlChars.cs:182
void SetLength(long value)
Definition SqlChars.cs:156
SqlChars(SqlString value)
Definition SqlChars.cs:144
SqlBytesCharsState _state
Definition SqlChars.cs:18
long Seek(long offset, SeekOrigin origin)
void Write(char[] buffer, int offset, int count)
int Read(char[] buffer, int offset, int count)
static string SqlMisc_BufferInsufficientMessage
Definition SR.cs:870
static string SqlMisc_NoBufferMessage
Definition SR.cs:868
static string SqlMisc_WriteNonZeroOffsetOnNullMessage
Definition SR.cs:872
static string SqlMisc_WriteOffsetLargerThanLenMessage
Definition SR.cs:874
Definition SR.cs:7
static bool ToBoolean(string s)
void GetObjectData(SerializationInfo info, StreamingContext context)
static readonly SqlString Null
Definition SqlString.cs:27