Module: IProto::EMConnection::FixedLengthProtocol

Included in:
IProto::EMConnection
Defined in:
lib/iproto/em.rb

Instance Method Summary collapse

Instance Method Details

#buffer_resetObject



30
31
32
# File 'lib/iproto/em.rb', line 30

def buffer_reset
  @buffer = ''.b
end

#post_initObject



8
9
10
# File 'lib/iproto/em.rb', line 8

def post_init
  raise "you should set @_needed_size"  unless @_needed_size
end

#receive_chunk(chunk) ⇒ Object



26
27
28
# File 'lib/iproto/em.rb', line 26

def receive_chunk(chunk)
  # for override
end

#receive_data(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/iproto/em.rb', line 12

def receive_data(data)
  @buffer ||= ''.b
  offset = 0
  while (chunk = data.byteslice(offset, _needed_size - @buffer.bytesize)).size > 0
    @buffer << chunk
    offset += chunk.size
    if @buffer.size == _needed_size
      chunk = @buffer
      @buffer = ''.b
      receive_chunk chunk
    end
  end 
end