Class: StompServer::StompFrameRecognizer

### Home Classes Methods

### In Files

- lib/stomp_server/stomp_frame.rb

### Parent

Object

### Methods

- ::new
- #<<
- #parse
- #parse_binary_body
- #parse_body
- #parse_header
- #parse_text_body

### Files

- History.txt
- Manifest.txt
- README.txt
- README.txt

### Class/Module Index

Quicksearch

- StompServer
- StompServer::ActiveRecordQueue
- StompServer::Configurator
- StompServer::DBMQueue
- StompServer::FileQueue
- StompServer::MemoryQueue
- StompServer::Protocols
- StompServer::Protocols::Http
- StompServer::Protocols::Stomp
- StompServer::Queue
- StompServer::QueueManager
- StompServer::QueueMonitor
- StompServer::Run
- StompServer::StompAuth
- StompServer::StompFrame
- StompServer::StompFrameRecognizer
- StompServer::StompId
- StompServer::StompUser
- StompServer::TestServer
- StompServer::TopicManager
- Mongrel
- Mongrel::HttpRequest
- ArMessage

No matching classes.

# StompServer::StompFrameRecognizer

### Attributes

frames[RW]

### Public Class Methods

new() click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 32
    def initialize
      @buffer = ''
      @body_length = nil
      @frame = StompServer::StompFrame.new
      @frames = []
    end

### Public Instance Methods

<<(buf) click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 91
    def<< (buf)
      @buffer << buf
      parse
    end

parse() click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 74
    def parse
      count = @frames.size

      parse_header unless @frame.command
      if @frame.command
        if @body_length
          parse_binary_body
        else
          parse_text_body
        end
      end

      # parse_XXX_body return the frame if they succeed and nil if they fail
      # the result will fall through
      parse if count != @frames.size
    end

parse_binary_body() click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 47
    def parse_binary_body
      if @buffer.length > @body_length
        parse_body(@body_length)
      end
    end

parse_body(len) click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 39
    def parse_body(len)
      raise RuntimeError.new("Invalid stompframe (missing null term)") unless @buffer[len] == 0.chr
      @frame.body = @buffer[0...len]
      @buffer = @buffer[len+1..-1]
      @frames << @frame
      @frame = StompServer::StompFrame.new
    end

parse_header() click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 59
    def parse_header
      if match = @buffer.match(/^\s*(\S+)$\r?\n((?:[ \t]*.*?[ \t]*:[ \t]*.*?[ \t]*$\r?\n)*)\r?\n/)
        @frame.command, headers = match.captures
        @buffer = match.post_match
        headers.split(/\n/).each do |data|
          if data =~ /^\s*(\S+)\s*:\s*(.*?)\s*$/
            @frame.headers[$1] = $2
          end
        end

        # body_length is nil, if there is no content-length, otherwise it is the length (as in integer)
        @body_length = @frame.headers['content-length'] && @frame.headers['content-length'].to_i
      end
    end

parse_text_body() click to toggle source

    # File lib/stomp_server/stomp_frame.rb, line 53
    def parse_text_body
      if pos = @buffer.index(0.chr)
        parse_body(pos)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.