class Aerospike::CDT::Context

Nested CDT context. Identifies the location of nested list/map to apply the operation. for the current level. An array of CTX identifies location of the list/map on multiple levels on nesting.

Attributes

id[RW]
value[RW]

Public Class Methods

base64(ctx) click to toggle source

Encodes the context array to messagepack and then encodes the resulting byte array to base64.

# File lib/aerospike/cdt/context.rb, line 163
def self.base64(ctx)
  unless ctx.to_a.empty?
    data = self.bytes(ctx)
    return Base64.strict_encode64(data).force_encoding("binary")
  end
  ""
end
bytes(ctx) click to toggle source

Encodes the context via message pack and return the results.

# File lib/aerospike/cdt/context.rb, line 126
def self.bytes(ctx)
  unless ctx.to_a.empty?
    Packer.use do |packer|
      packer.write_array_header(ctx.length * 2)
      ctx.each do |c|
        packer.write(c.id)
        Value.of(c.value).pack(packer)
      end
      return packer.bytes
    end
  end
  nil
end
from_base64(buf) click to toggle source

Decodes the byte array to messagepack and then decodes the resulting byte array to an array of Context.

# File lib/aerospike/cdt/context.rb, line 174
def self.from_base64(buf)
  bytes = Base64.strict_decode64(buf)
  self.from_bytes(bytes)
end
from_bytes(buf) click to toggle source

decodes the base64 encoded messagepack byte array and converts it to an array of Context.

# File lib/aerospike/cdt/context.rb, line 147
def self.from_bytes(buf)
  list = nil
  Unpacker.use do |unpacker|
    list = unpacker.unpack(buf)
  end

  unless list.length % 2 == 0
    raise Exceptions::Aerospike.new(Aerospike::ResultCode::PARAMETER_ERROR, "Invalid buffer")
  end

  list.each_slice(2).map { |id, value| Context.new(id, value) }
end
list_index(index) click to toggle source

Lookup list by index offset. If the index is negative, the resolved index starts backwards from end of list. If an index is out of bounds, a parameter error will be returned. Examples: 0: First item. 4: Fifth item. -1: Last item. -3: Third to last item.

# File lib/aerospike/cdt/context.rb, line 53
def self.list_index(index)
  Context.new(0x10, index)
end
list_index_create(index, order, pad) click to toggle source

Create list with given type at index offset, given an order and pad.

# File lib/aerospike/cdt/context.rb, line 40
def self.list_index_create(index, order, pad)
  Context.new(0x10 | ListOrder.flag(order, pad), index)
end
list_rank(rank) click to toggle source

Lookup list by rank. 0 = smallest value N = Nth smallest value -1 = largest value

# File lib/aerospike/cdt/context.rb, line 62
def self.list_rank(rank)
  Context.new(0x11, rank)
end
list_value(key) click to toggle source

Lookup list by value.

# File lib/aerospike/cdt/context.rb, line 68
def self.list_value(key)
  Context.new(0x13, key)
end
map_index(index) click to toggle source

Lookup map by index offset. If the index is negative, the resolved index starts backwards from end of list. If an index is out of bounds, a parameter error will be returned. Examples: 0: First item. 4: Fifth item. -1: Last item. -3: Third to last item.

# File lib/aerospike/cdt/context.rb, line 81
def self.map_index(index)
  Context.new(0x20, index)
end
map_key(key) click to toggle source

Lookup map by key.

# File lib/aerospike/cdt/context.rb, line 96
def self.map_key(key)
  Context.new(0x22, key)
end
map_key_create(key, order) click to toggle source

Create map with given type at map key.

# File lib/aerospike/cdt/context.rb, line 102
def self.map_key_create(key, order)
  Context.new(0x22 | order[:flag], key)
end
map_rank(rank) click to toggle source

Lookup map by rank. 0 = smallest value N = Nth smallest value -1 = largest value

# File lib/aerospike/cdt/context.rb, line 90
def self.map_rank(rank)
  Context.new(0x21, rank)
end
map_value(key) click to toggle source

Lookup map by value.

# File lib/aerospike/cdt/context.rb, line 108
def self.map_value(key)
  Context.new(0x23, key)
end
new(id, value) click to toggle source
# File lib/aerospike/cdt/context.rb, line 33
def initialize(id, value)
  @id = id
  @value = value
end
pack(packer, ctx) click to toggle source

Encodes the context via message pack.

# File lib/aerospike/cdt/context.rb, line 114
def self.pack(packer, ctx)
  unless ctx.to_a.empty?
    packer.write_array_header(2)
    ctx.each do |c|
      packer.write(c.id)
      Value.of(c.value)
    end
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/aerospike/cdt/context.rb, line 140
def ==(other)
  self.id == other.id && self.value == other.value
end