File: server_response.rb

package info (click to toggle)
ruby-em-mongo 0.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 320 kB
  • sloc: ruby: 2,728; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module EM::Mongo
  class ServerResponse

    attr_reader :size, :request_id, :response_to, :op,
      :result_flags, :cursor_id, :starting_from,
      :number_returned, :docs, :connection


    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

  end
end