module Mongo::Protocol::Serializers::Bytes

MongoDB wire protocol serialization strategy for n bytes.

Writes and fetches bytes from the byte buffer.

Public Class Methods

deserialize(buffer, num_bytes = nil) click to toggle source

Deserializes bytes from the byte buffer.

@param [ BSON::ByteBuffer ] buffer Buffer containing the value to read. @param [ Integer ] num_bytes Number of bytes to read.

@return [ String ] The bytes.

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 413
def self.deserialize(buffer, num_bytes = nil)
  buffer.get_bytes(num_bytes || buffer.length)
end
serialize(buffer, value, validating_keys = BSON::Config.validating_keys?) click to toggle source

Writes bytes into the buffer.

@param [ BSON::ByteBuffer ] buffer Buffer to receive the bytes. @param [ String ] value The bytes to write to the buffer. @param [ true, false ] validating_keys Whether to validate keys.

@return [ BSON::ByteBuffer ] Buffer with serialized value.

@since 2.5.0

# File lib/mongo/protocol/serializers.rb, line 401
def self.serialize(buffer, value, validating_keys = BSON::Config.validating_keys?)
  buffer.put_bytes(value)
end