Class: BitStream::FieldReader

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, instance) ⇒ FieldReader

Returns a new instance of FieldReader.



167
168
169
170
# File 'lib/bitstream.rb', line 167

def initialize(type, instance)
  @type = type
  @instance = instance
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



216
217
218
# File 'lib/bitstream.rb', line 216

def offset
  @offset
end

Instance Method Details

#indexObject



205
206
207
208
209
210
211
212
213
214
# File 'lib/bitstream.rb', line 205

def index
  queue = props.eval_queue
  
  while @offset.nil?
    field = queue.deq
    field.offset = props.curr_offset
    length = field.length
    props.curr_offset += length
  end
end

#lengthObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/bitstream.rb', line 189

def length
  length = @type.length
  # @length must not be nil if @has_read.
  if length.nil?
    if @info.nil?
      if @offset.nil?
        index
      end
      @info = @type.read(props.raw_data, @offset)
    end
    return @info[:length]
  else
    return length
  end
end

#readObject Also known as: value



177
178
179
180
181
182
183
184
185
# File 'lib/bitstream.rb', line 177

def read
  if @info.nil?
    if @offset.nil?
      index
    end
    @info = @type.read(props.raw_data, @offset)
  end
  return @info[:value]
end