Class: Ciri::Types::UInt

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/types/uint.rb

Direct Known Subclasses

Int24, Int256, UInt256, UInt32, UInt8

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ UInt

Returns a new instance of UInt.



56
57
58
59
# File 'lib/ciri/types/uint.rb', line 56

def initialize(value)
  raise "can't initialize size #{self.class.size} number" if self.class.size <= 0
  @value = value
end

Class Attribute Details

.sizeObject (readonly)

Returns the value of attribute size.



31
32
33
# File 'lib/ciri/types/uint.rb', line 31

def size
  @size
end

Class Method Details

.maxObject



41
42
43
# File 'lib/ciri/types/uint.rb', line 41

def max
  @max ||= 2 ** size - 1
end

.minObject



45
46
47
# File 'lib/ciri/types/uint.rb', line 45

def min
  0
end

.rlp_decode(encoded) ⇒ Object



37
38
39
# File 'lib/ciri/types/uint.rb', line 37

def rlp_decode(encoded)
  Utils.big_endian_decode(RLP.decode(encoded))
end

.rlp_encode(item) ⇒ Object



33
34
35
# File 'lib/ciri/types/uint.rb', line 33

def rlp_encode(item)
  RLP.encode new(item).to_bytes
end

.valid?(n) ⇒ Boolean

Returns:



49
50
51
# File 'lib/ciri/types/uint.rb', line 49

def valid?(n)
  n >= 0 && n <= max
end

Instance Method Details

#bytes_sizeObject



67
68
69
# File 'lib/ciri/types/uint.rb', line 67

def bytes_size
  self.class.size
end

#serializedObject Also known as: to_bytes



61
62
63
# File 'lib/ciri/types/uint.rb', line 61

def serialized
  Utils.big_endian_encode(@value, size: bytes_size)
end

#to_iObject



71
72
73
# File 'lib/ciri/types/uint.rb', line 71

def to_i
  @value
end