123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Defined in: lib/mongo/protocol/serializers.rb

Overview

MongoDB wire protocol serialization strategy for n bytes.

Writes and fetches bytes from the byte buffer.

Class Method Summary

Class Method Details

.deserialize(buffer, options = {}) ⇒ String

Deserializes bytes from the byte buffer.

Parameters:

  • buffer (BSON::ByteBuffer)

    Buffer containing the value to read.

  • options (Hash) (defaults to: {})

    The method options.

Options Hash (options):

  • num_bytes (Integer)

    Number of bytes to read.

Returns:

  • (String)

    The bytes.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 460

def self.deserialize(buffer, options = {})
  num_bytes = options[:num_bytes]
  buffer.get_bytes(num_bytes || buffer.length)
end

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

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: nil)

    Whether to validate keys. This option is deprecated and will not be used. It will removed in version 3.0.

Returns:

  • (BSON::ByteBuffer)

    Buffer with serialized value.

Since:

  • 2.5.0

[ GitHub ]

  
# File 'lib/mongo/protocol/serializers.rb', line 446

def self.serialize(buffer, value, validating_keys = nil)
  buffer.put_bytes(value)
end