Class: BigInteger
- Inherits:
-
BinData::BasePrimitive
- Object
- BinData::BasePrimitive
- BigInteger
- Defined in:
- lib/bindata/big_integer.rb
Instance Method Summary collapse
- #read_and_return_value(io) ⇒ Object
- #read_uint8(io) ⇒ Object
- #sensible_default ⇒ Object
- #value_to_binary_string(value) ⇒ Object
Instance Method Details
#read_and_return_value(io) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bindata/big_integer.rb', line 21 def read_and_return_value(io) value = 0 bit_shift = 0 loop do byte = read_uint8(io) has_more = byte & 0x80 seven_bit_byte = byte & 0x7f value |= seven_bit_byte << bit_shift bit_shift += 7 break if has_more.zero? end value end |
#read_uint8(io) ⇒ Object
42 43 44 |
# File 'lib/bindata/big_integer.rb', line 42 def read_uint8(io) io.readbytes(1).unpack("C").at(0) end |
#sensible_default ⇒ Object
38 39 40 |
# File 'lib/bindata/big_integer.rb', line 38 def sensible_default 0 end |
#value_to_binary_string(value) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bindata/big_integer.rb', line 4 def value_to_binary_string(value) value = value.abs bytes = [] loop do seven_bit_byte = value & 0x7f value >>= 7 has_more = value.nonzero? ? 0x80 : 0 byte = has_more | seven_bit_byte bytes.push(byte) break if has_more.zero? end bytes.collect { |b| b.chr }.join end |