Class: Hyperll::Varint
- Inherits:
-
Object
- Object
- Hyperll::Varint
- Defined in:
- lib/hyperll/varint.rb
Class Method Summary collapse
Class Method Details
.read_unsigned_var_int(bytes) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/hyperll/varint.rb', line 3 def self.read_unsigned_var_int(bytes) value, i, b = 0, 0, 0 while (b = bytes.shift) & 0x80 != 0 value |= (b & 0x7F) << i i += 7 raise "Variable length quantity is too long" if i > 35 end value | (b << i) end |
.write_unsigned_var_int(value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hyperll/varint.rb', line 15 def self.write_unsigned_var_int(value) bytes = [] while (value & 0xFFFFFF80) != 0 bytes << ((value & 0x7F) | 0x80) value >>= 7 end bytes << (value & 0x7F) bytes end |