Class: Canoser::Cursor
- Inherits:
-
Object
- Object
- Canoser::Cursor
- Defined in:
- lib/canoser/cursor.rb
Instance Method Summary collapse
- #finished? ⇒ Boolean
-
#initialize(bytes, offset = 0) ⇒ Cursor
constructor
A new instance of Cursor.
- #peek_bytes(size) ⇒ Object
- #read_bytes(size) ⇒ Object
Constructor Details
#initialize(bytes, offset = 0) ⇒ Cursor
Returns a new instance of Cursor.
3 4 5 6 |
# File 'lib/canoser/cursor.rb', line 3 def initialize(bytes, offset=0) @bytes = bytes @offset = offset end |
Instance Method Details
#finished? ⇒ Boolean
20 21 22 |
# File 'lib/canoser/cursor.rb', line 20 def finished? @offset == @bytes.size end |
#peek_bytes(size) ⇒ Object
15 16 17 18 |
# File 'lib/canoser/cursor.rb', line 15 def peek_bytes(size) raise ParseError.new("#{@offset+size} exceed bytes size:#{@bytes.size}") if @offset+size > @bytes.size @bytes[@offset, size] end |
#read_bytes(size) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/canoser/cursor.rb', line 8 def read_bytes(size) raise ParseError.new("#{@offset+size} exceed bytes size:#{@bytes.size}") if @offset+size > @bytes.size ret = @bytes[@offset, size] @offset += size ret end |