Class: Syncro::Protocol::MessageBuffer
- Inherits:
-
StringIO
- Object
- StringIO
- Syncro::Protocol::MessageBuffer
- Defined in:
- lib/syncro/protocol/message_buffer.rb
Instance Method Summary collapse
- #back(n) ⇒ Object
-
#left ⇒ Object
How much left to be read.
- #messages ⇒ Object
- #trim ⇒ Object
- #wind ⇒ Object
Instance Method Details
#back(n) ⇒ Object
9 10 11 |
# File 'lib/syncro/protocol/message_buffer.rb', line 9 def back(n) seek(n * -1, IO::SEEK_CUR) end |
#left ⇒ Object
How much left to be read
5 6 7 |
# File 'lib/syncro/protocol/message_buffer.rb', line 5 def left size - pos end |
#messages ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/syncro/protocol/message_buffer.rb', line 17 def = [] rewind while !eof? break unless left > 2 len = read_I16 msg = read(len) if !msg || msg.length != len back(2 + msg.length) break end << msg end trim wind end |
#trim ⇒ Object
13 14 15 |
# File 'lib/syncro/protocol/message_buffer.rb', line 13 def trim string.replace(read) end |
#wind ⇒ Object
35 36 37 |
# File 'lib/syncro/protocol/message_buffer.rb', line 35 def wind seek(0, IO::SEEK_END) end |