module Ruby::SerialData
Public Class Methods
byteArrayToInt(_arr)
click to toggle source
# File lib/ruby/proto.rb, line 79 def byteArrayToInt(_arr) value = 0 _arr.reverse_each do |_byte| # puts "#{__callee__} byte:[#{_byte}]" value = value << 8 value = value | _byte end value end
intToByteArray(_value, _length = 4)
click to toggle source
# File lib/ruby/proto.rb, line 69 def intToByteArray(_value, _length = 4) arr = [] _length.times do |_index| val = _value & 0xff; _value = _value >> 8; arr.push(val) end arr end
Public Instance Methods
loadInt16()
click to toggle source
# File lib/ruby/proto.rb, line 106 def loadInt16 doLoadInt_(2) end
loadInt32()
click to toggle source
# File lib/ruby/proto.rb, line 110 def loadInt32 doLoadInt_(4) end
loadInt8()
click to toggle source
# File lib/ruby/proto.rb, line 102 def loadInt8 doLoadInt_(1) end
storeInt16(_value)
click to toggle source
# File lib/ruby/proto.rb, line 94 def storeInt16(_value) doStoreInt_(_value, 2) end
storeInt32(_value)
click to toggle source
# File lib/ruby/proto.rb, line 90 def storeInt32(_value) doStoreInt_(_value, 4) end
storeInt8(_value)
click to toggle source
# File lib/ruby/proto.rb, line 98 def storeInt8(_value) doStoreInt_(_value, 1) end
Private Instance Methods
doLoadInt_(_length)
click to toggle source
# File lib/ruby/proto.rb, line 121 def doLoadInt_(_length) str = readDataImp(_length) return 0 if str.nil? || str.empty? _length = str.length arr = str.unpack("C#{_length}") SerialData.byteArrayToInt(arr) end
doStoreInt_(_value, _length)
click to toggle source
# File lib/ruby/proto.rb, line 115 def doStoreInt_(_value, _length) arr = SerialData.intToByteArray(_value, _length) str = arr.pack("C#{_length}") writeDataImp(str) end