File: frame.rb [amq-client-1.0.2 Documentation]

Last Modified
  2014-03-02 20:19:47 +0000
Requires
  - amq/client/exceptions

## Description

This will be probably used by all the async libraries like EventMachine. It expects the whole frame as one string, so if library of your choice gives you input chunk-by-chunk, you'll need to have something like this:

class Client

    include EventMachine::Deferrable

    def receive_data(chunk)
      if @payload.nil?
        self.decode_from_string(chunk[0..6])
        @payload = ""
      elsif @payload && chunk[-1] != FINAL_OCTET
        @payload += chunk
        @size += chunk.bytesize
      else
        check_size(@size, @payload.bytesize)
        Frame.decode(@payload) # we need the whole payload
        @size, @payload = nil
      end
    end

    NOTE: the client should also implement waiting for another frames, in case that some header/body frames are expected.

end