Class: Sphinx::Request
- Inherits:
-
Object
- Object
- Sphinx::Request
- Defined in:
- lib/sphinx/request.rb
Overview
Pack ints, floats, strings, and arrays to internal representation needed by Sphinx search engine.
Instance Method Summary (collapse)
-
- (Integer) crc32
Returns CRC32 of the serialized request.
-
- (Request) initialize
constructor
Initialize new empty request.
-
- (Request) put_float(*floats)
Put float(s) to request.
-
- (Request) put_int(*ints)
Put int(s) to request.
-
- (Request) put_int64(*ints)
Put 64-bit int(s) to request.
-
- (Request) put_int64_array(arr)
Put array of 64-bit ints to request.
-
- (Request) put_int_array(arr)
Put array of ints to request.
-
- (Request) put_string(*strings)
Put strings to request.
-
- (String) to_s
Returns the serialized request.
Constructor Details
- (Request) initialize
Initialize new empty request.
8 9 10 |
# File 'lib/sphinx/request.rb', line 8 def initialize @request = '' end |
Instance Method Details
- (Integer) crc32
Returns CRC32 of the serialized request.
117 118 119 |
# File 'lib/sphinx/request.rb', line 117 def crc32 Zlib.crc32(@request) end |
- (Request) put_float(*floats)
Put float(s) to request.
67 68 69 70 71 72 73 74 |
# File 'lib/sphinx/request.rb', line 67 def put_float(*floats) floats.each do |f| t1 = [f.to_f].pack('f') # machine order t2 = t1.unpack('L*').first # int in machine order @request << [t2].pack('N') end self end |
- (Request) put_int(*ints)
Put int(s) to request.
22 23 24 25 |
# File 'lib/sphinx/request.rb', line 22 def put_int(*ints) ints.each { |i| @request << [i].pack('N') } self end |
- (Request) put_int64(*ints)
Put 64-bit int(s) to request.
37 38 39 40 |
# File 'lib/sphinx/request.rb', line 37 def put_int64(*ints) ints.each { |i| @request << [i].pack('q').reverse }#[i >> 32, i & ((1 << 32) - 1)].pack('NN') } self end |
- (Request) put_int64_array(arr)
Put array of 64-bit ints to request.
99 100 101 102 103 |
# File 'lib/sphinx/request.rb', line 99 def put_int64_array(arr) put_int(arr.length) put_int64(*arr) self end |
- (Request) put_int_array(arr)
Put array of ints to request.
85 86 87 88 |
# File 'lib/sphinx/request.rb', line 85 def put_int_array(arr) put_int arr.length, *arr self end |
- (Request) put_string(*strings)
Put strings to request.
52 53 54 55 |
# File 'lib/sphinx/request.rb', line 52 def put_string(*strings) strings.each { |s| @request << [s.length].pack('N') + s } self end |
- (String) to_s
Returns the serialized request.
109 110 111 |
# File 'lib/sphinx/request.rb', line 109 def to_s @request end |