Class: Ciri::Types::UInt
- Inherits:
-
Object
show all
- Defined in:
- lib/ciri/types/uint.rb
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
.size ⇒ Object
Returns the value of attribute size.
31
32
33
|
# File 'lib/ciri/types/uint.rb', line 31
def size
@size
end
|
Class Method Details
.max ⇒ Object
41
42
43
|
# File 'lib/ciri/types/uint.rb', line 41
def max
@max ||= 2 ** size - 1
end
|
.min ⇒ Object
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
49
50
51
|
# File 'lib/ciri/types/uint.rb', line 49
def valid?(n)
n >= 0 && n <= max
end
|
Instance Method Details
#bytes_size ⇒ Object
67
68
69
|
# File 'lib/ciri/types/uint.rb', line 67
def bytes_size
self.class.size
end
|
#serialized ⇒ Object
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_i ⇒ Object
71
72
73
|
# File 'lib/ciri/types/uint.rb', line 71
def to_i
@value
end
|