Class: Omnizip::Algorithms::Zstandard::FSE::Encoder::BitCStream
- Inherits:
-
Object
- Object
- Omnizip::Algorithms::Zstandard::FSE::Encoder::BitCStream
- Defined in:
- lib/omnizip/algorithms/zstandard/fse/encoder.rb
Overview
Forward bit writer (C BIT_CStream): accumulates at the low end and flushes whole bytes.
Instance Method Summary collapse
- #add_bits(value, nb_bits) ⇒ Object
-
#close ⇒ String
Add the 1 end-mark bit and flush everything.
- #flush ⇒ Object
-
#initialize ⇒ BitCStream
constructor
A new instance of BitCStream.
Constructor Details
#initialize ⇒ BitCStream
Returns a new instance of BitCStream.
463 464 465 466 |
# File 'lib/omnizip/algorithms/zstandard/fse/encoder.rb', line 463 def initialize @container = 0 @bit_pos = 0 end |
Instance Method Details
#add_bits(value, nb_bits) ⇒ Object
470 471 472 473 474 |
# File 'lib/omnizip/algorithms/zstandard/fse/encoder.rb', line 470 def add_bits(value, nb_bits) mask = (1 << nb_bits) - 1 @container |= (value & mask) << @bit_pos @bit_pos += nb_bits end |
#close ⇒ String
Add the 1 end-mark bit and flush everything.
489 490 491 492 493 494 |
# File 'lib/omnizip/algorithms/zstandard/fse/encoder.rb', line 489 def close add_bits(1, 1) flush @bytes << (@container & 0xFF) if @bit_pos.positive? @bytes.pack("C*") end |
#flush ⇒ Object
476 477 478 479 480 481 482 483 484 |
# File 'lib/omnizip/algorithms/zstandard/fse/encoder.rb', line 476 def flush nb_bytes = @bit_pos >> 3 @bytes ||= [] nb_bytes.times do |i| @bytes << ((@container >> (8 * i)) & 0xFF) end @container >>= nb_bytes * 8 @bit_pos &= 7 end |