Class: LimitedIO
- Inherits:
-
Struct
- Object
- Struct
- LimitedIO
- Defined in:
- lib/protocol_buffers/limited_io.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit
1 2 3 |
# File 'lib/protocol_buffers/limited_io.rb', line 1 def limit @limit end |
#parent ⇒ Object
Returns the value of attribute parent
1 2 3 |
# File 'lib/protocol_buffers/limited_io.rb', line 1 def parent @parent end |
Instance Method Details
#eof? ⇒ Boolean
17 18 19 |
# File 'lib/protocol_buffers/limited_io.rb', line 17 def eof? limit == 0 || parent.eof? end |
#getbyte ⇒ Object
21 22 23 24 25 |
# File 'lib/protocol_buffers/limited_io.rb', line 21 def getbyte return nil if limit == 0 self.limit -= 1 parent.getbyte end |
#getc ⇒ Object
27 28 29 30 31 |
# File 'lib/protocol_buffers/limited_io.rb', line 27 def getc return nil if limit == 0 self.limit -= 1 parent.getc end |
#read(length = nil, buffer = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/protocol_buffers/limited_io.rb', line 3 def read(length = nil, buffer = nil) length = length || limit length = limit if length > limit self.limit -= length # seems silly to check for buffer, but some IO#read methods implemented in C # barf if you pass nil, rather than treat it as an argument that wasn't # passed at all. if buffer parent.read(length, buffer) else parent.read(length) end end |