Class: Aerospike::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/value/value.rb

Overview

Polymorphic value classes used to efficiently serialize objects into the wire protocol.

Class Method Summary collapse

Class Method Details

.of(value, allow_64bits = false) ⇒ Object

:nodoc:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/aerospike/value/value.rb', line 25

def self.of(value, allow_64bits = false)
  case value
  when Integer
    if allow_64bits
      # used in bitwise operations
      if value.bit_length <= 64
        res = IntegerValue.new(value)
      else
        # nums with more than 64 bits are not supported
        raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported with more than 64 bits.")
      end
    else
      if value.bit_length < 64
        res = IntegerValue.new(value)
      else
        # big nums > 2**63 are not supported
        raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported with more than 64 bits.")
      end
    end
  when Float
    res = FloatValue.new(value)
  when String
    res = StringValue.new(value)
  when Symbol
    res = StringValue.new(value.to_s)
  when Value
    res = value
  when Hash
    res = MapValue.new(value)
  when Array
    res = ListValue.new(value)
  when GeoJSON
    res = GeoJSONValue.new(value)
  when nil
    res = NULL
  when TrueClass, FalseClass
    res = BoolValue.new(value)
  else
    # throw an exception for anything that is not supported.
    raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported.")
  end

  res
end

.validate_hash_key(value) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/aerospike/value/value.rb', line 70

def self.validate_hash_key(value)
  case value
  when Integer
    if value.bit_length >= 64
      raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
    end
  when Float
  when String
  when Symbol
  when nil
  else
    # throw an exception for anything that is not supported.
    raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::TYPE_NOT_SUPPORTED, "Value type #{value.class} not supported as hash key.")
  end
end