Module: BSON
- Defined in:
- lib/bson/bson_c.rb,
lib/bson.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/min_max_keys.rb
Overview
– Copyright © 2008-2011 10gen Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ++
Defined Under Namespace
Classes: BSONError, BSON_C, BSON_JAVA, BSON_RUBY, Binary, ByteBuffer, Code, DBRef, InvalidDocument, InvalidKeyName, InvalidObjectID, InvalidObjectId, InvalidStringEncoding, MaxKey, MinKey, MongoDBError, MongoRubyError, ObjectId, OrderedHash
Constant Summary collapse
- VERSION =
"1.2.0"
- DEFAULT_MAX_BSON_SIZE =
4 * 1024 * 1024
- BSON_CODER =
BSON_JAVA
Class Method Summary collapse
- .deserialize(buf = nil) ⇒ Object
- .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
36 37 38 |
# File 'lib/bson.rb', line 36 def self.deserialize(buf=nil) BSON_CODER.deserialize(buf) end |
.ObjectId(s) ⇒ Object
25 26 27 |
# File 'lib/bson/types/object_id.rb', line 25 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.
47 48 49 50 51 52 53 54 |
# File 'lib/bson.rb', line 47 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
32 33 34 |
# File 'lib/bson.rb', line 32 def self.serialize(obj, check_keys=false, move_id=false) BSON_CODER.serialize(obj, check_keys, move_id) end |