Class: Syncro::Protocol::MessageBuffer

Inherits:
StringIO
  • Object
show all
Defined in:
lib/syncro/protocol/message_buffer.rb

Instance Method Summary collapse

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

#leftObject

How much left to be read



5
6
7
# File 'lib/syncro/protocol/message_buffer.rb', line 5

def left
  size - pos
end

#messagesObject



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 messages
  messages = []
  rewind
  while !eof?
    break unless left > 2
    len = read_I16
    msg = read(len)
    if !msg || msg.length != len
      back(2 + msg.length)
      break
    end
    messages << msg
  end
  trim
  wind
  messages
end

#trimObject



13
14
15
# File 'lib/syncro/protocol/message_buffer.rb', line 13

def trim
  string.replace(read)
end

#windObject



35
36
37
# File 'lib/syncro/protocol/message_buffer.rb', line 35

def wind
  seek(0, IO::SEEK_END)
end