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



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/amq/protocol/client.rb', line 252

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

  # 8 = 1 + 2 + 4 + 1
  # 1 byte of frame type
  # 2 bytes of channel number
  # 4 bytes of frame payload length
  # 1 byte of payload trailer FRAME_END byte
  limit        = frame_size - 8

  # Otherwise String#slice on 1.9 will operate with code points,
  # and we need bytes. MK.
  body.force_encoding("ASCII-8BIT") if RUBY_VERSION.to_f >= 1.9

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

  array
end

.indexObject



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

def self.index
  @index
end

.inherited(base) ⇒ Object



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

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



282
283
284
285
286
287
# File 'lib/amq/protocol/client.rb', line 282

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

.method_idObject



216
217
218
# File 'lib/amq/protocol/client.rb', line 216

def self.method_id
  @method_id
end

.methodsObject



234
235
236
# File 'lib/amq/protocol/client.rb', line 234

def self.methods
  @methods
end

.nameObject



220
221
222
# File 'lib/amq/protocol/client.rb', line 220

def self.name
  @name
end

.split_headers(user_headers) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/amq/protocol/client.rb', line 238

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