boss-protocol 1.4.1 → 1.4.2
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +4 -7
- data/lib/boss-protocol.rb +32 -23
- data/lib/boss-protocol/version.rb +1 -1
- data/spec/boss_spec.rb +49 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b396f11246208a61e308b3aacbd4f4f9ccb23e32
|
4
|
+
data.tar.gz: c6ec201f8e6c42f079660614c58e8185f9a8f486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0b5291588eac732637fe136d454e9e0ac486a00a18d1a0055ea0934b89d4d9f143574248d95d8328ea2edcb908ff8e7b077ef1509d11d9890d26afcaa63fe34
|
7
|
+
data.tar.gz: 175de9dc48ad4f4f8404f171c693a74ea63aad4a5b8ef1e6946719c38edd8d6d976503c60e469f8ac8c09b3aeb77a656f8075f8c9a7f793e29c042a3b98bc71b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -40,15 +40,12 @@ Supported types:
|
|
40
40
|
* Boolean values (true/false)
|
41
41
|
* UTF-8 encoded texts, any length
|
42
42
|
* Binary data, any length
|
43
|
-
* Time objects (date and time
|
44
|
-
* Arrays with any number of elements
|
43
|
+
* Time objects (date and time with 1 second resolution)
|
44
|
+
* Arrays with any number of elements of any type
|
45
45
|
* Hashes with any keys and values and unlimited length
|
46
|
-
* Reference to the object that already was serialized
|
46
|
+
* Reference to the object that already was serialized (unless in stream mode)
|
47
47
|
|
48
|
-
There is a
|
49
|
-
soon or even faster - leave me a request in issues. There are also versions
|
50
|
-
in C and Python that are in most part ready but are parts
|
51
|
-
in other systems and need to be extracted first.
|
48
|
+
There is a working JAVA implemetation also.
|
52
49
|
|
53
50
|
## Installation
|
54
51
|
|
data/lib/boss-protocol.rb
CHANGED
@@ -31,14 +31,15 @@ require 'zlib'
|
|
31
31
|
#
|
32
32
|
|
33
33
|
##
|
34
|
-
# Boss protocol version 1.
|
34
|
+
# Boss protocol version 1.4 full implementation
|
35
35
|
#
|
36
|
-
#
|
37
|
-
# with bz2 implementations on various platforms will be eased
|
36
|
+
# Attentionn! Bzip2 compression was removed for the sake of compatibility.
|
38
37
|
#
|
39
|
-
# 1.4 Stream mode not use caching
|
38
|
+
# 1.4 Stream mode do not use caching anymore (not effective while slow).
|
39
|
+
# Stream mode format is changed (removed unused parameters)
|
40
40
|
#
|
41
41
|
# 1.3.1 Stream mode added and fixed
|
42
|
+
# 1.3
|
42
43
|
#
|
43
44
|
# 1.2 version adds support for booelans and removes support for python __reduce__ - based objects
|
44
45
|
# as absolutely non portable. It also introduces
|
@@ -68,21 +69,21 @@ module Boss
|
|
68
69
|
TYPE_LIST = 6
|
69
70
|
TYPE_DICT = 7
|
70
71
|
|
71
|
-
|
72
|
+
# Extra types:
|
72
73
|
|
73
|
-
DZERO = 0
|
74
|
-
FZERO = 1
|
74
|
+
DZERO = 0 #: float 0.0
|
75
|
+
FZERO = 1 #: double 0.0
|
75
76
|
|
76
|
-
DONE = 2
|
77
|
-
FONE = 3
|
78
|
-
DMINUSONE = 4
|
79
|
-
FMINUSONE = 5
|
77
|
+
DONE = 2 #: double 1.0
|
78
|
+
FONE = 3 #: float 1.0
|
79
|
+
DMINUSONE = 4 #: double -1.0
|
80
|
+
FMINUSONE = 5 #: float -1.0
|
80
81
|
|
81
|
-
TFLOAT = 6
|
82
|
-
TDOUBLE = 7
|
82
|
+
TFLOAT = 6 #: 32-bit IEEE float
|
83
|
+
TDOUBLE = 7 #: 64-bit IEEE float
|
83
84
|
|
84
|
-
TOBJECT = 8
|
85
|
-
TMETHOD = 9
|
85
|
+
TOBJECT = 8 #: object record
|
86
|
+
TMETHOD = 9 #: instance method
|
86
87
|
TFUNCTION = 10 #: callable function
|
87
88
|
TGLOBREF = 11 #: global reference
|
88
89
|
|
@@ -114,14 +115,23 @@ module Boss
|
|
114
115
|
#
|
115
116
|
def initialize(dst=nil)
|
116
117
|
@io = dst ? dst : StringIO.new('', 'wb')
|
117
|
-
@io.set_encoding
|
118
|
-
@cache
|
118
|
+
@io.set_encoding Encoding::BINARY if @io.respond_to? :set_encoding
|
119
|
+
@cache = { nil => 0 }
|
119
120
|
@stream_mode = false
|
120
121
|
end
|
121
122
|
|
123
|
+
def get_stream
|
124
|
+
@io
|
125
|
+
end
|
126
|
+
|
122
127
|
|
123
128
|
# Switch to stream mode. Stream mode turns off caching.
|
124
129
|
def stream_mode
|
130
|
+
set_stream_mode
|
131
|
+
end
|
132
|
+
|
133
|
+
# Switch to stream mode. Stream mode turns off caching.
|
134
|
+
def set_stream_mode
|
125
135
|
@stream_mode = true
|
126
136
|
whdr TYPE_EXTRA, XT_STREAM_MODE
|
127
137
|
@cache = { nil => 0 }
|
@@ -157,7 +167,7 @@ module Boss
|
|
157
167
|
# has per-instance cache so put(x) put(x) put(x)
|
158
168
|
# will store one object and 2 more refs to it, so
|
159
169
|
# on load time only one object will be constructed and
|
160
|
-
# 2 more refs will be
|
170
|
+
# 2 more refs will be created.
|
161
171
|
def put(ob)
|
162
172
|
case ob
|
163
173
|
when Fixnum, Bignum
|
@@ -323,8 +333,8 @@ module Boss
|
|
323
333
|
def initialize(src=nil)
|
324
334
|
@io = src.class <= String ? StringIO.new(src) : src
|
325
335
|
@io.set_encoding Encoding::BINARY if @io.respond_to? :set_encoding
|
326
|
-
@rbyte
|
327
|
-
@cache
|
336
|
+
@rbyte = @io.respond_to?(:readbyte) ? -> { @io.readbyte } : -> { @io.read(1).ord }
|
337
|
+
@cache = [nil]
|
328
338
|
@stream_mode = false
|
329
339
|
end
|
330
340
|
|
@@ -372,7 +382,7 @@ module Boss
|
|
372
382
|
when TTIME
|
373
383
|
Time.at renc
|
374
384
|
when XT_STREAM_MODE
|
375
|
-
@cache
|
385
|
+
@cache = [nil]
|
376
386
|
@stream_mode = true
|
377
387
|
get
|
378
388
|
else
|
@@ -415,8 +425,7 @@ module Boss
|
|
415
425
|
|
416
426
|
private
|
417
427
|
|
418
|
-
def
|
419
|
-
cache_object object
|
428
|
+
def cache_object object
|
420
429
|
# Stream mode?
|
421
430
|
unless @stream_mode
|
422
431
|
@cache << object
|
data/spec/boss_spec.rb
CHANGED
@@ -101,7 +101,7 @@ describe 'Boss' do
|
|
101
101
|
round_check root
|
102
102
|
end
|
103
103
|
|
104
|
-
it '
|
104
|
+
it 'should encode hash/array ancestors too' do
|
105
105
|
class MyHash < Hash
|
106
106
|
def []= k, v
|
107
107
|
super k.to_s, v.to_s
|
@@ -126,6 +126,37 @@ describe 'Boss' do
|
|
126
126
|
|
127
127
|
end
|
128
128
|
|
129
|
+
it 'sends and restores foobars1' do
|
130
|
+
# stupid error
|
131
|
+
src = { :ref => 7, :result => { "foo" => "bar", "bardd" => "buzz", "last" => "item", "bar" => "test", arr: 10.times.map { 'bar' } }, :serial => 7 }
|
132
|
+
f = Boss::Formatter.new
|
133
|
+
f.set_stream_mode
|
134
|
+
f << src
|
135
|
+
# p f.get_stream.string
|
136
|
+
encoded = f.get_stream.string
|
137
|
+
ins = Boss::Parser.new(encoded)
|
138
|
+
ins.each { |res|
|
139
|
+
# p res
|
140
|
+
res['result']['bar'].should == 'test'
|
141
|
+
res['result']['arr'].should == 10.times.map { 'bar' }
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'sends and restores foobars2' do
|
146
|
+
# stupid error
|
147
|
+
src = { :ref => 7, :result => { "foo" => "bar", "bardd" => "buzz", "last" => "item", "bar" => "test", arr: 10.times.map { 'bar' } }, :serial => 7 }
|
148
|
+
f = Boss::Formatter.new
|
149
|
+
f << src
|
150
|
+
# p f.get_stream.string
|
151
|
+
encoded = f.get_stream.string
|
152
|
+
ins = Boss::Parser.new(encoded)
|
153
|
+
ins.each { |res|
|
154
|
+
# p res
|
155
|
+
res['result']['arr'].should == 10.times.map { 'bar' }
|
156
|
+
res['result']['bar'].should == 'test'
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
129
160
|
it 'should effectively compress/decompress' do
|
130
161
|
# No compression
|
131
162
|
data = "Too short"
|
@@ -185,6 +216,22 @@ describe 'Boss' do
|
|
185
216
|
src.each { |s| inp.get.should == s }
|
186
217
|
end
|
187
218
|
|
219
|
+
it 'should work in mixed normal and stream modes' do
|
220
|
+
s1 = "The string"
|
221
|
+
out = Boss::Formatter.new
|
222
|
+
out << s1 << s1
|
223
|
+
out.stream_mode
|
224
|
+
out << s1 << s1
|
225
|
+
# p Base64.encode64(out.string)
|
226
|
+
input = Boss::Parser.new out.string
|
227
|
+
a, b, c, d = 4.times.map { input.get }
|
228
|
+
b.__id__.should_not == c.__id__
|
229
|
+
c.__id__.should_not == d.__id__
|
230
|
+
a.should == b
|
231
|
+
b.should == c
|
232
|
+
c.should == d
|
233
|
+
end
|
234
|
+
|
188
235
|
def round_check(ob)
|
189
236
|
ob.should == Boss.load(Boss.dump(ob))
|
190
237
|
end
|
@@ -533,4 +580,4 @@ ZPRlks8o0Gc+RzbVHfjjBc+8ffGnPSaQaU6ZDxOCIu82CDqxTouy6UhoFPN1
|
|
533
580
|
NhpXhYHtuZti57hJEhySiPp/f/3XX//1/wEcUSZF
|
534
581
|
End
|
535
582
|
|
536
|
-
end
|
583
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boss-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version: 2.
|
66
|
+
rubygems_version: 2.5.1
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Traversable and streamable to protocol supports lists, hashes, caching, compression
|