class CryptoconditionsRuby::Utils::Predictor
Attributes
size[RW]
Public Class Methods
new()
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 4 def initialize @size = 0 end
Public Instance Methods
skip(byte_count)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 39 def skip(byte_count) self.size += byte_count end
write(in_bytes)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 35 def write(in_bytes) self.size += in_bytes.length end
write_octet_string(_value, length)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 22 def write_octet_string(_value, length) skip(length) end
write_uint(_value, length)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 8 def write_uint(_value, length) skip(length) end
write_uint16(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 47 def write_uint16(value) self.write_uint(value, 2) end
write_uint32(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 51 def write_uint32(value) self.write_uint(value, 4) end
write_uint64(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 55 def write_uint64(value) self.write_uint(value, 8) end
write_uint8(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 43 def write_uint8(value) self.write_uint(value, 1) end
write_var_octet_string(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 26 def write_var_octet_string(value) skip(1) if value.length > 127 length_of_length = (sprintf('%02b', value.length).length / 8.0).ceil.to_i skip(length_of_length) end skip(value.length) end
write_var_uint(value)
click to toggle source
# File lib/cryptoconditions_ruby/utils/predictor.rb, line 12 def write_var_uint(value) return write_var_octet_string(value) if value.is_a?(String) raise TypeError.new('UInt must be an integer') unless value.is_a?(Integer) raise TypeError.new('UInt must be positive') unless value > 0 length_of_value = (sprintf('%02b', value).length / 8.0).ceil.to_i buffer = (length_of_value - 1).times.map { 0 }.push(value).pack('C*') write_var_octet_string(buffer) end