diff --git a/Snappier/Internal/Constants.cs b/Snappier/Internal/Constants.cs index 3e62229..8c568f0 100644 --- a/Snappier/Internal/Constants.cs +++ b/Snappier/Internal/Constants.cs @@ -10,7 +10,11 @@ public enum ChunkType : byte UncompressedData = 0x01, SkippableChunk = 0x80, // If this bit is set, we can safely skip the chunk if unknown Padding = 0xfe, - StreamIdentifier = 0xff + StreamIdentifier = 0xff, + + // This is not part of the spec, but having this extra value representing null avoids + // the cost of wrapping in a Nullable + Null = 0xfd, } public const byte Literal = 0b00; diff --git a/Snappier/Internal/SnappyStreamDecompressor.cs b/Snappier/Internal/SnappyStreamDecompressor.cs index c938bac..6558f20 100644 --- a/Snappier/Internal/SnappyStreamDecompressor.cs +++ b/Snappier/Internal/SnappyStreamDecompressor.cs @@ -19,7 +19,7 @@ internal sealed class SnappyStreamDecompressor : IDisposable private readonly byte[] _scratch = new byte[ScratchBufferSize]; private int _scratchLength; - private Constants.ChunkType? _chunkType; + private Constants.ChunkType _chunkType = Constants.ChunkType.Null; private int _chunkSize; private int _chunkBytesProcessed; private uint _expectedChunkCrc; @@ -40,7 +40,7 @@ public int Decompress(Span buffer) // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (_chunkType) { - case null: + case Constants.ChunkType.Null: // Not in a chunk, read the chunk type and size uint rawChunkHeader = ReadChunkHeader(ref input); @@ -106,7 +106,7 @@ public int Decompress(Span buffer) if (_decompressor.EndOfFile) { // Completed reading the chunk - _chunkType = null; + _chunkType = Constants.ChunkType.Null; uint crc = Crc32CAlgorithm.ApplyMask(_chunkCrc); if (_expectedChunkCrc != crc) @@ -149,7 +149,7 @@ public int Decompress(Span buffer) if (_chunkBytesProcessed >= _chunkSize) { // Completed reading the chunk - _chunkType = null; + _chunkType = Constants.ChunkType.Null; uint crc = Crc32CAlgorithm.ApplyMask(_chunkCrc); if (_expectedChunkCrc != crc) @@ -176,7 +176,7 @@ public int Decompress(Span buffer) if (_chunkBytesProcessed >= _chunkSize) { // Completed reading the chunk - _chunkType = null; + _chunkType = Constants.ChunkType.Null; } break;