require 'bit_struct/field' module BitStruct class TextField < Field def initialize( name, length, description = nil ) raise "Length must be multiple of 8" unless ( length % 8 ) == 0 super name, length, description @length_in_bytes = length / 8 end def read( slicer ) res = '' slicer.get_bytes.reverse.each { |b| res << b } res end def write( slicer, new_value ) bytes = [] new_value.each_byte { |b| bytes << b } slicer.set_bytes bytes.reverse end end end