Class: EM::Mongo::ServerResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/em-mongo/server_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer, connection) ⇒ ServerResponse

Returns a new instance of ServerResponse.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/em-mongo/server_response.rb', line 9

def initialize(buffer, connection)
  @connection = connection
  # Header
  @size        = buffer.get_int
  @request_id  = buffer.get_int
  @response_to = buffer.get_int
  @op          = buffer.get_int

  # Response Header
  @result_flags     = buffer.get_int
  @cursor_id        = buffer.get_long
  @starting_from    = buffer.get_int
  @number_returned  = buffer.get_int

  # Documents
  pos = buffer.position
  @docs = (1..@number_returned).map do
    size= @connection.peek_size(buffer)
    doc = BSON::BSON_CODER.deserialize(buffer.to_s[pos,size])
    pos += size
    buffer.position = pos
    doc
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def connection
  @connection
end

#cursor_idObject (readonly)

Returns the value of attribute cursor_id.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def cursor_id
  @cursor_id
end

#docsObject (readonly)

Returns the value of attribute docs.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def docs
  @docs
end

#number_returnedObject (readonly)

Returns the value of attribute number_returned.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def number_returned
  @number_returned
end

#opObject (readonly)

Returns the value of attribute op.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def op
  @op
end

#request_idObject (readonly)

Returns the value of attribute request_id.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def request_id
  @request_id
end

#response_toObject (readonly)

Returns the value of attribute response_to.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def response_to
  @response_to
end

#result_flagsObject (readonly)

Returns the value of attribute result_flags.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def result_flags
  @result_flags
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def size
  @size
end

#starting_fromObject (readonly)

Returns the value of attribute starting_from.



4
5
6
# File 'lib/em-mongo/server_response.rb', line 4

def starting_from
  @starting_from
end