Class: BareTypes::Uint

Inherits:
BarePrimitive show all
Defined in:
lib/types.rb

Instance Method Summary collapse

Methods inherited from BarePrimitive

#==, #to_schema

Methods inherited from BaseType

#cycle_search, #initialize

Constructor Details

This class inherits a constructor from BareTypes::BaseType

Instance Method Details

#decode(msg) ⇒ Object



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/types.rb', line 285

def decode(msg)
  ints = msg.unpack("CCCCCCCC")
  relevantInts = []
  i = 0
  while ints[i] & 0b10000000 == 128
    relevantInts << ints[i] % 128
    i += 1
  end
  relevantInts << ints[i]
  sum = 0
  relevantInts.each_with_index do |int, idx|
    sum += int << (idx * 7)
  end
  return sum, msg[(i + 1)..msg.size]
end

#encode(msg, buffer) ⇒ Object

Raises:



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/types.rb', line 268

def encode(msg, buffer)
  bytes = "".b
  _get_next_7_bits_as_byte(msg, 128) do |byte|
    bytes << byte
  end
  (bytes.size - 1).downto(0) do |i|
    if bytes.bytes[i] == 128 && bytes.size > 1
      bytes = bytes.chop
    else
      break
    end
  end
  bytes[bytes.size - 1] = [bytes.bytes[bytes.size - 1] & 127].pack('C')[0]
  raise MaximumSizeError.new("Maximum u/int allowed is 64 bit precision") if bytes.size > 9
  buffer << bytes
end

#finalize_references(schema) ⇒ Object



266
# File 'lib/types.rb', line 266

def finalize_references(schema) end