dmendel / bindata

BinData - Reading and Writing Binary Data in Ruby
BSD 2-Clause "Simplified" License
577 stars 55 forks source link

Virtual fields affecting output when record is written #73

Closed hopesea closed 8 years ago

hopesea commented 8 years ago

I have found that if I define a non-byte virtual field within a record, then that virtual field impacts on the ouput when the record is written. For example

require 'bindata'

class A < BinData::Record
  endian :big
  bit4  :f1
  virtual  :f1_mod, :value => lambda { f1 + 1}
  bit4  :f2
  bit8  :f3
end

input = StringIO.new("@@")
output = StringIO.new("",'wb')

tst = A.read(input)
tst.write(output)

puts "input: #{input.string}"
puts tst
puts "output: #{output.string}"
dmendel commented 8 years ago

Thanks for the report. Fixed in bindata v2.3.1.