Class: StompServer::StompFrameRecognizer
- Inherits:
-
Object
- Object
- StompServer::StompFrameRecognizer
- Defined in:
- lib/stomp_server_ng/stomp_frame_recognizer.rb
Instance Attribute Summary collapse
-
#frames ⇒ Object
Returns the value of attribute frames.
Instance Method Summary collapse
- #<<(buf) ⇒ Object
-
#initialize ⇒ StompFrameRecognizer
constructor
A new instance of StompFrameRecognizer.
- #parse ⇒ Object
- #parse_binary_body ⇒ Object
- #parse_body(len) ⇒ Object
- #parse_header ⇒ Object
- #parse_text_body ⇒ Object
Constructor Details
#initialize ⇒ StompFrameRecognizer
Returns a new instance of StompFrameRecognizer.
6 7 8 9 10 11 12 13 14 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 6 def initialize @buffer = '' @body_length = nil @frame = StompServer::StompFrame.new @frames = [] # @@log = Logger.new(STDOUT) @@log.level = StompServer::LogHelper.get_loglevel end |
Instance Attribute Details
#frames ⇒ Object
Returns the value of attribute frames.
4 5 6 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 4 def frames @frames end |
Instance Method Details
#<<(buf) ⇒ Object
71 72 73 74 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 71 def<< (buf) @buffer << buf parse end |
#parse ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 54 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 ⇒ Object
25 26 27 28 29 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 25 def parse_binary_body if @buffer.length > @body_length parse_body(@body_length) end end |
#parse_body(len) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 16 def parse_body(len) # 1.8 / 1.9 compat raise RuntimeError.new("Invalid stompframe (missing null term)") unless @buffer[len].to_i == 0 @frame.body = @buffer[0...len] @buffer = @buffer[len+1..-1] @frames << @frame @frame = StompServer::StompFrame.new end |
#parse_header ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 39 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 ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/stomp_server_ng/stomp_frame_recognizer.rb', line 31 def parse_text_body @@log.debug("StompFrameRecognizer parse_text_body starts") pos = @buffer.index(0.chr) # 1.8 / 1.9 compat if pos parse_body(pos) end end |