Class: AceMQ::AMQP::StringCodec
- Inherits:
-
Object
- Object
- AceMQ::AMQP::StringCodec
- Defined in:
- lib/acemq/amqp/codec.rb
Overview
Reads and writes text.
For messages that really are text — a line of a log, a command somebody typed — rather than a structure that happens to be readable. Anything with fields wants JSONCodec.
Constant Summary collapse
- CONTENT_TYPE =
"text/plain; charset=utf-8"
Instance Method Summary collapse
-
#can_decode?(content_type) ⇒ Boolean
Accepts
text/*and nothing else. - #content_type ⇒ Object
- #decode(body) ⇒ String
- #encode(payload) ⇒ String
Instance Method Details
#can_decode?(content_type) ⇒ Boolean
Accepts text/* and nothing else.
Not a message with no content type, unlike JSONCodec: an untyped message is much more likely to be JSON, and a codec that claimed everything untyped would take those away from the codec that can actually read them.
208 209 210 |
# File 'lib/acemq/amqp/codec.rb', line 208 def can_decode?(content_type) content_type.to_s.downcase.start_with?("text/") end |
#content_type ⇒ Object
192 |
# File 'lib/acemq/amqp/codec.rb', line 192 def content_type = CONTENT_TYPE |
#decode(body) ⇒ String
200 |
# File 'lib/acemq/amqp/codec.rb', line 200 def decode(body) = body.to_s |
#encode(payload) ⇒ String
196 |
# File 'lib/acemq/amqp/codec.rb', line 196 def encode(payload) = payload.to_s |