ruby-osc 0.4.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +0 -2
- data/examples/localtest.rb +1 -2
- data/lib/ruby-osc.rb +11 -13
- data/lib/ruby-osc/bundle.rb +6 -7
- data/lib/ruby-osc/client.rb +8 -13
- data/lib/ruby-osc/message.rb +27 -42
- data/lib/ruby-osc/server.rb +3 -3
- data/lib/ruby-osc/version.rb +1 -2
- data/spec/bundle_spec.rb +12 -13
- data/spec/message_spec.rb +35 -54
- data/spec/server_spec.rb +0 -1
- data/spec/spec_helper.rb +2 -2
- metadata +22 -14
- checksums.yaml +0 -7
- data/streamscanner_benchmark.rb +0 -37
data/README.rdoc
CHANGED
data/examples/localtest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
$:.unshift( File.join( File.dirname( __FILE__), '..', 'lib' ) )
|
2
2
|
require 'ruby-osc'
|
3
3
|
|
4
4
|
include OSC
|
@@ -23,7 +23,6 @@ OSC.run do
|
|
23
23
|
exit
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
26
|
client.send Message.new('/foo/bar', 1, 1.2, 'a string')
|
28
27
|
client.send Message.new('/foo/bar/zar', 1, 1.2, 'a string')
|
29
28
|
client.send Bundle.new(Time.now + 2, Message.new('/exit'))
|
data/lib/ruby-osc.rb
CHANGED
@@ -4,9 +4,7 @@ require 'socket' # Strange side effects with eventmachine udp client and SuperCo
|
|
4
4
|
require 'strscan'
|
5
5
|
require 'thread'
|
6
6
|
|
7
|
-
$:.unshift( File.join( File.dirname( __FILE__), '..', 'lib' ) )
|
8
|
-
|
9
|
-
# encoding: UTF-8
|
7
|
+
$:.unshift( File.join( File.dirname( __FILE__), '..', 'lib' ) )
|
10
8
|
require 'ruby-osc/message'
|
11
9
|
require 'ruby-osc/bundle'
|
12
10
|
require 'ruby-osc/server'
|
@@ -15,15 +13,15 @@ require "ruby-osc/version"
|
|
15
13
|
|
16
14
|
module OSC
|
17
15
|
class DecodeError < StandardError; end
|
18
|
-
|
16
|
+
|
19
17
|
class Blob < String; end
|
20
|
-
|
18
|
+
|
21
19
|
module OSCArgument
|
22
20
|
def to_osc_type
|
23
21
|
raise NotImplementedError, "#to_osc_type method should be implemented for #{ self.class }"
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
27
25
|
def self.coerce_argument arg
|
28
26
|
case arg
|
29
27
|
when OSCArgument then arg.to_osc_type
|
@@ -31,29 +29,29 @@ module OSC
|
|
31
29
|
when String, Float, Fixnum, Blob, String then arg # Pure osc 1.0 specification
|
32
30
|
else raise(TypeError, "#{ arg.inspect } is not a valid Message argument") end
|
33
31
|
end
|
34
|
-
|
32
|
+
|
35
33
|
def self.decode str #:nodoc:
|
36
34
|
str.match(/^#bundle/) ? Bundle.decode(str) : Message.decode(str)
|
37
35
|
end
|
38
|
-
|
36
|
+
|
39
37
|
def self.padding_size size
|
40
|
-
(4 - (size) % 4) % 4
|
38
|
+
(4 - (size) % 4) % 4
|
41
39
|
end
|
42
40
|
|
43
41
|
def self.run
|
44
42
|
EM.run do
|
45
43
|
EM.error_handler { |e| puts e }
|
46
|
-
EM.set_quantum 5
|
44
|
+
EM.set_quantum 5
|
47
45
|
yield
|
48
46
|
end
|
49
47
|
end
|
50
|
-
|
48
|
+
|
51
49
|
def self.encoding_directive obj #:nodoc:
|
52
50
|
case obj
|
53
51
|
when Float then [obj, 'f', 'g']
|
54
52
|
when Fixnum then [obj, 'i', 'N']
|
55
|
-
when Blob then [[obj.
|
56
|
-
when String then [obj, 's', "Z*x#{ padding_size obj.
|
53
|
+
when Blob then [[obj.size, obj], 'b', "Na*x#{ padding_size obj.size + 4 }"]
|
54
|
+
when String then [obj, 's', "Z*x#{ padding_size obj.size + 1 }"]
|
57
55
|
when Time
|
58
56
|
t1, fr = (obj.to_f + 2208988800).divmod(1)
|
59
57
|
t2 = (fr * (2**32)).to_i
|
data/lib/ruby-osc/bundle.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
module OSC
|
3
2
|
class Bundle < Array
|
4
3
|
attr_accessor :timetag
|
@@ -16,7 +15,7 @@ module OSC
|
|
16
15
|
time, tag, dir = OSC.encoding_directive @timetag
|
17
16
|
time.pack dir
|
18
17
|
else "\000\000\000\000\000\000\000\001" end
|
19
|
-
|
18
|
+
|
20
19
|
"#bundle\000#{ timetag }" + collect do |x|
|
21
20
|
x = x.encode
|
22
21
|
[x.size].pack('N') + x
|
@@ -26,26 +25,26 @@ module OSC
|
|
26
25
|
def self.decode string
|
27
26
|
string.sub! /^#bundle\000/, ''
|
28
27
|
t1, t2, content_str = string.unpack('N2a*')
|
29
|
-
|
28
|
+
|
30
29
|
timetag = t1 == 0 && t2 == 1 ? nil : Time.at(t1 + t2 / (2**32.0) - 2_208_988_800)
|
31
30
|
scanner = StringScanner.new content_str
|
32
31
|
args = []
|
33
|
-
|
32
|
+
|
34
33
|
until scanner.eos?
|
35
34
|
size = scanner.scan(/.{4}/).unpack('N').first
|
36
35
|
arg_str = scanner.scan(/.{#{ size }}/nm) rescue raise(DecodeError, "An error occured while trying to decode bad formatted osc bundle")
|
37
36
|
args << OSC.decode(arg_str)
|
38
37
|
end
|
39
|
-
|
38
|
+
|
40
39
|
new timetag, *args
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
def == other
|
44
43
|
self.class == other.class and self.timetag == other.timetag and self.to_a == other.to_a
|
45
44
|
end
|
46
45
|
|
47
46
|
def to_a; Array.new self; end
|
48
|
-
|
47
|
+
|
49
48
|
def to_s
|
50
49
|
"OSC::Bundle(#{ self.join(', ') })"
|
51
50
|
end
|
data/lib/ruby-osc/client.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'socket' # Strange side effects with eventmachine udp client and SuperCollider
|
3
|
-
|
4
1
|
# From the Funaba osc gem:
|
5
2
|
module OSC
|
6
3
|
class Client
|
7
|
-
|
4
|
+
|
8
5
|
def initialize port, host = '127.0.0.1'
|
9
6
|
@socket = UDPSocket.new
|
10
|
-
@socket = UDPSocket.open
|
11
|
-
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
|
12
7
|
@socket.connect host, port
|
13
8
|
end
|
14
|
-
|
9
|
+
|
15
10
|
def send mesg, *args
|
16
11
|
@socket.send mesg.encode, 0
|
17
12
|
end
|
@@ -20,24 +15,24 @@ end
|
|
20
15
|
|
21
16
|
# module OSC
|
22
17
|
# class Client
|
23
|
-
#
|
18
|
+
#
|
24
19
|
# def initialize port, address = 'localhost'
|
25
20
|
# @address, @port = address, port
|
26
21
|
# run
|
27
22
|
# end
|
28
|
-
#
|
23
|
+
#
|
29
24
|
# def run
|
30
25
|
# @connection = EventMachine.open_datagram_socket 'localhost', 0, Connection
|
31
26
|
# end
|
32
|
-
#
|
27
|
+
#
|
33
28
|
# def stop
|
34
29
|
# @connection.close_connection if @connection
|
35
30
|
# end
|
36
|
-
#
|
31
|
+
#
|
37
32
|
# def send item
|
38
|
-
# @connection.send_datagram item.encode, @address, @port
|
33
|
+
# @connection.send_datagram item.encode, @address, @port
|
39
34
|
# end
|
40
|
-
#
|
35
|
+
#
|
41
36
|
# class Connection < EventMachine::Connection #:nodoc:
|
42
37
|
# end
|
43
38
|
# end
|
data/lib/ruby-osc/message.rb
CHANGED
@@ -31,51 +31,36 @@ module OSC
|
|
31
31
|
|
32
32
|
def self.decode string
|
33
33
|
scanner = StringScanner.new string
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def self.decode_message scanner
|
40
|
-
pos = scanner.pos
|
41
|
-
begin
|
42
|
-
address, tags = (1..2).map do
|
43
|
-
string = scanner.scan(/[^\000]+\000/)
|
44
|
-
raise DecodeError, "no address or tags" if string.nil?
|
45
|
-
scanner.pos += OSC.padding_size(string.bytesize)
|
46
|
-
string.chomp("\000")
|
47
|
-
end
|
34
|
+
address, tags = (1..2).map do
|
35
|
+
string = scanner.scan(/[^\000]+\000/)
|
36
|
+
scanner.pos += OSC.padding_size(string.size)
|
37
|
+
string.chomp("\000")
|
38
|
+
end
|
48
39
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
raise DecodeError, "#{ tag } is not a known tag"
|
69
|
-
end
|
40
|
+
args = []
|
41
|
+
tags.scan(/\w/) do |tag|
|
42
|
+
case tag
|
43
|
+
when 'i'
|
44
|
+
int = scanner.scan(/.{4}/nm).unpack('N').first
|
45
|
+
args.push( int > (2**31-1) ? int - 2**32 : int )
|
46
|
+
when 'f'
|
47
|
+
args.push scanner.scan(/.{4}/nm).unpack('g').first
|
48
|
+
when 's'
|
49
|
+
str = scanner.scan(/[^\000]+\000/)
|
50
|
+
scanner.pos += OSC.padding_size(str.size)
|
51
|
+
args.push str.chomp("\000")
|
52
|
+
when 'b'
|
53
|
+
size = scanner.scan(/.{4}/).unpack('N').first
|
54
|
+
str = scanner.scan(/.{#{ size }}/nm)
|
55
|
+
scanner.pos += OSC.padding_size(size + 4)
|
56
|
+
args.push Blob.new(str)
|
57
|
+
else
|
58
|
+
raise DecodeError, "#{ t } is not a known tag"
|
70
59
|
end
|
71
|
-
new address, *args
|
72
60
|
end
|
73
|
-
|
74
|
-
|
75
|
-
raise e
|
76
|
-
rescue => e
|
77
|
-
scanner.pos = pos
|
78
|
-
raise DecodeError, e
|
61
|
+
|
62
|
+
new address, *args
|
79
63
|
end
|
64
|
+
|
80
65
|
end
|
81
66
|
end
|
data/lib/ruby-osc/server.rb
CHANGED
@@ -36,7 +36,7 @@ module OSC
|
|
36
36
|
when Message
|
37
37
|
dispatch decoded
|
38
38
|
end
|
39
|
-
rescue => e
|
39
|
+
rescue => e
|
40
40
|
warn "Bad data received: #{ e }"
|
41
41
|
end
|
42
42
|
|
@@ -54,7 +54,7 @@ module OSC
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def dispatch message
|
57
|
-
@patterns.each do |pat, block|
|
57
|
+
@patterns.each do |pat, block|
|
58
58
|
block.call(*message.to_a) if pat === message.address
|
59
59
|
end
|
60
60
|
end
|
@@ -65,7 +65,7 @@ module OSC
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def receive_data data
|
68
|
-
@server.receive(data)
|
68
|
+
@server.receive(data)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
data/lib/ruby-osc/version.rb
CHANGED
data/spec/bundle_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require "#{ File.dirname __FILE__ }/spec_helper"
|
3
2
|
|
4
3
|
describe Bundle do
|
@@ -13,11 +12,11 @@ describe Bundle do
|
|
13
12
|
it "should rise TypeError if passing passing incorrect type" do
|
14
13
|
lambda { Bundle.new Time.now, 1 }.should raise_error(TypeError)
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
it "should raise TypeError if timetag is not Time" do
|
18
17
|
lambda { Bundle.new 1 }.should raise_error(TypeError)
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
it "should accept nil for timetag" do
|
22
21
|
Bundle.new nil
|
23
22
|
end
|
@@ -39,15 +38,15 @@ describe Bundle do
|
|
39
38
|
Bundle.decode(@expected).should == @bundle
|
40
39
|
end
|
41
40
|
end
|
42
|
-
|
41
|
+
|
43
42
|
describe 'Empty bundle nil timetag' do
|
44
43
|
before do
|
45
44
|
@bundle = Bundle.new
|
46
|
-
@expected = "#bundle\000\000\000\000\000\000\000\000\001"
|
45
|
+
@expected = "#bundle\000\000\000\000\000\000\000\000\001"
|
47
46
|
end
|
48
47
|
it_should_behave_like 'Encodable Bundle'
|
49
48
|
end
|
50
|
-
|
49
|
+
|
51
50
|
describe 'Empty bundle with timetag' do
|
52
51
|
before do
|
53
52
|
@bundle = Bundle.new Time.at(1251420949.16959)
|
@@ -55,7 +54,7 @@ describe Bundle do
|
|
55
54
|
end
|
56
55
|
it_should_behave_like 'Encodable Bundle'
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
describe 'Bundle with timetag and messages' do
|
60
59
|
before do
|
61
60
|
@bundle = Bundle.new Time.at(946702800), Message.new('/bar/foo', 4, 3, 2, 1), Message.new('/foo/bar', 1, 2, 3, 4)
|
@@ -63,15 +62,15 @@ describe Bundle do
|
|
63
62
|
end
|
64
63
|
it_should_behave_like 'Encodable Bundle'
|
65
64
|
end
|
66
|
-
|
65
|
+
|
67
66
|
describe 'Nested bundles' do
|
68
67
|
before do
|
69
68
|
@bundle = Bundle.new( nil, Bundle.new(nil, Message.new('/a')), Message.new('/b') )
|
70
|
-
@expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
|
69
|
+
@expected = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
|
71
70
|
end
|
72
71
|
it_should_behave_like 'Encodable Bundle'
|
73
72
|
end
|
74
|
-
|
73
|
+
|
75
74
|
describe 'Complex blob' do
|
76
75
|
before do
|
77
76
|
data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 4, 104, 111, 108, 97, 0, 2, 67, -36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, -1, -1, 0, 0, -1, -1, 0, 1, 2, 0, 0 ].pack('C*')
|
@@ -80,7 +79,7 @@ describe Bundle do
|
|
80
79
|
end
|
81
80
|
it_should_behave_like 'Encodable Bundle'
|
82
81
|
end
|
83
|
-
|
82
|
+
|
84
83
|
describe 'Complex blob 2' do
|
85
84
|
before do
|
86
85
|
data = [ 83, 67, 103, 102, 0, 0, 0, 1, 0, 1, 2, 97, 109, 0, 7, 0, 0, 0, 0, 63, 0, 0, 0, 63, -128, 0, 0, 64, 0, 0, 0, -62, -58, 0, 0, 64, -96, 0, 0, -64, -128, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 103, 97, 116, 101, 0, 0, 9, 112, 111, 114, 116, 97, 100, 111, 114, 97, 0, 1, 10, 109, 111, 100, 117, 108, 97, 100, 111, 114, 97, 0, 2, 3, 97, 109, 112, 0, 3, 0, 8, 7, 67, 111, 110, 116, 114, 111, 108, 1, 0, 0, 0, 4, 0, 0, 1, 1, 1, 1, 6, 83, 105, 110, 79, 115, 99, 1, 0, 2, 0, 1, 0, 0, 0, 0, 0, 2, -1, -1, 0, 0, 1, 6, 77, 117, 108, 65, 100, 100, 1, 0, 3, 0, 1, 0, 0, 0, 1, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, 1, 6, 83, 105, 110, 79, 115, 99, 2, 0, 2, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 2, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 3, 0, 0, 0, 2, 0, 0, 2, 6, 69, 110, 118, 71, 101, 110, 1, 0, 17, 0, 1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -1, 0, 0, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 2, -1, -1, 0, 4, -1, -1, 0, 2, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, -1, -1, 0, 0, -1, -1, 0, 3, -1, -1, 0, 5, -1, -1, 0, 6, 1, 12, 66, 105, 110, 97, 114, 121, 79, 112, 85, 71, 101, 110, 2, 0, 2, 0, 1, 0, 2, 0, 4, 0, 0, 0, 5, 0, 0, 2, 3, 79, 117, 116, 2, 0, 2, 0, 0, 0, 0, -1, -1, 0, 0, 0, 6, 0, 0, 0, 0 ].pack('C*')
|
@@ -89,9 +88,9 @@ describe Bundle do
|
|
89
88
|
end
|
90
89
|
it_should_behave_like 'Encodable Bundle'
|
91
90
|
end
|
92
|
-
|
91
|
+
|
93
92
|
it 'Should raise OSC::DecodeError with bad encoded bundle' do
|
94
|
-
bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
|
93
|
+
bad_data = "#bundle\000\000\000\000\000\000\000\000\001\000\000\000\034#bundle\000\000\000\000\000\001\000\000\000\b/a\000\000,\000\000\000\000\000\000\b/b\000\000,\000\000\000"
|
95
94
|
lambda { Bundle.decode bad_data }.should raise_error(DecodeError)
|
96
95
|
end
|
97
96
|
end
|
data/spec/message_spec.rb
CHANGED
@@ -1,59 +1,56 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require "#{ File.dirname __FILE__ }/spec_helper"
|
3
2
|
|
4
3
|
describe Message do
|
4
|
+
|
5
5
|
it "should raise TypeError if passing wrong type" do
|
6
|
-
|
6
|
+
lambda { Message.new('address', Class) }.should raise_error(TypeError)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should raise TypeError if not passing a string for address" do
|
10
|
-
|
10
|
+
lambda { Message.new(OSC) }.should raise_error(TypeError)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should have address" do
|
14
14
|
Message.new('/foo/bar').address.should == '/foo/bar'
|
15
15
|
end
|
16
|
-
|
17
|
-
it "should accept utf8 address" do
|
18
|
-
Message.new('/foo/bär').address.should == '/foo/bär'
|
19
|
-
end
|
20
16
|
|
21
17
|
it "should collect args" do
|
22
18
|
Message.new('/foo/bar', 1, 2, 3, 4).args.size.should == 4
|
23
19
|
end
|
24
|
-
|
20
|
+
|
25
21
|
it "should accept integer" do
|
26
22
|
Message.new('/foo/bar', 1).args.should == [1]
|
27
23
|
end
|
28
|
-
|
24
|
+
|
29
25
|
it "should should accept float" do
|
30
26
|
Message.new('/foo/bar', 1.0).args.should == [1.0]
|
31
27
|
end
|
32
|
-
|
28
|
+
|
33
29
|
it "should accept string" do
|
34
30
|
Message.new('/foo/bar', 'string').args.should == ['string']
|
35
31
|
end
|
36
|
-
|
32
|
+
|
37
33
|
it "should accept Blob" do
|
38
34
|
Message.new('/foo/bar', Blob.new('blob')).args.should == [Blob.new('blob')]
|
39
35
|
end
|
40
|
-
|
36
|
+
|
41
37
|
it "should convert to array" do
|
42
38
|
Message.new('/foo/bar', 1, 2, 3, 4).to_a.should == ['/foo/bar', 1, 2, 3, 4]
|
43
39
|
end
|
44
|
-
|
40
|
+
|
45
41
|
describe 'Custom argument coercion' do
|
42
|
+
|
46
43
|
before do
|
47
44
|
TrueClass.send(:include, OSCArgument)
|
48
45
|
TrueClass.send( :define_method, :to_osc_type){ 1 }
|
49
46
|
FalseClass.send(:include, OSCArgument)
|
50
47
|
FalseClass.send( :define_method, :to_osc_type){ 0 }
|
51
48
|
Hash.send(:include, OSCArgument)
|
52
|
-
Hash.send( :define_method, :to_osc_type) do
|
49
|
+
Hash.send( :define_method, :to_osc_type) do
|
53
50
|
self.to_a.collect{ |pair| pair.collect{ |a| OSC.coerce_argument a } }
|
54
51
|
end
|
55
52
|
end
|
56
|
-
|
53
|
+
|
57
54
|
it "should accept true" do
|
58
55
|
Message.new('/foo/bar', true).args.should == [1]
|
59
56
|
end
|
@@ -66,50 +63,50 @@ describe Message do
|
|
66
63
|
Message.new('/foo/bar', {:a => :b}).args.should == ["a", "b"]
|
67
64
|
end
|
68
65
|
end
|
69
|
-
|
66
|
+
|
70
67
|
describe 'Encode/decode' do
|
71
68
|
shared_examples_for 'Encodable Message' do
|
72
69
|
it "should encode" do
|
73
70
|
@message.encode.should == @expected
|
74
71
|
end
|
75
|
-
|
72
|
+
|
76
73
|
it "should decode to message" do
|
77
74
|
Message.decode(@expected).should be_a(Message)
|
78
75
|
end
|
79
|
-
|
76
|
+
|
80
77
|
it "should decode address" do
|
81
78
|
Message.decode(@expected).address.should == @message.address
|
82
79
|
end
|
83
|
-
|
80
|
+
|
84
81
|
it "should actually decode" do
|
85
82
|
Message.decode(@expected).to_a.inspect.should == @message.to_a.inspect.to_s # Problem with float comparing
|
86
83
|
end
|
87
84
|
end
|
88
|
-
|
85
|
+
|
89
86
|
describe 'Address' do
|
90
87
|
before do
|
91
88
|
@message = Message.new('/foo/bar/long/very/long/long/long/address')
|
92
|
-
@expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000"
|
89
|
+
@expected = "/foo/bar/long/very/long/long/long/address\000\000\000,\000\000\000"
|
93
90
|
end
|
94
91
|
it_should_behave_like 'Encodable Message'
|
95
92
|
end
|
96
|
-
|
93
|
+
|
97
94
|
describe 'Integer' do
|
98
95
|
before do
|
99
96
|
@message = Message.new('/foo/barz', 2)
|
100
|
-
@expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002"
|
97
|
+
@expected = "/foo/barz\000\000\000,i\000\000\000\000\000\002"
|
101
98
|
end
|
102
99
|
it_should_behave_like 'Encodable Message'
|
103
100
|
end
|
104
|
-
|
101
|
+
|
105
102
|
describe 'Negative Integer' do
|
106
103
|
before do
|
107
104
|
@message = Message.new('/foo/barz', -2)
|
108
|
-
@expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376"
|
105
|
+
@expected = "/foo/barz\000\000\000,i\000\000\377\377\377\376"
|
109
106
|
end
|
110
107
|
it_should_behave_like 'Encodable Message'
|
111
108
|
end
|
112
|
-
|
109
|
+
|
113
110
|
describe 'Float' do
|
114
111
|
before do
|
115
112
|
@message = Message.new('/foo/bar', 1.100000023841858)
|
@@ -117,7 +114,7 @@ describe Message do
|
|
117
114
|
end
|
118
115
|
it_should_behave_like 'Encodable Message'
|
119
116
|
end
|
120
|
-
|
117
|
+
|
121
118
|
describe 'Negative Float' do
|
122
119
|
before do
|
123
120
|
@message = Message.new('/foo/bar', -1.100000023841858)
|
@@ -125,19 +122,11 @@ describe Message do
|
|
125
122
|
end
|
126
123
|
it_should_behave_like 'Encodable Message'
|
127
124
|
end
|
128
|
-
|
125
|
+
|
129
126
|
describe 'String' do
|
130
127
|
before do
|
131
128
|
@message = Message.new('/foo/bar', 'a string to encode')
|
132
|
-
@expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000"
|
133
|
-
end
|
134
|
-
it_should_behave_like 'Encodable Message'
|
135
|
-
end
|
136
|
-
|
137
|
-
describe 'UTF8 String' do
|
138
|
-
before do
|
139
|
-
@message = Message.new('/foo/bar', 'a string to äncode')
|
140
|
-
@expected = "/foo/bar\000\000\000\000,s\000\000a string to äncode\000".force_encoding("binary")
|
129
|
+
@expected = "/foo/bar\000\000\000\000,s\000\000a string to encode\000\000"
|
141
130
|
end
|
142
131
|
it_should_behave_like 'Encodable Message'
|
143
132
|
end
|
@@ -149,35 +138,27 @@ describe Message do
|
|
149
138
|
end
|
150
139
|
it_should_behave_like 'Encodable Message'
|
151
140
|
end
|
152
|
-
|
141
|
+
|
153
142
|
describe 'Blob' do
|
154
143
|
before do
|
155
144
|
@message = Message.new('/foo/bar', Blob.new('test blob'))
|
156
|
-
@expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000"
|
145
|
+
@expected = "/foo/bar\000\000\000\000,b\000\000\000\000\000\ttest blob\000\000\000"
|
157
146
|
end
|
158
147
|
it_should_behave_like 'Encodable Message'
|
159
|
-
|
148
|
+
|
160
149
|
it "should raise if size doesn't correspond and return empty message" do
|
161
150
|
lambda do
|
162
|
-
Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000"
|
151
|
+
Message.decode("/foo/bar\000\000\000\000,b\000\000\000\000\000\020test blob\000\000\000")
|
163
152
|
end.should raise_error
|
164
153
|
end
|
165
154
|
end
|
166
|
-
|
155
|
+
|
167
156
|
describe 'Lots of ints' do
|
168
157
|
before do
|
169
158
|
@message = Message.new('/bar/foo', 4, 3, 2, 1)
|
170
|
-
@expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001"
|
159
|
+
@expected = "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001"
|
171
160
|
end
|
172
161
|
it_should_behave_like 'Encodable Message'
|
173
162
|
end
|
174
|
-
|
175
|
-
describe 'Invalid message' do
|
176
|
-
it "should raise if invalid tag is used" do
|
177
|
-
lambda do
|
178
|
-
Message.decode("/foo/bar\000\000\000\000,k\000\000\000\000\000\020test blob\000\000\000".force_encoding("binary"))
|
179
|
-
end.should raise_exception(DecodeError)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
163
|
+
end
|
183
164
|
end
|
data/spec/server_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-osc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.31.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Macario
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rspec
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>='
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 2.6.0
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - '>='
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 2.6.0
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: bundler
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '1.0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '1.0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: eventmachine
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: 0.12.8
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: 0.12.8
|
55
62
|
description: Concise OSC Ruby implementation
|
@@ -76,32 +83,33 @@ files:
|
|
76
83
|
- spec/message_spec.rb
|
77
84
|
- spec/server_spec.rb
|
78
85
|
- spec/spec_helper.rb
|
79
|
-
- streamscanner_benchmark.rb
|
80
86
|
homepage: http://makarius.me
|
81
87
|
licenses: []
|
82
|
-
metadata: {}
|
83
88
|
post_install_message:
|
84
89
|
rdoc_options: []
|
85
90
|
require_paths:
|
86
91
|
- lib
|
87
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
88
94
|
requirements:
|
89
|
-
- - '>='
|
95
|
+
- - ! '>='
|
90
96
|
- !ruby/object:Gem::Version
|
91
97
|
version: '0'
|
92
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
93
100
|
requirements:
|
94
|
-
- - '>='
|
101
|
+
- - ! '>='
|
95
102
|
- !ruby/object:Gem::Version
|
96
103
|
version: '0'
|
97
104
|
requirements: []
|
98
105
|
rubyforge_project: ruby-osc
|
99
|
-
rubygems_version:
|
106
|
+
rubygems_version: 1.8.24
|
100
107
|
signing_key:
|
101
|
-
specification_version:
|
108
|
+
specification_version: 3
|
102
109
|
summary: Concise OSC Ruby implementation
|
103
110
|
test_files:
|
104
111
|
- spec/bundle_spec.rb
|
105
112
|
- spec/message_spec.rb
|
106
113
|
- spec/server_spec.rb
|
107
114
|
- spec/spec_helper.rb
|
115
|
+
has_rdoc:
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: c7a3ed90d79d95eb44be4341b5e0e3cd13b19826
|
4
|
-
data.tar.gz: 860511677129f64f5de77c761c6adce36accad05
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 5508fc05070baa6616cf7494e7a020c313dbfdf5e870e7db58c45e0d7c80cd3f89b054cec32f5bee0bb78615c232c39e7c38bcd8b2f5a53a09471178a8a1efc6
|
7
|
-
data.tar.gz: 3373a2777db15a1c6e4fe73ca7bacc0808ba8fba2ad66653bcd2c46b7e0e687a7f4a4146a9129ffc7c28b493bbe28701b7fe1dea054bf6230e67e0afd904e921
|
data/streamscanner_benchmark.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
|
-
$:.unshift( File.join( File.dirname( __FILE__), 'lib' ) )
|
4
|
-
|
5
|
-
require 'ruby-osc/streamscanner'
|
6
|
-
|
7
|
-
@ss = OSC::StreamScanner.new
|
8
|
-
|
9
|
-
count = 10_000
|
10
|
-
|
11
|
-
Benchmark.bm(23) do |x|
|
12
|
-
x.report("add new string") do
|
13
|
-
count.times do
|
14
|
-
@ss << "/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001".force_encoding("binary")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
x.report("parse string") do
|
19
|
-
count.times do
|
20
|
-
@ss.tryparse
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
x.report("try parse each message") do
|
26
|
-
count.times do
|
27
|
-
OSC::Message.decode("/bar/foo\000\000\000\000,iiii\000\000\000\000\000\000\004\000\000\000\003\000\000\000\002\000\000\000\001".force_encoding("binary"))
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
x.report("parse failure") do
|
32
|
-
count.times do
|
33
|
-
@ss.tryparse rescue nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|