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

◆ DecodeBlock()

bool System.IO.Compression.InflaterManaged.DecodeBlock ( out bool end_of_block_code_seen)
inlineprivate

Definition at line 268 of file InflaterManaged.cs.

269 {
270 end_of_block_code_seen = false;
271 int num = _output.FreeBytes;
272 while (num > 65536)
273 {
274 switch (_state)
275 {
276 case InflaterState.DecodeTop:
277 {
278 int nextSymbol = _literalLengthTree.GetNextSymbol(_input);
279 if (nextSymbol < 0)
280 {
281 return false;
282 }
283 if (nextSymbol < 256)
284 {
285 _output.Write((byte)nextSymbol);
286 num--;
287 break;
288 }
289 if (nextSymbol == 256)
290 {
291 end_of_block_code_seen = true;
292 _state = InflaterState.ReadingBFinal;
293 return true;
294 }
295 nextSymbol -= 257;
296 if (nextSymbol < 8)
297 {
298 nextSymbol += 3;
299 _extraBits = 0;
300 }
301 else if (!_deflate64 && nextSymbol == 28)
302 {
303 nextSymbol = 258;
304 _extraBits = 0;
305 }
306 else
307 {
308 if (nextSymbol < 0 || nextSymbol >= s_extraLengthBits.Length)
309 {
310 throw new InvalidDataException(System.SR.GenericInvalidData);
311 }
312 _extraBits = s_extraLengthBits[nextSymbol];
313 }
314 _length = nextSymbol;
315 goto case InflaterState.HaveInitialLength;
316 }
317 case InflaterState.HaveInitialLength:
318 if (_extraBits > 0)
319 {
320 _state = InflaterState.HaveInitialLength;
321 int bits2 = _input.GetBits(_extraBits);
322 if (bits2 < 0)
323 {
324 return false;
325 }
326 if (_length < 0 || _length >= s_lengthBase.Length)
327 {
328 throw new InvalidDataException(System.SR.GenericInvalidData);
329 }
330 _length = s_lengthBase[_length] + bits2;
331 }
332 _state = InflaterState.HaveFullLength;
333 goto case InflaterState.HaveFullLength;
334 case InflaterState.HaveFullLength:
335 if (_blockType == BlockType.Dynamic)
336 {
338 }
339 else
340 {
342 if (_distanceCode >= 0)
343 {
345 }
346 }
347 if (_distanceCode < 0)
348 {
349 return false;
350 }
351 _state = InflaterState.HaveDistCode;
352 goto case InflaterState.HaveDistCode;
353 case InflaterState.HaveDistCode:
354 {
355 int distance;
356 if (_distanceCode > 3)
357 {
358 _extraBits = _distanceCode - 2 >> 1;
359 int bits = _input.GetBits(_extraBits);
360 if (bits < 0)
361 {
362 return false;
363 }
364 distance = s_distanceBasePosition[_distanceCode] + bits;
365 }
366 else
367 {
368 distance = _distanceCode + 1;
369 }
371 num -= _length;
372 _state = InflaterState.DecodeTop;
373 break;
374 }
375 default:
376 throw new InvalidDataException(System.SR.UnknownState);
377 }
378 }
379 return true;
380 }
int GetNextSymbol(InputBuffer input)
static readonly byte[] s_staticDistanceTreeTable
static readonly byte[] s_extraLengthBits
static readonly int[] s_distanceBasePosition
void WriteLengthDistance(int length, int distance)
static string UnknownState
Definition SR.cs:38
static string GenericInvalidData
Definition SR.cs:20
Definition SR.cs:7

References System.IO.Compression.InflaterManaged._blockType, System.IO.Compression.InflaterManaged._deflate64, System.IO.Compression.InflaterManaged._distanceCode, System.IO.Compression.InflaterManaged._distanceTree, System.IO.Compression.InflaterManaged._extraBits, System.IO.Compression.InflaterManaged._input, System.IO.Compression.InflaterManaged._length, System.IO.Compression.InflaterManaged._literalLengthTree, System.IO.Compression.InflaterManaged._output, System.IO.Compression.InflaterManaged._state, System.IO.Compression.OutputWindow.FreeBytes, System.SR.GenericInvalidData, System.IO.Compression.InputBuffer.GetBits(), System.IO.Compression.HuffmanTree.GetNextSymbol(), System.IO.Compression.InflaterManaged.s_distanceBasePosition, System.IO.Compression.InflaterManaged.s_extraLengthBits, System.IO.Compression.InflaterManaged.s_lengthBase, System.IO.Compression.InflaterManaged.s_staticDistanceTreeTable, System.SR.UnknownState, System.IO.Compression.OutputWindow.Write(), and System.IO.Compression.OutputWindow.WriteLengthDistance().

Referenced by System.IO.Compression.InflaterManaged.Decode().