Class: AMQ::Protocol::TableValueDecoder
- Inherits:
-
Object
- Object
- AMQ::Protocol::TableValueDecoder
- Includes:
- TypeConstants
- Defined in:
- lib/amq/protocol/table_value_decoder.rb
Constant Summary
Constants included from TypeConstants
AMQ::Protocol::TypeConstants::BOOLEAN_FALSE, AMQ::Protocol::TypeConstants::BOOLEAN_TRUE, AMQ::Protocol::TypeConstants::TEN, AMQ::Protocol::TypeConstants::TYPE_32BIT_FLOAT, AMQ::Protocol::TypeConstants::TYPE_64BIT_FLOAT, AMQ::Protocol::TypeConstants::TYPE_ARRAY, AMQ::Protocol::TypeConstants::TYPE_BOOLEAN, AMQ::Protocol::TypeConstants::TYPE_BYTE_ARRAY, AMQ::Protocol::TypeConstants::TYPE_DECIMAL, AMQ::Protocol::TypeConstants::TYPE_HASH, AMQ::Protocol::TypeConstants::TYPE_INTEGER, AMQ::Protocol::TypeConstants::TYPE_SIGNED_16BIT, AMQ::Protocol::TypeConstants::TYPE_SIGNED_64BIT, AMQ::Protocol::TypeConstants::TYPE_SIGNED_8BIT, AMQ::Protocol::TypeConstants::TYPE_STRING, AMQ::Protocol::TypeConstants::TYPE_TIME, AMQ::Protocol::TypeConstants::TYPE_VOID
Class Method Summary collapse
- .decode_32bit_float(data, offset) ⇒ Object
- .decode_64bit_float(data, offset) ⇒ Object
-
.decode_array(data, initial_offset) ⇒ Object
API.
- .decode_big_decimal(data, offset) ⇒ Object
- .decode_boolean(data, offset) ⇒ Object
- .decode_hash(data, offset) ⇒ Object
- .decode_integer(data, offset) ⇒ Object
- .decode_string(data, offset) ⇒ Object
- .decode_time(data, offset) ⇒ Object
- .decode_value_type(data, offset) ⇒ Object
Class Method Details
.decode_32bit_float(data, offset) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 120 def self.decode_32bit_float(data, offset) v = data.slice(offset, 4).unpack(PACK_32BIT_FLOAT).first offset += 4 [v, offset] end |
.decode_64bit_float(data, offset) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 128 def self.decode_64bit_float(data, offset) v = data.slice(offset, 8).unpack(PACK_64BIT_FLOAT).first offset += 8 [v, offset] end |
.decode_array(data, initial_offset) ⇒ Object
API
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 23 def self.decode_array(data, initial_offset) array_length = data.slice(initial_offset, 4).unpack(PACK_UINT32).first ary = Array.new offset = initial_offset + 4 while offset <= (initial_offset + array_length) type, offset = decode_value_type(data, offset) i = case type when TYPE_STRING v, offset = decode_string(data, offset) v when TYPE_INTEGER v, offset = decode_integer(data, offset) v when TYPE_DECIMAL v, offset = decode_big_decimal(data, offset) v when TYPE_TIME v, offset = decode_time(data, offset) v when TYPE_HASH v, offset = decode_hash(data, offset) v when TYPE_BOOLEAN v, offset = decode_boolean(data, offset) v when TYPE_SIGNED_8BIT then raise NotImplementedError.new when TYPE_SIGNED_16BIT then raise NotImplementedError.new when TYPE_SIGNED_64BIT then raise NotImplementedError.new when TYPE_32BIT_FLOAT then v, offset = decode_32bit_float(data, offset) v when TYPE_64BIT_FLOAT then v, offset = decode_64bit_float(data, offset) v when TYPE_VOID nil when TYPE_ARRAY v, offset = TableValueDecoder.decode_array(data, offset) v else raise ArgumentError.new("unsupported type: #{type.inspect}") end ary << i end [ary, initial_offset + array_length + 4] end |
.decode_big_decimal(data, offset) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 95 def self.decode_big_decimal(data, offset) decimals, raw = data.slice(offset, 5).unpack(PACK_UCHAR_UINT32) offset += 5 v = BigDecimal.new(raw.to_s) * (BigDecimal.new(TEN) ** -decimals) [v, offset] end |
.decode_boolean(data, offset) ⇒ Object
113 114 115 116 117 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 113 def self.decode_boolean(data, offset) integer = data.slice(offset, 2).unpack(PACK_CHAR).first # 0 or 1 offset += 1 [(integer == 1), offset] end |
.decode_hash(data, offset) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 142 def self.decode_hash(data, offset) length = data.slice(offset, 4).unpack(PACK_UINT32).first v = Table.decode(data.slice(offset, length + 4)) offset += 4 + length [v, offset] end |
.decode_integer(data, offset) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 87 def self.decode_integer(data, offset) v = data.slice(offset, 4).unpack(PACK_UINT32).first offset += 4 [v, offset] end |
.decode_string(data, offset) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 77 def self.decode_string(data, offset) length = data.slice(offset, 4).unpack(PACK_UINT32).first offset += 4 v = data.slice(offset, length) offset += length [v, offset] end |
.decode_time(data, offset) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 104 def self.decode_time(data, offset) = data.slice(offset, 8).unpack(PACK_UINT32_X2).last v = Time.at() offset += 8 [v, offset] end |
.decode_value_type(data, offset) ⇒ Object
136 137 138 |
# File 'lib/amq/protocol/table_value_decoder.rb', line 136 def self.decode_value_type(data, offset) [data.slice(offset, 1), offset + 1] end |