Class: AMQ::Protocol::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/amq/protocol/client.rb

Class Method Summary collapse

Class Method Details

.encode_body(body, channel, frame_size) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/amq/protocol/client.rb', line 246

def self.encode_body(body, channel, frame_size)
  return [BodyFrame.new(body, channel)] if body.empty?

  # See https://dev.rabbitmq.com/wiki/Amqp091Errata#section_11
  limit        = frame_size - 8
  limit_plus_1 = limit + 1

  array = Array.new
  while body
    payload, body = body[0, limit_plus_1], body[limit_plus_1, body.length - limit]
    # array << [0x03, payload]
    array << BodyFrame.new(payload, channel)
  end

  array
end

.indexObject



218
219
220
# File 'lib/amq/protocol/client.rb', line 218

def self.index
  @index
end

.inherited(base) ⇒ Object



222
223
224
225
226
# File 'lib/amq/protocol/client.rb', line 222

def self.inherited(base)
  if self == Protocol::Method
    @methods << base
  end
end

.instantiate(*args, &block) ⇒ Object

We can return different:

  • instantiate given subclass of Method

  • create an OpenStruct object

  • create a hash

  • yield params into the block rather than just return



269
270
271
272
273
274
# File 'lib/amq/protocol/client.rb', line 269

def self.instantiate(*args, &block)
  self.new(*args, &block)
  # or OpenStruct.new(args.first)
  # or args.first
  # or block.call(*args)
end

.method_idObject



210
211
212
# File 'lib/amq/protocol/client.rb', line 210

def self.method_id
  @method_id
end

.methodsObject



228
229
230
# File 'lib/amq/protocol/client.rb', line 228

def self.methods
  @methods
end

.nameObject



214
215
216
# File 'lib/amq/protocol/client.rb', line 214

def self.name
  @name
end

.split_headers(user_headers) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/amq/protocol/client.rb', line 232

def self.split_headers(user_headers)
  properties, headers = {}, {}
  user_headers.each do |key, value|
    # key MUST be a symbol since symbols are not garbage-collected
    if Basic::PROPERTIES.include?(key)
      properties[key] = value
    else
      headers[key] = value
    end
  end

  return [properties, headers]
end