Class: AceMQ::AMQP::BytesCodec

Inherits:
Object
  • Object
show all
Defined in:
lib/acemq/amqp/codec.rb

Overview

Passes bodies through untouched.

For a payload that is already encoded — an image, something another system's serialiser produced — and for reading a message this process has no type for. Replaying a dead-lettered message wants it too: the bytes that were committed are the bytes that should go back, and re-encoding through a class that has since gained a field would produce something else.

It answers for every content type, which is exactly why it has to be asked for by name rather than found by one.

Constant Summary collapse

CONTENT_TYPE =
"application/octet-stream"

Instance Method Summary collapse

Instance Method Details

#can_decode?(_content_type) ⇒ Boolean

True for anything, including a message with no content type.

Returns:

  • (Boolean)


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

def can_decode?(_content_type) = true

#content_type ⇒ Object



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

def content_type = CONTENT_TYPE

#decode(body) ⇒ String

Returns the bytes, unchanged.

Parameters:

  • body (String)

Returns:

  • (String) —

    the bytes, unchanged



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

def decode(body) = body.to_s

#encode(payload) ⇒ String

Parameters:

  • payload (String, nil)

Returns:

  • (String)

Raises:



169
170
171
172
173
174
# File 'lib/acemq/amqp/codec.rb', line 169

def encode(payload)
  return "" if payload.nil?
  return payload if payload.is_a?(String)

  raise EncodeError, "BytesCodec takes a String, not a #{payload.class}"
end