ruby - Reusing BinData Records with different data -
if have multiple bindata records take following form, here few examples:
class debuginfo < bindata::record endian :little int32 :num array :data, :type => :debug_log, initial_length: :num end class goalinfo < bindata::record endian :little int32 :num array :data, :type => :goal, initial_length: :num end class packageinfo < bindata::record endian :little int32 :num array :data, :type => :package, initial_length: :num end
all of these same, make array using different types of objects. there way make 1 of these , somehow pass type of object want read array?
module info @base_classes = {} def self.[](type) @base_classes[type] ||= class.new(bindata::record) { endian :little int32 :num array :data, :type => type, initial_length: :num } end end
then
class debuginfo < info[:debug_log] end class goalinfo < info[:goal] end class packageinfo < info[:package] end
disclaimer
not tested.
Comments
Post a Comment