Class: GrizzlyBerElement
- Inherits:
-
Object
- Object
- GrizzlyBerElement
- Defined in:
- lib/grizzly_ber.rb
Instance Attribute Summary collapse
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(byte_array = []) ⇒ GrizzlyBerElement
constructor
A new instance of GrizzlyBerElement.
- #to_ber ⇒ Object
Constructor Details
#initialize(byte_array = []) ⇒ GrizzlyBerElement
Returns a new instance of GrizzlyBerElement.
8 9 10 11 12 13 |
# File 'lib/grizzly_ber.rb', line 8 def initialize(byte_array = []) raise ArgumentError, "byte_array must be of type Array" unless byte_array.is_a?(Array) @tag = +"" # is an uppercase hex string @value = nil # is a byte array if this is a data element or a GrizzlyBer if it's a sequence element decode_value decode_length decode_tag byte_array end |
Instance Attribute Details
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/grizzly_ber.rb', line 6 def tag @tag end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/grizzly_ber.rb', line 6 def value @value end |
Instance Method Details
#to_ber ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/grizzly_ber.rb', line 26 def to_ber ber_array = "" ber_array += @tag.upcase value_hex_string = @value.pack("C*").unpack("H*").first.upcase if @value.is_a? Array value_hex_string = @value.to_ber if @value.is_a? GrizzlyBer value_byte_count = value_hex_string.size/2 if value_byte_count < 0x7F # if the length of the value array is only one byte long and does not have its upper bit set ber_array << byte_to_hex(value_byte_count) else #pack("w") was meant to do this length calc but doesn't work right... number_of_bytes_in_byte_count = ((value_byte_count).to_s(16).size/2.0).ceil ber_array << byte_to_hex(number_of_bytes_in_byte_count | 0x80) ber_array += (value_byte_count).to_s(16).rjust(number_of_bytes_in_byte_count*2,'0').upcase end ber_array += value_hex_string end |