class StompOut::Frame
Container for STOMP frame
Attributes
body[RW]
command[RW]
headers[RW]
Public Class Methods
new(command = nil, headers = nil, body = nil)
click to toggle source
Create Stomp frame
@param [String, NilClass] command name in upper case @param [Hash, NilClass] headers with string header name as key @param [String] body
# File lib/stomp_out/frame.rb, line 34 def initialize(command = nil, headers = nil, body = nil) @command = command @headers = headers || {} @body = body || "" end
Public Instance Methods
require(version, required)
click to toggle source
Verify that required headers are present and then return their values
@param [String] version of STOMP in use @param [Hash] required headers with name as key and list of STOMP versions
to be excluded from the verification as value
@return [Array, Object] values of selected headers in header name sorted order,
or individual header value if only one header required
@raise [ProtocolError] missing header
# File lib/stomp_out/frame.rb, line 58 def require(version, required) values = [] required.keys.sort.each do |header| exclude = required[header] value = @headers[header] raise ProtocolError.new("Missing '#{header}' header", self) if value.nil? && !exclude.include?(version) values << value end values.size > 1 ? values : values.first end
to_s()
click to toggle source
Serialize frame for transmission on wire
@return [String] serialized frame
# File lib/stomp_out/frame.rb, line 43 def to_s @headers["content-length"] = @body.size.to_s if @body.include?(NULL) @headers.keys.sort.inject("#{@command}\n") { |r, key| r << "#{key}:#{@headers[key]}\n" } + "\n#{@body}#{NULL}\n" end