Module: BSON
- Defined in:
- lib/bson/bson_c.rb,
lib/bson.rb,
lib/bson/bson_java.rb,
lib/bson/bson_ruby.rb,
lib/bson/exceptions.rb,
lib/bson/types/code.rb,
lib/bson/byte_buffer.rb,
lib/bson/types/dbref.rb,
lib/bson/ordered_hash.rb,
lib/bson/types/binary.rb,
lib/bson/types/object_id.rb,
lib/bson/types/timestamp.rb,
lib/bson/types/min_max_keys.rb
Overview
A hash in which the order of keys are preserved.
Under Ruby 1.9 and greater, this class has no added methods because Ruby’s Hash already keeps its keys ordered by order of insertion.
Defined Under Namespace
Classes: BSONError, BSON_C, BSON_JAVA, BSON_RUBY, Binary, ByteBuffer, Code, DBRef, InvalidDocument, InvalidKeyName, InvalidObjectId, InvalidStringEncoding, MaxKey, MinKey, MongoDBError, MongoRubyError, ObjectId, OrderedHash, Timestamp
Constant Summary collapse
- DEFAULT_MAX_BSON_SIZE =
4 * 1024 * 1024
- NULL_BYTE =
"\x00"
Class Method Summary collapse
- .deserialize(buf = nil) ⇒ Object
- .extension? ⇒ Boolean
- .ObjectId(s) ⇒ Object
-
.read_bson_document(io) ⇒ ByteBuffer
Reads a single BSON document from an IO object.
- .serialize(obj, check_keys = false, move_id = false) ⇒ Object
Class Method Details
.deserialize(buf = nil) ⇒ Object
8 9 10 |
# File 'lib/bson.rb', line 8 def self.deserialize(buf=nil) BSON_CODER.deserialize(buf) end |
.extension? ⇒ Boolean
28 29 30 31 |
# File 'lib/bson.rb', line 28 def self.extension? !((ENV.key?('BSON_EXT_DISABLED') && RUBY_PLATFORM =~ /java/) || (ENV.key?('BSON_EXT_DISABLED') || "\x01\x00\x00\x00".unpack("i")[0] != 1)) end |
.ObjectId(s) ⇒ Object
7 8 9 |
# File 'lib/bson/types/object_id.rb', line 7 def BSON::ObjectId(s) ObjectId.from_string(s) end |
.read_bson_document(io) ⇒ ByteBuffer
Reads a single BSON document from an IO object. This method is used in the executable b2json, bundled with the bson gem, for reading a file of bson documents.
19 20 21 22 23 24 25 26 |
# File 'lib/bson.rb', line 19 def self.read_bson_document(io) bytebuf = BSON::ByteBuffer.new sz = io.read(4).unpack("V")[0] bytebuf.put_int(sz) bytebuf.put_array(io.read(sz-4).unpack("C*")) bytebuf.rewind return BSON.deserialize(bytebuf) end |
.serialize(obj, check_keys = false, move_id = false) ⇒ Object
4 5 6 |
# File 'lib/bson.rb', line 4 def self.serialize(obj, check_keys=false, move_id=false) BSON_CODER.serialize(obj, check_keys, move_id) end |