Class: Bones::RPC::Parser::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/bones/rpc/parser/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ioObject (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

#getcObject



13
14
15
# File 'lib/bones/rpc/parser/buffer.rb', line 13

def getc
  io.getc
end

#posObject



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

#rewindObject



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

#sizeObject



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_strObject



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

#transactionObject



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