Class: Fields::StringField

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

Overview

SignedField

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) ⇒ StringField

Returns a new instance of StringField.



271
272
273
274
# File 'lib/fields.rb', line 271

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

Instance Method Details

#get_valueObject



283
284
285
286
# File 'lib/fields.rb', line 283

def get_value
    return @bitstring if @bitstring==""
    [@bitstring].pack('B*')
end

#input_to_bitstring(value) ⇒ Object



276
277
278
279
280
281
# File 'lib/fields.rb', line 276

def input_to_bitstring( value )
    unless value.respond_to? :to_str 
        raise ArgumentError, "StringField(#{@name}): Input value not a string."
    end
    value.to_str.unpack('B*').join
end