Class: Riddle::Client::Response
- Inherits:
-
Object
- Object
- Riddle::Client::Response
- 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
-
#initialize(str) ⇒ Response
constructor
Create with the data to interpret.
-
#length ⇒ Object
Returns the length of the streamed data.
-
#next ⇒ Object
Return the next string value in the stream.
- #next_64bit_int ⇒ Object
- #next_64bit_int_array ⇒ Object
-
#next_array ⇒ Object
Returns an array of string items.
-
#next_float ⇒ Object
Return the next float value from the stream.
- #next_float_array ⇒ Object
-
#next_int ⇒ Object
Return the next integer value from the stream.
-
#next_int_array ⇒ Object
Returns an array of int items.
Constructor Details
#initialize(str) ⇒ Response
Create with the data to interpret
11 12 13 14 |
# File 'lib/riddle/client/response.rb', line 11 def initialize(str) @str = str @marker = 0 end |
Instance Method Details
#length ⇒ Object
Returns the length of the streamed data
91 92 93 |
# File 'lib/riddle/client/response.rb', line 91 def length @str.length end |
#next ⇒ Object
Return the next string value in the stream
17 18 19 20 21 22 23 |
# File 'lib/riddle/client/response.rb', line 17 def next len = next_int result = @str[@marker, len] @marker += len Riddle.encode(result) end |
#next_64bit_int ⇒ Object
33 34 35 36 37 38 |
# File 'lib/riddle/client/response.rb', line 33 def next_64bit_int high, low = @str[@marker, 8].unpack('N*N*')[0..1] @marker += 8 (high << 32) + low end |
#next_64bit_int_array ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/riddle/client/response.rb', line 80 def next_64bit_int_array byte_count = next_int items = [] (byte_count / 2).times do items << self.next_64bit_int end items end |
#next_array ⇒ Object
Returns an array of string items
49 50 51 52 53 54 55 56 57 |
# File 'lib/riddle/client/response.rb', line 49 def next_array count = next_int items = [] count.times do items << self.next end items end |
#next_float ⇒ Object
Return the next float value from the stream
41 42 43 44 45 46 |
# File 'lib/riddle/client/response.rb', line 41 def next_float float = @str[@marker, 4].unpack('N*').pack('L').unpack('f*').first @marker += 4 float end |
#next_float_array ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/riddle/client/response.rb', line 70 def next_float_array count = next_int items = [] count.times do items << self.next_float end items end |
#next_int ⇒ Object
Return the next integer value from the stream
26 27 28 29 30 31 |
# File 'lib/riddle/client/response.rb', line 26 def next_int int = @str[@marker, 4].unpack('N*').first @marker += 4 int end |
#next_int_array ⇒ Object
Returns an array of int items
60 61 62 63 64 65 66 67 68 |
# File 'lib/riddle/client/response.rb', line 60 def next_int_array count = next_int items = [] count.times do items << self.next_int end items end |