Class: Ciri::Types::UInt
- Inherits:
-
Object
- Object
- Ciri::Types::UInt
- Defined in:
- lib/ciri/types/uint.rb
Class Attribute Summary collapse
-
.size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
- .max ⇒ Object
- .min ⇒ Object
- .rlp_decode(encoded) ⇒ Object
- .rlp_encode(item) ⇒ Object
- .valid?(n) ⇒ Boolean
Instance Method Summary collapse
- #bytes_size ⇒ Object
-
#initialize(value) ⇒ UInt
constructor
A new instance of UInt.
- #serialized ⇒ Object (also: #to_bytes)
- #to_i ⇒ Object
Constructor Details
#initialize(value) ⇒ UInt
Returns a new instance of UInt.
50 51 52 53 |
# File 'lib/ciri/types/uint.rb', line 50 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 (readonly)
Returns the value of attribute size.
25 26 27 |
# File 'lib/ciri/types/uint.rb', line 25 def size @size end |
Class Method Details
.max ⇒ Object
35 36 37 |
# File 'lib/ciri/types/uint.rb', line 35 def max @max ||= 2 ** size - 1 end |
.min ⇒ Object
39 40 41 |
# File 'lib/ciri/types/uint.rb', line 39 def min 0 end |
.rlp_decode(encoded) ⇒ Object
31 32 33 |
# File 'lib/ciri/types/uint.rb', line 31 def rlp_decode(encoded) Utils.big_endian_decode(RLP.decode(encoded)) end |
.rlp_encode(item) ⇒ Object
27 28 29 |
# File 'lib/ciri/types/uint.rb', line 27 def rlp_encode(item) RLP.encode new(item).to_bytes end |
.valid?(n) ⇒ Boolean
43 44 45 |
# File 'lib/ciri/types/uint.rb', line 43 def valid?(n) n >= 0 && n <= max end |
Instance Method Details
#bytes_size ⇒ Object
61 62 63 |
# File 'lib/ciri/types/uint.rb', line 61 def bytes_size self.class.size end |
#serialized ⇒ Object Also known as: to_bytes
55 56 57 |
# File 'lib/ciri/types/uint.rb', line 55 def serialized Utils.big_endian_encode(@value, size: bytes_size) end |
#to_i ⇒ Object
65 66 67 |
# File 'lib/ciri/types/uint.rb', line 65 def to_i @value end |