Class: Bones::RPC::Parser::Buffer
- Inherits:
-
Object
- Object
- Bones::RPC::Parser::Buffer
- Defined in:
- lib/bones/rpc/parser/buffer.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #getc ⇒ Object
-
#initialize(data) ⇒ Buffer
constructor
A new instance of Buffer.
- #pos ⇒ Object
- #read(n) ⇒ Object
- #rewind ⇒ Object
- #seek(pos) ⇒ Object
- #size ⇒ Object
- #skip(n) ⇒ Object
- #sync(*others) ⇒ Object
- #to_str ⇒ Object
- #transaction ⇒ Object
- #ungetc(c) ⇒ Object
Constructor Details
#initialize(data) ⇒ Buffer
Returns a new instance of Buffer.
9 10 11 |
# File 'lib/bones/rpc/parser/buffer.rb', line 9 def initialize(data) @io = StringIO.new(data) end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
7 8 9 |
# File 'lib/bones/rpc/parser/buffer.rb', line 7 def io @io end |
Instance Method Details
#getc ⇒ Object
13 14 15 |
# File 'lib/bones/rpc/parser/buffer.rb', line 13 def getc io.getc end |
#pos ⇒ Object
17 18 19 |
# File 'lib/bones/rpc/parser/buffer.rb', line 17 def pos io.pos end |
#read(n) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bones/rpc/parser/buffer.rb', line 21 def read(n) i = pos data = io.read(n) if data.bytesize < n seek(i) raise EOFError else data end end |
#rewind ⇒ Object
32 33 34 |
# File 'lib/bones/rpc/parser/buffer.rb', line 32 def rewind io.rewind end |
#seek(pos) ⇒ Object
36 37 38 |
# File 'lib/bones/rpc/parser/buffer.rb', line 36 def seek(pos) io.seek(pos) end |
#size ⇒ Object
40 41 42 |
# File 'lib/bones/rpc/parser/buffer.rb', line 40 def size io.size end |
#skip(n) ⇒ Object
44 45 46 |
# File 'lib/bones/rpc/parser/buffer.rb', line 44 def skip(n) seek(pos + n) end |
#sync(*others) ⇒ Object
48 49 50 51 52 |
# File 'lib/bones/rpc/parser/buffer.rb', line 48 def sync(*others) yield ensure others.each { |other| other.seek(pos) } end |
#to_str ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/bones/rpc/parser/buffer.rb', line 54 def to_str i = pos begin io.read || "" ensure seek(i) end end |
#transaction ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/bones/rpc/parser/buffer.rb', line 63 def transaction i = pos begin yield rescue EOFError => e seek(i) raise e end end |
#ungetc(c) ⇒ Object
73 74 75 |
# File 'lib/bones/rpc/parser/buffer.rb', line 73 def ungetc(c) io.ungetc(c) end |