amq-protocol 1.0.0.pre1 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +0 -1
- data/lib/amq/bit_set.rb +82 -0
- data/lib/amq/protocol/version.rb +1 -1
- data/spec/amq/bit_set_spec.rb +128 -0
- data/spec/amq/protocol/method_spec.rb +2 -2
- metadata +6 -4
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/lib/amq/bit_set.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module AMQ
|
4
|
+
# Very minimalistic, pure Ruby implementation of bit set. Inspired by java.util.BitSet,
|
5
|
+
# although significantly smaller in scope.
|
6
|
+
#
|
7
|
+
# Originally part of amqp gem. Extracted to make it possible for Bunny to use it.
|
8
|
+
class BitSet
|
9
|
+
|
10
|
+
#
|
11
|
+
# API
|
12
|
+
#
|
13
|
+
|
14
|
+
ADDRESS_BITS_PER_WORD = 6
|
15
|
+
BITS_PER_WORD = (1 << ADDRESS_BITS_PER_WORD)
|
16
|
+
WORD_MASK = 0xffffffffffffffff
|
17
|
+
|
18
|
+
# @param [Integer] Number of bits in the set
|
19
|
+
# @api public
|
20
|
+
def initialize(nbits)
|
21
|
+
@nbits = nbits
|
22
|
+
|
23
|
+
self.init_words(nbits)
|
24
|
+
end # initialize(nbits)
|
25
|
+
|
26
|
+
# Sets (flags) given bit. This method allows bits to be set more than once in a row, no exception will be raised.
|
27
|
+
#
|
28
|
+
# @param [Integer] A bit to set
|
29
|
+
# @api public
|
30
|
+
def set(i)
|
31
|
+
w = self.word_index(i)
|
32
|
+
@words[w] |= (1 << i)
|
33
|
+
end # set(i)
|
34
|
+
|
35
|
+
# Fetches flag value for given bit.
|
36
|
+
#
|
37
|
+
# @param [Integer] A bit to fetch
|
38
|
+
# @return [Boolean] true if given bit is set, false otherwise
|
39
|
+
# @api public
|
40
|
+
def get(i)
|
41
|
+
w = self.word_index(i)
|
42
|
+
|
43
|
+
(@words[w] & (1 << i)) != 0
|
44
|
+
end # get(i)
|
45
|
+
alias [] get
|
46
|
+
|
47
|
+
# Unsets (unflags) given bit. This method allows bits to be unset more than once in a row, no exception will be raised.
|
48
|
+
#
|
49
|
+
# @param [Integer] A bit to unset
|
50
|
+
# @api public
|
51
|
+
def unset(i)
|
52
|
+
w = self.word_index(i)
|
53
|
+
return if w.nil?
|
54
|
+
|
55
|
+
@words[w] &= ~(1 << i)
|
56
|
+
end # unset(i)
|
57
|
+
|
58
|
+
# Clears all bits in the set
|
59
|
+
# @api public
|
60
|
+
def clear
|
61
|
+
self.init_words(@nbits)
|
62
|
+
end # clear
|
63
|
+
|
64
|
+
|
65
|
+
#
|
66
|
+
# Implementation
|
67
|
+
#
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
# @private
|
72
|
+
def init_words(nbits)
|
73
|
+
n = word_index(nbits-1) + 1
|
74
|
+
@words = Array.new(n) { 1 }
|
75
|
+
end # init_words
|
76
|
+
|
77
|
+
# @private
|
78
|
+
def word_index(i)
|
79
|
+
i >> ADDRESS_BITS_PER_WORD
|
80
|
+
end # word_index(i)
|
81
|
+
end # BitSet
|
82
|
+
end # AMQ
|
data/lib/amq/protocol/version.rb
CHANGED
@@ -0,0 +1,128 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
require "amq/bit_set"
|
6
|
+
|
7
|
+
|
8
|
+
# extracted from amqp gem. MK.
|
9
|
+
describe AMQ::BitSet do
|
10
|
+
|
11
|
+
#
|
12
|
+
# Environment
|
13
|
+
#
|
14
|
+
|
15
|
+
let(:nbits) { (1 << 16) - 1 }
|
16
|
+
|
17
|
+
|
18
|
+
#
|
19
|
+
# Examples
|
20
|
+
#
|
21
|
+
|
22
|
+
describe "#get, #[]" do
|
23
|
+
describe "when bit at given position is set" do
|
24
|
+
subject do
|
25
|
+
o = described_class.new(nbits)
|
26
|
+
o.set(3)
|
27
|
+
o
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns true" do
|
31
|
+
subject.get(3).should be_true
|
32
|
+
end # it
|
33
|
+
end # describe
|
34
|
+
|
35
|
+
describe "when bit at given position is off" do
|
36
|
+
subject do
|
37
|
+
described_class.new(nbits)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns false" do
|
41
|
+
subject.get(5).should be_false
|
42
|
+
end # it
|
43
|
+
end # describe
|
44
|
+
end # describe
|
45
|
+
|
46
|
+
|
47
|
+
describe "#set" do
|
48
|
+
describe "when bit at given position is set" do
|
49
|
+
subject do
|
50
|
+
described_class.new(nbits)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "has no effect" do
|
54
|
+
subject.set(3)
|
55
|
+
subject.get(3).should be_true
|
56
|
+
subject.set(3)
|
57
|
+
subject[3].should be_true
|
58
|
+
end # it
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "when bit at given position is off" do
|
62
|
+
subject do
|
63
|
+
described_class.new(nbits)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets that bit" do
|
67
|
+
subject.set(3)
|
68
|
+
subject.get(3).should be_true
|
69
|
+
|
70
|
+
subject.set(33)
|
71
|
+
subject.get(33).should be_true
|
72
|
+
|
73
|
+
subject.set(3387)
|
74
|
+
subject.get(3387).should be_true
|
75
|
+
end
|
76
|
+
end # describe
|
77
|
+
end # describe
|
78
|
+
|
79
|
+
|
80
|
+
describe "#unset" do
|
81
|
+
describe "when bit at a given position is set" do
|
82
|
+
subject do
|
83
|
+
described_class.new(nbits)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "unsets that bit" do
|
87
|
+
subject.set(3)
|
88
|
+
subject.get(3).should be_true
|
89
|
+
subject.unset(3)
|
90
|
+
subject.get(3).should be_false
|
91
|
+
end # it
|
92
|
+
end # describe
|
93
|
+
|
94
|
+
|
95
|
+
describe "when bit at a given position is off" do
|
96
|
+
subject do
|
97
|
+
described_class.new(nbits)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "has no effect" do
|
101
|
+
subject.get(3).should be_false
|
102
|
+
subject.unset(3)
|
103
|
+
subject.get(3).should be_false
|
104
|
+
end # it
|
105
|
+
end # describe
|
106
|
+
end # describe
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
describe "#clear" do
|
111
|
+
subject do
|
112
|
+
described_class.new(nbits)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "clears all bits" do
|
116
|
+
subject.set(3)
|
117
|
+
subject.get(3).should be_true
|
118
|
+
|
119
|
+
subject.set(7668)
|
120
|
+
subject.get(7668).should be_true
|
121
|
+
|
122
|
+
subject.clear
|
123
|
+
|
124
|
+
subject.get(3).should be_false
|
125
|
+
subject.get(7668).should be_false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -25,11 +25,11 @@ module AMQ
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context 'when the body is
|
28
|
+
context 'when the body is too big to fit in a single frame' do
|
29
29
|
it 'encodes a body into a list of BodyFrames that each fit within the frame size' do
|
30
30
|
lipsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
|
31
31
|
frame_size = 100
|
32
|
-
expected_payload_size =
|
32
|
+
expected_payload_size = 92
|
33
33
|
body_frames = Method.encode_body(lipsum, 1, frame_size)
|
34
34
|
body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
|
35
35
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amq-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: -
|
4
|
+
hash: -2170921152
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- pre
|
11
|
-
-
|
12
|
-
version: 1.0.0.
|
11
|
+
- 2
|
12
|
+
version: 1.0.0.pre2
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Jakub Stastny
|
@@ -20,7 +20,7 @@ autorequire:
|
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
22
|
|
23
|
-
date: 2012-06-
|
23
|
+
date: 2012-06-23 00:00:00 Z
|
24
24
|
dependencies: []
|
25
25
|
|
26
26
|
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"
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- codegen_helpers.py
|
50
50
|
- generate.rb
|
51
51
|
- irb.rb
|
52
|
+
- lib/amq/bit_set.rb
|
52
53
|
- lib/amq/hacks.rb
|
53
54
|
- lib/amq/protocol.rb
|
54
55
|
- lib/amq/protocol/client.rb
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- lib/amq/protocol/version.rb
|
61
62
|
- post-processing.rb
|
62
63
|
- protocol.rb.pytemplate
|
64
|
+
- spec/amq/bit_set_spec.rb
|
63
65
|
- spec/amq/hacks_spec.rb
|
64
66
|
- spec/amq/protocol/basic_spec.rb
|
65
67
|
- spec/amq/protocol/blank_body_encoding_spec.rb
|