Class: Mongo::Protocol::Serializers::BitVector Private
- Inherits:
-
Object
- Object
- Mongo::Protocol::Serializers::BitVector
- Defined in:
- lib/mongo/protocol/bit_vector.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Class used to define a bitvector for a MongoDB wire protocol message.
Defines serialization strategy upon initialization.
Instance Method Summary collapse
-
#deserialize(buffer) ⇒ Array<Symbol>
private
Deserializes vector by decoding the symbol according to its mask.
-
#initialize(layout) ⇒ BitVector
constructor
private
Initializes a BitVector with a layout.
-
#serialize(buffer, value) ⇒ String
private
Serializes vector by encoding each symbol according to its mask.
Constructor Details
#initialize(layout) ⇒ BitVector
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.
Initializes a BitVector with a layout
28 29 30 31 32 33 |
# File 'lib/mongo/protocol/bit_vector.rb', line 28 def initialize(layout) @masks = {} layout.each_with_index do |field, index| @masks[field] = 2**index end end |
Instance Method Details
#deserialize(buffer) ⇒ Array<Symbol>
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 vector by decoding the symbol according to its mask
52 53 54 55 56 57 58 59 |
# File 'lib/mongo/protocol/bit_vector.rb', line 52 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) ⇒ 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.
Serializes vector by encoding each symbol according to its mask
41 42 43 44 45 |
# File 'lib/mongo/protocol/bit_vector.rb', line 41 def serialize(buffer, value) bits = 0 value.each { |flag| bits |= @masks[flag] } buffer.put_int32(bits) end |