def read_var_integer(data, offset = 0)
      raise ArgumentError, "data is nil." unless data
      packed = [data].pack('H*')
      return [nil, 0] if packed.bytesize < 1+offset
      bytes = packed.bytes[offset..(offset + 9)] # 9 is variable integer max storage length.
      first_byte = bytes[0]
      if first_byte < 0xfd
        [first_byte, offset + 1]
      elsif first_byte == 0xfd
        [calc_var_integer_val(bytes[1..2]), offset + 3]
      elsif first_byte == 0xfe
        [calc_var_integer_val(bytes[1..4]), offset + 5]
      elsif first_byte == 0xff
        [calc_var_integer_val(bytes[1..8]), offset + 9]
      end
    end
def read_var_integer(data, offset = 0)
      raise ArgumentError, "data is nil." unless data
      packed = [data].pack('H*')
      return [nil, 0] if packed.bytesize < 1+offset
      bytes = packed.bytes[offset..(offset + 9)] # 9 is variable integer max storage length.
      first_byte = bytes[0]
      if first_byte < 0xfd
        [first_byte, offset + 1]
      elsif first_byte == 0xfd
        [calc_var_integer_val(bytes[1..2]), offset + 3]
      elsif first_byte == 0xfe
        [calc_var_integer_val(bytes[1..4]), offset + 5]
      elsif first_byte == 0xff
        [calc_var_integer_val(bytes[1..8]), offset + 9]
      end
    end
read variable integer
 @param [String] data reading data
 @param [Integer] offset the position when reading from data.
 @return [[Integer, Integer]]  decoded integer value and the reading byte length.
 https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer