Class: BER::C64

Inherits:
Object show all
Defined in:
lib/gri/msnmp.rb

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ C64

Returns a new instance of C64.



36
37
38
39
40
41
# File 'lib/gri/msnmp.rb', line 36

def initialize s
  @s = s
  @a = [0, 0, 0, 0, 0, 0, 0, 0]
  j = 7
  (s.size-1).downto(0) {|i| @a[j] = s.getbyte(i); j -= 1}
end

Instance Method Details

#to_binaryObject



47
48
49
# File 'lib/gri/msnmp.rb', line 47

def to_binary
  @a.pack('C*')
end

#to_iObject



55
56
57
58
59
# File 'lib/gri/msnmp.rb', line 55

def to_i
  n = 0
  0.upto(7) {|i| n = n * 256 + @a[i]}
  n
end

#to_msgpackObject



51
52
53
# File 'lib/gri/msnmp.rb', line 51

def to_msgpack
  "\xcf" + @a.pack('C*')
end

#to_sObject



43
44
45
# File 'lib/gri/msnmp.rb', line 43

def to_s
  '0x' + @a.map {|b| sprintf "%02x", b}.join('')
end