lib/mongo/protocol/serializers.rb in mongo-2.2.7 vs lib/mongo/protocol/serializers.rb in mongo-2.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2014-2015 MongoDB, Inc.
+# Copyright (C) 2014-2016 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
#
@@ -48,11 +48,11 @@
#
# @param buffer [ String ] Buffer to receive the serialized value.
# @param value [ String ] Header value to be serialized.
#
# @return [ String ] Buffer with serialized value.
- def self.serialize(buffer, value)
+ def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
buffer.put_bytes(value.pack(HEADER_PACK))
end
# Deserializes the header value from the IO stream
#
@@ -74,11 +74,11 @@
#
# @param buffer [ String ] Buffer to receive the serialized CString.
# @param value [ String ] The string to be serialized.
#
# @return [ String ] Buffer with serialized value.
- def self.serialize(buffer, value)
+ def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
buffer.put_cstring(value)
end
end
# MongoDB wire protocol serialization strategy for 32-bit Zero.
@@ -90,11 +90,11 @@
#
# @param buffer [ String ] Buffer to receive the serialized Zero.
# @param value [ Fixnum ] Ignored value.
#
# @return [ String ] Buffer with serialized value.
- def self.serialize(buffer, value)
+ def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
buffer.put_int32(ZERO)
end
end
# MongoDB wire protocol serialization strategy for 32-bit integers.
@@ -106,11 +106,11 @@
#
# @param buffer [ String ] Buffer to receive the serialized Int32.
# @param value [ Fixnum ] 32-bit integer to be serialized.
#
# @return [String] Buffer with serialized value.
- def self.serialize(buffer, value)
+ def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
buffer.put_int32(value)
end
# Deserializes a 32-bit Fixnum from the IO stream
#
@@ -131,11 +131,11 @@
#
# @param buffer [ String ] Buffer to receive the serialized Int64.
# @param value [ Fixnum ] 64-bit integer to be serialized.
#
# @return [ String ] Buffer with serialized value.
- def self.serialize(buffer, value)
+ def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
buffer.put_int64(value)
end
# Deserializes a 64-bit Fixnum from the IO stream
#
@@ -156,12 +156,12 @@
#
# @param buffer [ String ] Buffer to receive the BSON encoded document.
# @param value [ Hash ] Document to serialize as BSON.
#
# @return [ String ] Buffer with serialized value.
- def self.serialize(buffer, value, max_bson_size = nil)
+ def self.serialize(buffer, value, max_bson_size = nil, validating_keys = BSON::Config.validating_keys?)
start_size = buffer.length
- value.to_bson(buffer)
+ value.to_bson(buffer, validating_keys)
if max_bson_size && buffer.length - start_size > max_bson_size
raise Error::MaxBSONSize.new(max_bson_size)
end
end