Class | Stomp::Message |
In: |
lib/stomp/message.rb
|
Parent: | Object |
body | [RW] | |
command | [RW] | |
headers | [RW] | |
original | [RW] |
# File lib/stomp/message.rb, line 9 9: def initialize(frame) 10: # p frame 11: # Set default empty values 12: self.command = '' 13: self.headers = {} 14: self.body = '' 15: self.original = frame 16: return self if is_blank?(frame) 17: # Figure out where individual parts of the frame begin and end. 18: command_index = frame.index("\n") 19: raise Stomp::Error::InvalidFormat, 'command index' unless command_index 20: # 21: headers_index = frame.index("\n\n", command_index+1) 22: raise Stomp::Error::InvalidFormat, 'headers index' unless headers_index 23: # 24: lastnull_index = frame.rindex("\0") 25: raise Stomp::Error::InvalidFormat, 'lastnull index' unless lastnull_index 26: 27: # Extract working copies of each frame part 28: work_command = frame[0..command_index-1] 29: raise Stomp::Error::InvalidServerCommand, "invalid command: #{work_command.inspect}" unless @@allowed_commands.include?(work_command) 30: # 31: work_headers = frame[command_index+1..headers_index-1] 32: raise Stomp::Error::InvalidFormat, 'nil headers' unless work_headers 33: # 34: work_body = frame[headers_index+2..lastnull_index-1] 35: raise Stomp::Error::InvalidFormat, 'nil body' unless work_body 36: # Set the frame values 37: self.command = work_command 38: work_headers.split("\n").map do |value| 39: parsed_value = value.match /^([\w|-]*):(.*)$/ 40: raise Stomp::Error::InvalidFormat, 'parsed header value' unless parsed_value 41: self.headers[parsed_value[1].strip] = parsed_value[2].strip if parsed_value 42: end 43: 44: body_length = -1 45: 46: if self.headers['content-length'] 47: body_length = self.headers['content-length'].to_i 48: raise Stomp::Error::InvalidMessageLength if work_body.length != body_length 49: end 50: self.body = work_body[0..body_length] 51: end
# File lib/stomp/message.rb, line 57 57: def empty? 58: is_blank?(command) && is_blank?(headers) && is_blank?(body) 59: end
# File lib/stomp/message.rb, line 53 53: def to_s 54: "<Stomp::Message headers=#{headers.inspect} body='#{body}' command='#{command}' >" 55: end