Class: Riddle::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/riddle/client/response.rb

Overview

Used to interrogate responses from the Sphinx daemon. Keep in mind none of the methods here check whether the data they're grabbing are what the user expects - it just assumes the user knows what the data stream is made up of.

Instance Method Summary (collapse)

Constructor Details

- (Response) initialize(str)

Create with the data to interpret



9
10
11
12
# File 'lib/riddle/client/response.rb', line 9

def initialize(str)
  @str = str
  @marker = 0
end

Instance Method Details

- (Object) length

Returns the length of the streamed data



89
90
91
# File 'lib/riddle/client/response.rb', line 89

def length
  @str.length
end

- (Object) next

Return the next string value in the stream



15
16
17
18
19
20
21
# File 'lib/riddle/client/response.rb', line 15

def next
  len = next_int
  result = @str[@marker, len]
  @marker += len
  
  Riddle.encode(result)
end

- (Object) next_64bit_int



31
32
33
34
35
36
# File 'lib/riddle/client/response.rb', line 31

def next_64bit_int
  high, low = @str[@marker, 8].unpack('N*N*')[0..1]
  @marker += 8
  
  (high << 32) + low
end

- (Object) next_64bit_int_array



78
79
80
81
82
83
84
85
86
# File 'lib/riddle/client/response.rb', line 78

def next_64bit_int_array
  count = next_int
  items = []
  count.times do
    items << self.next_64bit_int
  end
  
  items
end

- (Object) next_array

Returns an array of string items



47
48
49
50
51
52
53
54
55
# File 'lib/riddle/client/response.rb', line 47

def next_array
  count = next_int
  items = []
  count.times do
    items << self.next
  end
  
  items
end

- (Object) next_float

Return the next float value from the stream



39
40
41
42
43
44
# File 'lib/riddle/client/response.rb', line 39

def next_float
  float = @str[@marker, 4].unpack('N*').pack('L').unpack('f*').first
  @marker += 4
  
  float
end

- (Object) next_float_array



68
69
70
71
72
73
74
75
76
# File 'lib/riddle/client/response.rb', line 68

def next_float_array
  count = next_int
  items = []
  count.times do
    items << self.next_float
  end
  
  items
end

- (Object) next_int

Return the next integer value from the stream



24
25
26
27
28
29
# File 'lib/riddle/client/response.rb', line 24

def next_int
  int = @str[@marker, 4].unpack('N*').first
  @marker += 4
  
  int
end

- (Object) next_int_array

Returns an array of int items



58
59
60
61
62
63
64
65
66
# File 'lib/riddle/client/response.rb', line 58

def next_int_array
  count = next_int
  items = []
  count.times do
    items << self.next_int
  end
  
  items
end