mongo-ruby-driver/lib/mongo_bson/bson_c.rb

21 lines
449 B
Ruby
Raw Normal View History

2009-12-01 18:55:04 +00:00
# A thin wrapper for the CBson class
module Mongo
class BSON_C
2009-12-01 18:55:04 +00:00
def self.serialize(obj, check_keys=false, move_id=false)
ByteBuffer.new(CBson.serialize(obj, check_keys, move_id))
end
2009-12-01 18:55:04 +00:00
def self.deserialize(buf=nil)
if buf.is_a? String
to_deserialize = ByteBuffer.new(buf) if buf
else
buf = ByteBuffer.new(buf.to_a) if buf
end
buf.rewind
CBson.deserialize(buf.to_s)
2009-12-01 18:55:04 +00:00
end
end
2009-12-01 18:55:04 +00:00
end