class BareTypes::Int
Public Instance Methods
decode(msg)
click to toggle source
# File lib/types.rb, line 36 def decode(msg) value, rest = Uint.new.decode(msg) value = value.odd? ? (value + 1) / -2 : value / 2 return value, rest end
encode(msg)
click to toggle source
developers.google.com/protocol-buffers/docs/encoding Easy to just convert to signed and re-use uint code
# File lib/types.rb, line 31 def encode(msg) mappedInteger = msg < 0 ? -2 * msg - 1 : msg * 2 return Uint.new.encode(mappedInteger) end