module BSON

A thin wrapper for the BSON C-Extension

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

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.

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

Copyright (C) 2009-2013 MongoDB, 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.

Constants

BSON_CODER
DEFAULT_MAX_BSON_SIZE
NULL_BYTE

Public Class Methods

ObjectId(s) click to toggle source
# File lib/bson/types/object_id.rb, line 20
def BSON::ObjectId(s)
  ObjectId.from_string(s)
end
deserialize(buf=nil, opts={}) click to toggle source
# File lib/bson.rb, line 22
def self.deserialize(buf=nil, opts={})
  BSON_CODER.deserialize(buf, opts)
end
extension?() click to toggle source
# File lib/bson.rb, line 42
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
read_bson_document(io) click to toggle source

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.

@param [IO] io an io object containing a bson object.

@return [ByteBuffer]

# File lib/bson.rb, line 33
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) click to toggle source
# File lib/bson.rb, line 18
def self.serialize(obj, check_keys=false, move_id=false)
  BSON_CODER.serialize(obj, check_keys, move_id)
end