Class: OWNet::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/connection.rb

Overview

Encapsulates a response from owserver

Constant Summary collapse

PING_PAYLOAD =

Minus one interpreted as an unsigned int

4294967295

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Response

Returns a new instance of Response.

Raises:



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/connection.rb', line 73

def initialize(socket)
  data = socket.read(24)
  raise ShortRead if !data || data.size != 24
    
  version, @payload_len, self.return_value, @format_flags,
  @data_len, @offset = data.unpack('NNNNNN')
  
  if @payload_len > 0 && !isping? 
    #FIXME: Guard against a short read here
    @data = socket.read(@payload_len)[@offset..@data_len+@offset-1] 
  end
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



71
72
73
# File 'lib/connection.rb', line 71

def data
  @data
end

#return_valueObject

Returns the value of attribute return_value.



71
72
73
# File 'lib/connection.rb', line 71

def return_value
  @return_value
end

Instance Method Details

#isping?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/connection.rb', line 86

def isping?
   @payload_len == PING_PAYLOAD
end