Class: BitcoinCigs::CompactInt
- Inherits:
-
Object
- Object
- BitcoinCigs::CompactInt
- Defined in:
- lib/bitcoin_cigs/compact_int.rb
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(value) ⇒ CompactInt
constructor
A new instance of CompactInt.
Constructor Details
#initialize(value) ⇒ CompactInt
Returns a new instance of CompactInt.
4 5 6 |
# File 'lib/bitcoin_cigs/compact_int.rb', line 4 def initialize(value) @value = value end |
Instance Method Details
#encode ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bitcoin_cigs/compact_int.rb', line 8 def encode() arr = if @value < 253 [@value] elsif @value < (1 << 16) [253, *number_to_bytes(@value, 2)] elsif value < (1 << 32) [254, *number_to_bytes(@value, 4)] else [255, *number_to_bytes(@value, 8)] end arr.pack('C*') end |