Class: Couchbase::TranscoderFlags Private

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/transcoder_flags.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.

API:

  • private

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.

API:

  • private

{
  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.

API:

  • private

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.

API:

  • private

{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.

API:

  • private

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.

API:

  • private



36
37
38
39
40
# File 'lib/couchbase/transcoder_flags.rb', line 36

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

Instance Attribute Details

#compression ⇒ Object (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.

API:

  • private



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

def compression
  @compression
end

#format ⇒ Object (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.

API:

  • private



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

def format
  @format
end

#lower_bits ⇒ Object (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.

API:

  • private



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

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.

API:

  • private



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

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

#encode ⇒ 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.

API:

  • private



59
60
61
62
# File 'lib/couchbase/transcoder_flags.rb', line 59

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