Class: Fields::BitstringField

Inherits:
Field show all
Defined in:
lib/fields.rb

Overview

For getting and setting via binary strings

Instance Attribute Summary

Attributes inherited from Field

#bitstring, #default_value, #desc, #endianness, #length, #length_type, #name, #type

Instance Method Summary collapse

Methods inherited from Field

#parse_buffer, #parse_buffer_lazy, #parse_buffer_strict, #randomize!, #set_raw, #set_value, #to_s

Constructor Details

#initialize(*args) ⇒ BitstringField

Returns a new instance of BitstringField.



292
293
294
295
# File 'lib/fields.rb', line 292

def initialize *args
    @length_type="fixed"
    super
end

Instance Method Details

#get_valueObject



304
305
306
# File 'lib/fields.rb', line 304

def get_value
    @bitstring
end

#input_to_bitstring(value) ⇒ Object



297
298
299
300
301
302
# File 'lib/fields.rb', line 297

def input_to_bitstring( value )
    unless value.respond_to? :to_str  and value.to_str=~/^[01\s]*$/
        raise ArgumentError, "BitstringField(#{@name}) (PARSE): Input value not a bitstring."
    end
    parse_buffer(value.to_str.gsub(/\s/,''))
end