boss-protocol 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/boss-protocol/version.rb +1 -1
- data/lib/boss-protocol.rb +12 -1
- data/spec/boss_spec.rb +66 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5874e8e0bafe28f14f96860d9e91ea38d0ab1783
|
4
|
+
data.tar.gz: ba1ce2c78a5f90e304f1e9bdc4fe7d3c4617df4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f6d6ca3de1a97e307cafd2aef68e983d21e62d4b237849ebc181d1e83200c845d83d6ab64f1f3eb2f829eb79a0cf93e91e933f507e72ba9dcf31985ee56936c
|
7
|
+
data.tar.gz: 21bbd5e2bff93811da4eac812bcf01c0103a4b95f28a85c7e361731e422f6f87f840b52bf0d858ce08fee289212d4abbef5efb622202e3671c3ffa7f7fd6c4b2
|
data/lib/boss-protocol.rb
CHANGED
@@ -311,7 +311,7 @@ module Boss
|
|
311
311
|
##
|
312
312
|
# write single byte
|
313
313
|
def wbyte(b)
|
314
|
-
@io
|
314
|
+
@io << b.chr
|
315
315
|
end
|
316
316
|
|
317
317
|
def wdouble val
|
@@ -338,6 +338,17 @@ module Boss
|
|
338
338
|
@stream_mode = false
|
339
339
|
end
|
340
340
|
|
341
|
+
##
|
342
|
+
# Load the object (object tree) from the stream. Note that if there
|
343
|
+
# is more than one object in the stream that are stored with the same
|
344
|
+
# Formatter instance, they will share same cache and references,
|
345
|
+
# see Boss.Formatter.put for details.
|
346
|
+
# Note that nil is a valid restored object. Check eof? or catch
|
347
|
+
# EOFError, or use Boss.Parser.each to read all objects from the stream
|
348
|
+
def read
|
349
|
+
get
|
350
|
+
end
|
351
|
+
|
341
352
|
##
|
342
353
|
# Load the object (object tree) from the stream. Note that if there
|
343
354
|
# is more than one object in the stream that are stored with the same
|
data/spec/boss_spec.rb
CHANGED
@@ -5,6 +5,37 @@ require 'json'
|
|
5
5
|
require 'zlib'
|
6
6
|
require 'base64'
|
7
7
|
require 'boss-protocol'
|
8
|
+
require 'socket'
|
9
|
+
|
10
|
+
class SocketStream
|
11
|
+
|
12
|
+
def initialize socket
|
13
|
+
@socket = socket
|
14
|
+
end
|
15
|
+
|
16
|
+
def read length=1
|
17
|
+
# data = ''
|
18
|
+
# while data.length < length
|
19
|
+
# data << @socket.recv(length - data.length, Socket::MSG_WAITALL)
|
20
|
+
# end
|
21
|
+
# data
|
22
|
+
@socket.read length
|
23
|
+
end
|
24
|
+
|
25
|
+
def write data
|
26
|
+
@socket.write data
|
27
|
+
end
|
28
|
+
|
29
|
+
def eof?
|
30
|
+
@socket.eof?
|
31
|
+
end
|
32
|
+
|
33
|
+
def << data
|
34
|
+
write data
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
8
39
|
|
9
40
|
describe 'Boss' do
|
10
41
|
|
@@ -231,6 +262,41 @@ describe 'Boss' do
|
|
231
262
|
b.should == c
|
232
263
|
c.should == d
|
233
264
|
end
|
265
|
+
|
266
|
+
it 'run interoperable' do
|
267
|
+
s1, s2 = Socket.pair(:UNIX, :STREAM, 0)
|
268
|
+
|
269
|
+
out = SocketStream.new(s1)
|
270
|
+
ins = Boss::Parser.new SocketStream.new(s2)
|
271
|
+
|
272
|
+
last = nil
|
273
|
+
t = Thread.start {
|
274
|
+
ins.each { |obj|
|
275
|
+
obj == nil and break
|
276
|
+
last= obj
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
out << Boss.dump( { :cmd => "foo", :args => [], :kwargs => {}, :serial => 0 })
|
281
|
+
out << Boss.dump({ :ref => 0, :error => { "class" => "ArgumentError", "text" => "wrong number of arguments (given 0, expected 2)" }, :serial => 0 })
|
282
|
+
out << Boss.dump( { :cmd => "foo", :args => [10, 20], :kwargs => {}, :serial => 1 })
|
283
|
+
out << Boss.dump( { :ref => 1, :result => "Foo: 30, none", :serial => 1 })
|
284
|
+
out << Boss.dump( { :cmd => "foo", :args => [5, 6], :kwargs => { :optional => "yes!" }, :serial => 2 })
|
285
|
+
out << Boss.dump( { :ref => 2, :result => "Foo: 11, yes!", :serial => 2 })
|
286
|
+
out << Boss.dump( { :cmd => "a", :args => [], :kwargs => {}, :serial => 3 } )
|
287
|
+
out << Boss.dump( { :ref => 3, :result => 5, :serial => 3 } )
|
288
|
+
|
289
|
+
out << Boss.dump( { :cmd => "b", :args => [], :kwargs => {}, :serial => 4 } )
|
290
|
+
out << Boss.dump( { :ref => 4, :result => 6, :serial => 4 } )
|
291
|
+
out << Boss.dump( { :cmd => "get_hash", :args => [], :kwargs => {}, :serial => 5 } )
|
292
|
+
out << Boss.dump( { :ref => 5, :result => { "foo" => "bar", "bardd" => "buzz", "last" => "item", "bar" => "test" }, :serial => 5 } )
|
293
|
+
|
294
|
+
out << Boss.dump(nil)
|
295
|
+
t.join
|
296
|
+
|
297
|
+
last['ref'].should == 5
|
298
|
+
last['result']['foo'].should == 'bar'
|
299
|
+
end
|
234
300
|
|
235
301
|
def round_check(ob)
|
236
302
|
ob.should == Boss.load(Boss.dump(ob))
|