Class: Couchbase::TranscoderFlags Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/transcoder_flags.rb

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.

Constant Summary collapse

FORMAT_MAP =

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

{
  reserved: 0,
  private: 1,
  json: 2,
  binary: 3,
  string: 4,
}.freeze
INV_FORMAT_MAP =

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

FORMAT_MAP.invert.freeze
COMPRESSION_MAP =

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

{none: 0}.freeze
INV_COMPRESSION_MAP =

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

COMPRESSION_MAP.invert

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format:, compression: :none, lower_bits: 0) ⇒ TranscoderFlags

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.

Returns a new instance of TranscoderFlags.



34
35
36
37
38
# File 'lib/couchbase/transcoder_flags.rb', line 34

def initialize(format:, compression: :none, lower_bits: 0)
  @format = format
  @compression = compression
  @lower_bits = lower_bits
end

Instance Attribute Details

#compressionObject (readonly)

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.



31
32
33
# File 'lib/couchbase/transcoder_flags.rb', line 31

def compression
  @compression
end

#formatObject (readonly)

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.



30
31
32
# File 'lib/couchbase/transcoder_flags.rb', line 30

def format
  @format
end

#lower_bitsObject (readonly)

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.



32
33
34
# File 'lib/couchbase/transcoder_flags.rb', line 32

def lower_bits
  @lower_bits
end

Class Method Details

.decode(flags) ⇒ Object

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.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/couchbase/transcoder_flags.rb', line 40

def self.decode(flags)
  return TranscoderFlags.new(format: flags) if flags.is_a?(Symbol)

  common_flags = flags >> 24
  lower_bits = flags & 0x00ffff

  return TranscoderFlags.new(format: nil, lower_bits: lower_bits) if common_flags.zero?

  compression_bits = common_flags >> 5
  format_bits = common_flags & 0x0f
  TranscoderFlags.new(
    format: INV_FORMAT_MAP[format_bits],
    compression: INV_COMPRESSION_MAP[compression_bits],
    lower_bits: lower_bits
  )
end

Instance Method Details

#encodeObject

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.



57
58
59
60
# File 'lib/couchbase/transcoder_flags.rb', line 57

def encode
  common_flags = (COMPRESSION_MAP[@compression] << 5) | FORMAT_MAP[@format]
  (common_flags << 24) | @lower_bits
end