class ObjectFramework::Protobuf::Wire::Cursor
Attributes
Public Class Methods
Source
# File lib/object_framework/protobuf.rb, line 30 def initialize(bytes); @bytes, @position = bytes.b, 0; end
Public Instance Methods
Source
# File lib/object_framework/protobuf.rb, line 31 def done?; @position == @bytes.bytesize; end
Source
# File lib/object_framework/protobuf.rb, line 51 def skip(wire) case wire when 0 then varint when 1 then take(8) when 2 then take(varint) when 5 then take(4) else raise InvalidInput, "Unsupported protobuf wire type" end end
Source
# File lib/object_framework/protobuf.rb, line 33 def take(count) raise InvalidInput, "Truncated protobuf field" if count.negative? || @position + count > @bytes.bytesize result = @bytes.byteslice(@position, count) @position += count result end
Source
# File lib/object_framework/protobuf.rb, line 40 def varint result = 0 10.times do |index| byte = take(1).getbyte(0) raise InvalidInput, "Varint overflow" if index == 9 && byte > 1 result |= (byte & 127) << (index * 7) return result if byte < 128 end raise InvalidInput, "Varint overflow" end