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_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
9 10 11 12 |
# File 'lib/riddle/client/response.rb', line 9 def initialize(str) @str = str @marker = 0 end |
Instance Method Details
#length ⇒ Object
Returns the length of the streamed data
79 80 81 |
# File 'lib/riddle/client/response.rb', line 79 def length @str.length end |
#next ⇒ Object
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 return result end |
#next_64bit_int ⇒ Object
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 return (high << 32) + low end |
#next_array ⇒ Object
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 = [] for i in 0...count items << self.next end return items end |
#next_float ⇒ Object
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 return float end |
#next_float_array ⇒ Object
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 = [] for i in 0...count items << self.next_float end return items end |
#next_int ⇒ Object
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 return int end |
#next_int_array ⇒ Object
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 = [] for i in 0...count items << self.next_int end return items end |