amq-protocol 0.9.3 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -84,9 +84,13 @@ module AMQ
84
84
  when TYPE_BOOLEAN
85
85
  v, offset = TableValueDecoder.decode_boolean(data, offset)
86
86
  v
87
- when TYPE_SIGNED_8BIT then raise NotImplementedError.new
88
- when TYPE_SIGNED_16BIT then raise NotImplementedError.new
89
- when TYPE_SIGNED_64BIT then raise NotImplementedError.new
87
+ when TYPE_SIGNED_8BIT then
88
+ raise NotImplementedError.new
89
+ when TYPE_SIGNED_16BIT then
90
+ raise NotImplementedError.new
91
+ when TYPE_SIGNED_64BIT then
92
+ v, offset = TableValueDecoder.decode_long(data, offset)
93
+ v
90
94
  when TYPE_32BIT_FLOAT then
91
95
  v, offset = TableValueDecoder.decode_32bit_float(data, offset)
92
96
  v
@@ -20,6 +20,10 @@ module AMQ
20
20
  # API
21
21
  #
22
22
 
23
+ BIG_ENDIAN = ([1].pack("s") == "\x00\x01")
24
+ Q = "Q".freeze
25
+
26
+
23
27
  def self.decode_array(data, initial_offset)
24
28
  array_length = data.slice(initial_offset, 4).unpack(PACK_UINT32).first
25
29
 
@@ -30,41 +34,47 @@ module AMQ
30
34
  type, offset = decode_value_type(data, offset)
31
35
 
32
36
  i = case type
33
- when TYPE_STRING
34
- v, offset = decode_string(data, offset)
35
- v
36
- when TYPE_INTEGER
37
- v, offset = decode_integer(data, offset)
38
- v
39
- when TYPE_DECIMAL
40
- v, offset = decode_big_decimal(data, offset)
41
- v
42
- when TYPE_TIME
43
- v, offset = decode_time(data, offset)
44
- v
45
- when TYPE_HASH
46
- v, offset = decode_hash(data, offset)
47
- v
48
- when TYPE_BOOLEAN
49
- v, offset = decode_boolean(data, offset)
50
- v
51
- when TYPE_SIGNED_8BIT then raise NotImplementedError.new
52
- when TYPE_SIGNED_16BIT then raise NotImplementedError.new
53
- when TYPE_SIGNED_64BIT then raise NotImplementedError.new
54
- when TYPE_32BIT_FLOAT then
55
- v, offset = decode_32bit_float(data, offset)
56
- v
57
- when TYPE_64BIT_FLOAT then
58
- v, offset = decode_64bit_float(data, offset)
59
- v
60
- when TYPE_VOID
61
- nil
62
- when TYPE_ARRAY
63
- v, offset = TableValueDecoder.decode_array(data, offset)
64
- v
65
- else
66
- raise ArgumentError.new("unsupported type: #{type.inspect}")
67
- end
37
+ when TYPE_STRING
38
+ v, offset = decode_string(data, offset)
39
+ v
40
+ when TYPE_INTEGER
41
+ v, offset = decode_integer(data, offset)
42
+ v
43
+ when TYPE_DECIMAL
44
+ v, offset = decode_big_decimal(data, offset)
45
+ v
46
+ when TYPE_TIME
47
+ v, offset = decode_time(data, offset)
48
+ v
49
+ when TYPE_HASH
50
+ v, offset = decode_hash(data, offset)
51
+ v
52
+ when TYPE_BOOLEAN
53
+ v, offset = decode_boolean(data, offset)
54
+ v
55
+ when TYPE_SIGNED_8BIT then
56
+ # TODO
57
+ raise NotImplementedError.new
58
+ when TYPE_SIGNED_16BIT then
59
+ # TODO
60
+ raise NotImplementedError.new
61
+ when TYPE_SIGNED_64BIT then
62
+ v, offset = decode_long(data, offset)
63
+ v
64
+ when TYPE_32BIT_FLOAT then
65
+ v, offset = decode_32bit_float(data, offset)
66
+ v
67
+ when TYPE_64BIT_FLOAT then
68
+ v, offset = decode_64bit_float(data, offset)
69
+ v
70
+ when TYPE_VOID
71
+ nil
72
+ when TYPE_ARRAY
73
+ v, offset = TableValueDecoder.decode_array(data, offset)
74
+ v
75
+ else
76
+ raise ArgumentError.new("unsupported type in a table value: #{type.inspect}, do not know how to decode!")
77
+ end
68
78
 
69
79
  ary << i
70
80
  end
@@ -92,6 +102,24 @@ module AMQ
92
102
  end # self.decode_integer(data, offset)
93
103
 
94
104
 
105
+ if BIG_ENDIAN
106
+ def self.decode_long(data, offset)
107
+ v = data.slice(offset, 8).unpack(Q)
108
+
109
+ offset += 8
110
+ [v, offset]
111
+ end
112
+ else
113
+ def self.decode_long(data, offset)
114
+ slice = data.slice(offset, 8).bytes.to_a.reverse.map(&:chr).join
115
+ v = slice.unpack(Q).first
116
+
117
+ offset += 8
118
+ [v, offset]
119
+ end
120
+ end
121
+
122
+
95
123
  def self.decode_big_decimal(data, offset)
96
124
  decimals, raw = data.slice(offset, 5).unpack(PACK_UCHAR_UINT32)
97
125
  offset += 5
@@ -1,5 +1,5 @@
1
1
  module AMQ
2
2
  module Protocol
3
- VERSION = "0.9.3"
3
+ VERSION = "0.9.4"
4
4
  end # Protocol
5
5
  end # AMQ
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amq-protocol
3
3
  version: !ruby/object:Gem::Version
4
- hash: 61
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 3
10
- version: 0.9.3
9
+ - 4
10
+ version: 0.9.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jakub Stastny
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-06-27 00:00:00 Z
21
+ date: 2012-07-02 00:00:00 Z
22
22
  dependencies: []
23
23
 
24
24
  description: " amq-protocol is an AMQP 0.9.1 serialization library for Ruby. It is not an\n AMQP client: amq-protocol only handles serialization and deserialization.\n If you want to write your own AMQP client, this gem can help you with that.\n"
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements: []
104
104
 
105
105
  rubyforge_project: amq-protocol
106
- rubygems_version: 1.8.15
106
+ rubygems_version: 1.8.24
107
107
  signing_key:
108
108
  specification_version: 3
109
109
  summary: AMQP 0.9.1 encoder & decoder.