Module: Mongo::Protocol::Serializers::Bytes Private

Defined in:
lib/mongo/protocol/serializers.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

MongoDB wire protocol serialization strategy for n bytes.

Writes and fetches bytes from the byte buffer.

Class Method Summary collapse

Class Method Details

.deserialize(buffer, num_bytes = nil) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deserializes bytes from the byte buffer.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer containing the value to read.

  • num_bytes (Integer) (defaults to: nil)

    Number of bytes to read.

Returns:

  • (String)

    The bytes.

Since:

  • 2.5.0



407
408
409
# File 'lib/mongo/protocol/serializers.rb', line 407

def self.deserialize(buffer, num_bytes = nil)
  buffer.get_bytes(num_bytes || buffer.length)
end

.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?) ⇒ BSON::ByteBuffer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Writes bytes into the buffer.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer to receive the bytes.

  • value (String)

    The bytes to write to the buffer.

  • validating_keys (true, false) (defaults to: BSON::Config.validating_keys?)

    Whether to validate keys.

Returns:

  • (BSON::ByteBuffer)

    Buffer with serialized value.

Since:

  • 2.5.0



395
396
397
# File 'lib/mongo/protocol/serializers.rb', line 395

def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
  buffer.put_bytes(value)
end