def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
      if Environment.ruby_1_9?
        marshal_dump.dup
      else
        to_h
      end.to_bson(buffer, validating_keys)
    end
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
      if Environment.ruby_1_9?
        marshal_dump.dup
      else
        to_h
      end.to_bson(buffer, validating_keys)
    end
Get the OpenStruct as encoded BSON.

 @example Get the OpenStruct object as encoded BSON.
   OpenStruct.new({ "field" => "value" }).to_bson

 @return [ BSON::ByteBuffer ] The buffer with the encoded object.

 @see http://bsonspec.org/#/specification

 @since 4.2.0