Class: Mongo::Protocol::Serializers::BitVector Private
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/mongo/protocol/bit_vector.rb |
Overview
Class used to define a bitvector for a MongoDB wire protocol message.
Defines serialization strategy upon initialization.
Class Method Summary
-
.new(layout) ⇒ BitVector
constructor
Internal use only
Initializes a
BitVector
with a layout.
Instance Method Summary
-
#deserialize(buffer, options = {}) ⇒ Array<Symbol>
Internal use only
Deserializes vector by decoding the symbol according to its mask.
-
#serialize(buffer, value, validating_keys = nil) ⇒ String
Internal use only
Serializes vector by encoding each symbol according to its mask.
Instance Method Details
#deserialize(buffer, options = {}) ⇒ Array
<Symbol>
Deserializes vector by decoding the symbol according to its mask
# File 'lib/mongo/protocol/bit_vector.rb', line 58
def deserialize(buffer, = {}) vector = buffer.get_int32 flags = [] @masks.each do |flag, mask| flags << flag if mask & vector != 0 end flags end
#serialize(buffer, value, validating_keys = nil) ⇒ String
Serializes vector by encoding each symbol according to its mask
# File 'lib/mongo/protocol/bit_vector.rb', line 46
def serialize(buffer, value, validating_keys = nil) bits = 0 value.each { |flag| bits |= (@masks[flag] || 0) } buffer.put_int32(bits) end