Class: Omnizip::Algorithms::Zstandard::Frame::Block
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Zstandard::Frame::Block
- Includes:
- Constants
- Defined in:
- lib/omnizip/algorithms/zstandard/frame/block.rb
Overview
Zstandard block header parser (RFC 8878 Section 3.1.1.2)
Block_Header structure (3 bytes, little-endian):
- Last_Block: bit 0
- Block_Type: bits 1-2
- Block_Size: bits 3-23
Constant Summary
Constants included from Constants
Constants::BLOCK_HEADER_SIZE, Constants::BLOCK_MAX_SIZE, Constants::BLOCK_TYPE_COMPRESSED, Constants::BLOCK_TYPE_RAW, Constants::BLOCK_TYPE_RESERVED, Constants::BLOCK_TYPE_RLE, Constants::BUFFER_SIZE, Constants::DEFAULT_LEVEL, Constants::DEFAULT_REPEAT_OFFSETS, Constants::FSE_MAX_ACCURACY_LOG, Constants::FSE_MIN_ACCURACY_LOG, Constants::HUFFMAN_MAX_BITS, Constants::HUFFMAN_MAX_CODE_LENGTH, Constants::HUFFMAN_MAX_LOG, Constants::HUFFMAN_STANDARD_TABLE_SIZE, Constants::LITERALS_BLOCK_COMPRESSED, Constants::LITERALS_BLOCK_RAW, Constants::LITERALS_BLOCK_RLE, Constants::LITERALS_BLOCK_TREELESS, Constants::LITERALS_LENGTH_ACCURACY_LOG, Constants::LITERAL_LENGTH_TABLE, Constants::MAGIC_BYTES, Constants::MAGIC_NUMBER, Constants::MATCH_LENGTH_ACCURACY_LOG, Constants::MATCH_LENGTH_TABLE, Constants::MAX_LEVEL, Constants::MIN_LEVEL, Constants::MODE_FSE, Constants::MODE_PREDEFINED, Constants::MODE_REPEAT, Constants::MODE_RLE, Constants::OFFSET_ACCURACY_LOG, Constants::PREDEFINED_LL_DISTRIBUTION, Constants::PREDEFINED_ML_DISTRIBUTION, Constants::PREDEFINED_OFFSET_DISTRIBUTION, Constants::REPEAT_OFFSET_1, Constants::REPEAT_OFFSET_2, Constants::REPEAT_OFFSET_3, Constants::SKIPPABLE_MAGIC_BASE, Constants::SKIPPABLE_MAGIC_MASK, Constants::WINDOW_LOG_MAX, Constants::WINDOW_LOG_MIN
Instance Attribute Summary collapse
-
#block_size ⇒ Integer
readonly
Block size in bytes.
-
#block_type ⇒ Integer
readonly
Block type (0=Raw, 1=RLE, 2=Compressed, 3=Reserved).
-
#last_block ⇒ Boolean
readonly
True if this is the last block.
-
#raw_header ⇒ Integer
readonly
Block header bytes.
Class Method Summary collapse
-
.parse(input) ⇒ Block
Parse block header from input.
Instance Method Summary collapse
-
#compressed? ⇒ Boolean
Check if this is a compressed block.
-
#initialize(last_block, block_type, block_size, raw_header) ⇒ Block
constructor
Initialize with parsed values.
-
#raw? ⇒ Boolean
Check if this is a raw (uncompressed) block.
-
#reserved? ⇒ Boolean
Check if block type is reserved.
-
#rle? ⇒ Boolean
Check if this is an RLE block.
-
#type_name ⇒ Symbol
Get block type name.
-
#valid? ⇒ Boolean
Validate block type.
Constructor Details
#initialize(last_block, block_type, block_size, raw_header) ⇒ Block
Initialize with parsed values
69 70 71 72 73 74 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 69 def initialize(last_block, block_type, block_size, raw_header) @last_block = last_block @block_type = block_type @block_size = block_size @raw_header = raw_header end |
Instance Attribute Details
#block_size ⇒ Integer (readonly)
Returns Block size in bytes.
43 44 45 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 43 def block_size @block_size end |
#block_type ⇒ Integer (readonly)
Returns Block type (0=Raw, 1=RLE, 2=Compressed, 3=Reserved).
40 41 42 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 40 def block_type @block_type end |
#last_block ⇒ Boolean (readonly)
Returns True if this is the last block.
37 38 39 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 37 def last_block @last_block end |
#raw_header ⇒ Integer (readonly)
Returns Block header bytes.
46 47 48 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 46 def raw_header @raw_header end |
Class Method Details
.parse(input) ⇒ Block
Parse block header from input
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 52 def self.parse(input) bytes = input.read(3) # Read 3 bytes as little-endian 24-bit value raw = bytes.nil? ? 0 : (bytes.getbyte(0) | (bytes.getbyte(1) << 8) | (bytes.getbyte(2) << 16)) last_block = raw.allbits?(0x01) block_type = (raw >> 1) & 0x03 block_size = (raw >> 3) & 0x1FFFFF new(last_block, block_type, block_size, raw) end |
Instance Method Details
#compressed? ⇒ Boolean
Check if this is a compressed block
93 94 95 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 93 def compressed? @block_type == BLOCK_TYPE_COMPRESSED end |
#raw? ⇒ Boolean
Check if this is a raw (uncompressed) block
79 80 81 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 79 def raw? @block_type == BLOCK_TYPE_RAW end |
#reserved? ⇒ Boolean
Check if block type is reserved
100 101 102 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 100 def reserved? @block_type == BLOCK_TYPE_RESERVED end |
#rle? ⇒ Boolean
Check if this is an RLE block
86 87 88 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 86 def rle? @block_type == BLOCK_TYPE_RLE end |
#type_name ⇒ Symbol
Get block type name
114 115 116 117 118 119 120 121 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 114 def type_name case @block_type when BLOCK_TYPE_RAW then :raw when BLOCK_TYPE_RLE then :rle when BLOCK_TYPE_COMPRESSED then :compressed when BLOCK_TYPE_RESERVED then :reserved end end |
#valid? ⇒ Boolean
Validate block type
107 108 109 |
# File 'lib/omnizip/algorithms/zstandard/frame/block.rb', line 107 def valid? !reserved? end |