Class: AceMQ::AMQP::StringCodec

Inherits:
Object
  • Object
show all
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

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.

Returns:

  • (Boolean)


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

Parameters:

  • body (String)

Returns:

  • (String)


200
# File 'lib/acemq/amqp/codec.rb', line 200

def decode(body) = body.to_s

#encode(payload) ⇒ String

Parameters:

  • payload (Object) —

    anything that answers to_s

Returns:

  • (String)


196
# File 'lib/acemq/amqp/codec.rb', line 196

def encode(payload) = payload.to_s