Class: AMQ::Protocol::Basic
Defined Under Namespace
Classes: Ack, Cancel, CancelOk, Consume, ConsumeOk, Deliver, Get, GetEmpty, GetOk, Nack, Publish, Qos, QosOk, Recover, RecoverAsync, RecoverOk, Reject, Return
Constant Summary collapse
- PROPERTIES =
[ :content_type, # shortstr :content_encoding, # shortstr :headers, # table :delivery_mode, # octet :priority, # octet :correlation_id, # shortstr :reply_to, # shortstr :expiration, # shortstr :message_id, # shortstr :timestamp, # timestamp :type, # shortstr :user_id, # shortstr :app_id, # shortstr :cluster_id, # shortstr ]
- DECODE_PROPERTIES =
THIS DECODES ONLY FLAGS
{ 0x8000 => :content_type, 0x4000 => :content_encoding, 0x2000 => :headers, 0x1000 => :delivery_mode, 0x0800 => :priority, 0x0400 => :correlation_id, 0x0200 => :reply_to, 0x0100 => :expiration, 0x0080 => :message_id, 0x0040 => :timestamp, 0x0020 => :type, 0x0010 => :user_id, 0x0008 => :app_id, 0x0004 => :cluster_id, }
- DECODE_PROPERTIES_TYPE =
{ 0x8000 => :shortstr, 0x4000 => :shortstr, 0x2000 => :table, 0x1000 => :octet, 0x0800 => :octet, 0x0400 => :shortstr, 0x0200 => :shortstr, 0x0100 => :shortstr, 0x0080 => :shortstr, 0x0040 => :timestamp, 0x0020 => :shortstr, 0x0010 => :shortstr, 0x0008 => :shortstr, 0x0004 => :shortstr, }
- DECODE_PROPERTIES_KEYS =
Hash doesn“t give any guarantees on keys order, we will do it in a straightforward way
[ 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, ]
Class Method Summary collapse
- .decode_properties(data) ⇒ Object
-
.encode_app_id(value) ⇒ Object
1 << 3.
-
.encode_cluster_id(value) ⇒ Object
1 << 2.
-
.encode_content_encoding(value) ⇒ Object
1 << 14.
-
.encode_content_type(value) ⇒ Object
1 << 15.
-
.encode_correlation_id(value) ⇒ Object
1 << 10.
-
.encode_delivery_mode(value) ⇒ Object
1 << 12.
-
.encode_expiration(value) ⇒ Object
1 << 8.
-
.encode_headers(value) ⇒ Object
1 << 13.
-
.encode_message_id(value) ⇒ Object
1 << 7.
-
.encode_priority(value) ⇒ Object
1 << 11.
- .encode_properties(body_size, properties) ⇒ Object
-
.encode_reply_to(value) ⇒ Object
1 << 9.
-
.encode_timestamp(value) ⇒ Object
1 << 6.
-
.encode_type(value) ⇒ Object
1 << 5.
-
.encode_user_id(value) ⇒ Object
1 << 4.
Methods inherited from Class
classes, inherited, method_id, name
Class Method Details
.decode_properties(data) ⇒ Object
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 |
# File 'lib/amq/protocol/client.rb', line 1458 def self.decode_properties(data) offset, data_length, properties = 0, data.bytesize, {} compressed_index = data[offset, 2].unpack(PACK_UINT16)[0] offset += 2 while data_length > offset DECODE_PROPERTIES_KEYS.each do |key| next unless compressed_index >= key compressed_index -= key name = DECODE_PROPERTIES[key] || raise(RuntimeError.new("No property found for index #{index.inspect}!")) case DECODE_PROPERTIES_TYPE[key] when :shortstr size = data[offset, 1].unpack(PACK_CHAR)[0] offset += 1 result = data[offset, size] when :octet size = 1 result = data[offset, size].unpack(PACK_CHAR).first when :timestamp size = 8 result = Time.at(data[offset, size].unpack(PACK_UINT32_X2).last) when :table size = 4 + data[offset, 4].unpack(PACK_UINT32)[0] result = Table.decode(data[offset, size]) end properties[name] = result offset += size end end properties end |
.encode_app_id(value) ⇒ Object
1 << 3
1373 1374 1375 1376 1377 1378 |
# File 'lib/amq/protocol/client.rb', line 1373 def self.encode_app_id(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [12, 0x0008, buffer] end |
.encode_cluster_id(value) ⇒ Object
1 << 2
1381 1382 1383 1384 1385 1386 |
# File 'lib/amq/protocol/client.rb', line 1381 def self.encode_cluster_id(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [13, 0x0004, buffer] end |
.encode_content_encoding(value) ⇒ Object
1 << 14
1289 1290 1291 1292 1293 1294 |
# File 'lib/amq/protocol/client.rb', line 1289 def self.encode_content_encoding(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [1, 0x4000, buffer] end |
.encode_content_type(value) ⇒ Object
1 << 15
1281 1282 1283 1284 1285 1286 |
# File 'lib/amq/protocol/client.rb', line 1281 def self.encode_content_type(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [0, 0x8000, buffer] end |
.encode_correlation_id(value) ⇒ Object
1 << 10
1318 1319 1320 1321 1322 1323 |
# File 'lib/amq/protocol/client.rb', line 1318 def self.encode_correlation_id(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [5, 0x0400, buffer] end |
.encode_delivery_mode(value) ⇒ Object
1 << 12
1304 1305 1306 1307 1308 |
# File 'lib/amq/protocol/client.rb', line 1304 def self.encode_delivery_mode(value) buffer = "" buffer << [value].pack(PACK_CHAR) [3, 0x1000, buffer] end |
.encode_expiration(value) ⇒ Object
1 << 8
1334 1335 1336 1337 1338 1339 |
# File 'lib/amq/protocol/client.rb', line 1334 def self.encode_expiration(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [7, 0x0100, buffer] end |
.encode_headers(value) ⇒ Object
1 << 13
1297 1298 1299 1300 1301 |
# File 'lib/amq/protocol/client.rb', line 1297 def self.encode_headers(value) buffer = "" buffer << AMQ::Protocol::Table.encode(value) [2, 0x2000, buffer] end |
.encode_message_id(value) ⇒ Object
1 << 7
1342 1343 1344 1345 1346 1347 |
# File 'lib/amq/protocol/client.rb', line 1342 def self.(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [8, 0x0080, buffer] end |
.encode_priority(value) ⇒ Object
1 << 11
1311 1312 1313 1314 1315 |
# File 'lib/amq/protocol/client.rb', line 1311 def self.encode_priority(value) buffer = "" buffer << [value].pack(PACK_CHAR) [4, 0x0800, buffer] end |
.encode_properties(body_size, properties) ⇒ Object
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 |
# File 'lib/amq/protocol/client.rb', line 1388 def self.encode_properties(body_size, properties) pieces, flags = [], 0 properties.reject {|key, value| value.nil?}.each do |key, value| i, f, result = self.__send__(:"encode_#{key}", value) flags |= f pieces[i] = result end # result = [60, 0, body_size, flags].pack("n2Qn") result = [60, 0].pack(PACK_UINT16_X2) result += AMQ::Hacks.pack_64_big_endian(body_size) result += [flags].pack(PACK_UINT16) result + pieces.join(EMPTY_STRING) end |
.encode_reply_to(value) ⇒ Object
1 << 9
1326 1327 1328 1329 1330 1331 |
# File 'lib/amq/protocol/client.rb', line 1326 def self.encode_reply_to(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [6, 0x0200, buffer] end |
.encode_timestamp(value) ⇒ Object
1 << 6
1350 1351 1352 1353 1354 |
# File 'lib/amq/protocol/client.rb', line 1350 def self.(value) buffer = "" buffer << AMQ::Hacks.pack_64_big_endian(value) [9, 0x0040, buffer] end |
.encode_type(value) ⇒ Object
1 << 5
1357 1358 1359 1360 1361 1362 |
# File 'lib/amq/protocol/client.rb', line 1357 def self.encode_type(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [10, 0x0020, buffer] end |
.encode_user_id(value) ⇒ Object
1 << 4
1365 1366 1367 1368 1369 1370 |
# File 'lib/amq/protocol/client.rb', line 1365 def self.encode_user_id(value) buffer = "" buffer << value.to_s.bytesize.chr buffer << value.to_s [11, 0x0010, buffer] end |