Class: M3u8::Scte35BitReader

Inherits:
Object
  • Object
show all
Defined in:
lib/m3u8/scte35_bit_reader.rb

Overview

Reads sub-byte bit fields from binary data for SCTE-35 parsing

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Scte35BitReader

Returns a new instance of Scte35BitReader.



6
7
8
9
10
# File 'lib/m3u8/scte35_bit_reader.rb', line 6

def initialize(data)
  @data = data.b
  @byte_pos = 0
  @bit_pos = 0
end

Instance Method Details

#bytes_remainingObject



33
34
35
# File 'lib/m3u8/scte35_bit_reader.rb', line 33

def bytes_remaining
  @data.length - @byte_pos - (@bit_pos.positive? ? 1 : 0)
end

#read_bits(count) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/m3u8/scte35_bit_reader.rb', line 12

def read_bits(count)
  value = 0
  count.times do
    value = (value << 1) | current_bit
    advance_bit
  end
  value
end

#read_bytes(count) ⇒ Object



25
26
27
# File 'lib/m3u8/scte35_bit_reader.rb', line 25

def read_bytes(count)
  @data[@byte_pos, count].tap { @byte_pos += count }
end

#read_flagObject



21
22
23
# File 'lib/m3u8/scte35_bit_reader.rb', line 21

def read_flag
  read_bits(1) == 1
end

#skip_bits(count) ⇒ Object



29
30
31
# File 'lib/m3u8/scte35_bit_reader.rb', line 29

def skip_bits(count)
  count.times { advance_bit }
end