Module: Stomper::Support::Ruby1_8::FrameSerializer
- Defined in:
- lib/stomper/support/1.8/frame_serializer.rb
Overview
Implementation of FrameSerializer methods for Ruby 1.8.7
Instance Method Summary collapse
-
#determine_content_length(frame) ⇒ Fixnum
Determines the content-length of a frame being sent to a broker.
-
#determine_content_type(frame) ⇒ String
Determines the content-type of a frame being sent to a broker.
-
#encode_body(body, ct_header) ⇒ String
Return the body with the specified encoding applied.
-
#get_body_byte ⇒ String?
Reads a single byte from the body portion of a frame.
-
#get_header_line ⇒ String
Reads a line of text from the underlying IO.
Instance Method Details
#determine_content_length(frame) ⇒ Fixnum
Determines the content-length of a frame being sent to a broker. For Ruby 1.8.7, this is just the size
of the frame’s body.
41 42 43 |
# File 'lib/stomper/support/1.8/frame_serializer.rb', line 41 def determine_content_length(frame) frame.body.size end |
#determine_content_type(frame) ⇒ String
Determines the content-type of a frame being sent to a broker. This version of the method is used by Ruby 1.8.7, which lacks native string encoding support. If the content-type matches ‘text/*’, and no charset parameter is set, a charset of UTF-8 will be assumed. In all other cases, the ‘content-type’ header is used directly.
29 30 31 32 33 34 35 36 |
# File 'lib/stomper/support/1.8/frame_serializer.rb', line 29 def determine_content_type(frame) ct = frame[:'content-type'] if ct =~ /^text\//i && !(ct =~ /\;\s*charset=\"?[a-zA-Z0-9!\#$&.+\-^_]+\"?/i) "#{ct};charset=UTF-8" else ct end end |
#encode_body(body, ct_header) ⇒ String
Return the body with the specified encoding applied. Ruby 1.8 does not have a native awareness of string encodings. As such, this method does not change the body in any way.
11 12 13 |
# File 'lib/stomper/support/1.8/frame_serializer.rb', line 11 def encode_body(body, ct_header) body end |
#get_body_byte ⇒ String?
Reads a single byte from the body portion of a frame. Returns nil
if the character read is a frame terminator.
18 19 20 21 |
# File 'lib/stomper/support/1.8/frame_serializer.rb', line 18 def get_body_byte c = @io.getc.chr c == ::Stomper::FrameSerializer::FRAME_TERMINATOR ? nil : c end |
#get_header_line ⇒ String
Reads a line of text from the underlying IO. As per the Stomp 1.1 specification, all header strings are encoded with UTF-8.
48 49 50 |
# File 'lib/stomper/support/1.8/frame_serializer.rb', line 48 def get_header_line @io.gets || '' end |