lib/mongo/protocol/msg.rb in mongo-2.12.4 vs lib/mongo/protocol/msg.rb in mongo-2.13.0.beta1

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2017-2019 MongoDB, Inc. +# Copyright (C) 2017-2020 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 # @@ -137,13 +137,11 @@ # @param [ Integer ] max_bson_size The maximum bson object size. # # @return [ BSON::ByteBuffer ] buffer containing the serialized message. # # @since 2.5.0 - def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil) - validate_document_size!(max_bson_size) - + def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil) super add_check_sum(buffer) buffer end @@ -195,19 +193,19 @@ # @param [ Mongo::Client | nil ] client The client used to make the original # command. This client may have auto-encryption options specified. # # @return [ Mongo::Protocol::Msg ] The encrypted message, or the original # message if encryption was not possible or necessary. - def maybe_encrypt(server, client) + def maybe_encrypt(connection, client) # TODO verify compression happens later, i.e. when this method runs # the message is not compressed. if client && client.encrypter && client.encrypter.encrypt? - if server.max_wire_version < 8 + if connection.description.max_wire_version < 8 raise Error::CryptError.new( "Cannot perform encryption against a MongoDB server older than " + "4.2 (wire version less than 8). Currently connected to server " + - "with max wire version #{server.max_wire_version}} " + + "with max wire version #{connection.description.max_wire_version}} " + "(Auto-encryption requires a minimum MongoDB version of 4.2)" ) end db_name = @main_document[DATABASE_IDENTIFIER] @@ -267,26 +265,9 @@ num_inserts > 1 || num_updates > 1 || num_deletes > 1 end private - - # Validate that the documents in this message are all smaller than the - # maxBsonObjectSize. If not, raise an exception. - def validate_document_size!(max_bson_size) - max_bson_size ||= Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE - - contains_too_large_document = @sections.any? do |section| - section[:type] == 1 && - section[:payload][:sequence].any? do |document| - document.to_bson.length > max_bson_size - end - end - - if contains_too_large_document - raise Error::MaxBSONSize.new('The document exceeds maximum allowed BSON object size after serialization') - end - end def command @command ||= if @main_document @main_document.dup.tap do |cmd| @sequences.each do |section|