Class: Mongo::Message
- Inherits:
-
Object
show all
- Defined in:
- lib/mongo/message/message.rb
Constant Summary
collapse
16
- @@class_req_id =
0
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(op) ⇒ Message
Returns a new instance of Message.
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/mongo/message/message.rb', line 30
def initialize(op)
@op = op
@message_length = HEADER_SIZE
@data_length = 0
@request_id = (@@class_req_id += 1)
@response_id = 0
@buf = ByteBuffer.new
@buf.put_int(16) @buf.put_int(@request_id)
@buf.put_int(0) @buf.put_int(op)
end
|
Instance Attribute Details
#buf ⇒ Object
28
29
30
|
# File 'lib/mongo/message/message.rb', line 28
def buf
@buf
end
|
Instance Method Details
#dump ⇒ Object
68
69
70
|
# File 'lib/mongo/message/message.rb', line 68
def dump
@buf.dump
end
|
#to_a ⇒ Object
64
65
66
|
# File 'lib/mongo/message/message.rb', line 64
def to_a
@buf.to_a
end
|
#update_message_length ⇒ Object
Do not call. Private, but kept public for testing.
73
74
75
76
77
|
# File 'lib/mongo/message/message.rb', line 73
def update_message_length
pos = @buf.position
@buf.put_int(@buf.size, 0)
@buf.position = pos
end
|
#write_doc(hash, check_keys = false) ⇒ Object
59
60
61
62
|
# File 'lib/mongo/message/message.rb', line 59
def write_doc(hash, check_keys=false)
@buf.put_array(BSON.new.serialize(hash, check_keys).to_a)
update_message_length
end
|
#write_int(i) ⇒ Object
44
45
46
47
|
# File 'lib/mongo/message/message.rb', line 44
def write_int(i)
@buf.put_int(i)
update_message_length
end
|
#write_long(i) ⇒ Object
49
50
51
52
|
# File 'lib/mongo/message/message.rb', line 49
def write_long(i)
@buf.put_long(i)
update_message_length
end
|
#write_string(s) ⇒ Object
54
55
56
57
|
# File 'lib/mongo/message/message.rb', line 54
def write_string(s)
BSON.serialize_cstr(@buf, s)
update_message_length
end
|