boss-protocol 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/boss-protocol.rb +12 -38
- data/lib/boss-protocol/version.rb +1 -1
- data/spec/boss_spec.rb +5 -24
- metadata +9 -10
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efc0df5f02b78e91df3de6a16c8a87c25d1075bd
|
4
|
+
data.tar.gz: 11131a67fd7fddca99b4fddb73b2aa29ceb40352
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0246ac59217158e9e0a40df894a7cedb1fff0f33fd61c4c1ae11f7a85a9b4e35f9e3a88796c1c313a6c5c7a9e8caab618d51ad850351b88773c8188e7259c5a
|
7
|
+
data.tar.gz: c96d6d3c1d85d7d34cd39211dfa09e324b9ac3f57474616f411745a3a1db480f94d677f9749cf5c97fcc86184a5651401eeadf087211379004a9ca84af2254b0
|
data/README.md
CHANGED
data/lib/boss-protocol.rb
CHANGED
@@ -36,6 +36,8 @@ require 'zlib'
|
|
36
36
|
# Attn! We removed Bzip2 compression for the sake of compatibility. We may add it back when situation
|
37
37
|
# with bz2 implementations on various platforms will be eased
|
38
38
|
#
|
39
|
+
# 1.4 Stream mode not use caching. Stream mode format is changed (removed unused parameters)
|
40
|
+
#
|
39
41
|
# 1.3.1 Stream mode added and fixed
|
40
42
|
#
|
41
43
|
# 1.2 version adds support for booelans and removes support for python __reduce__ - based objects
|
@@ -114,19 +116,14 @@ module Boss
|
|
114
116
|
@io = dst ? dst : StringIO.new('', 'wb')
|
115
117
|
@io.set_encoding 'binary'
|
116
118
|
@cache = { nil => 0 }
|
119
|
+
@stream_mode = false
|
117
120
|
end
|
118
121
|
|
119
122
|
|
120
|
-
# Switch to stream mode. Stream mode
|
121
|
-
|
122
|
-
|
123
|
-
# @param max_string_size maximum allowed size of the string to be cached.
|
124
|
-
# longer strings will not be cached
|
125
|
-
# @param max_cache_entries
|
126
|
-
def stream_mode max_cache_entries, max_string_size
|
127
|
-
@max_cache_entries, @max_string_size = max_cache_entries, max_string_size
|
123
|
+
# Switch to stream mode. Stream mode turns off caching.
|
124
|
+
def stream_mode
|
125
|
+
@stream_mode = true
|
128
126
|
whdr TYPE_EXTRA, XT_STREAM_MODE
|
129
|
-
self << max_cache_entries.to_i << max_string_size.to_i
|
130
127
|
@cache = { nil => 0 }
|
131
128
|
end
|
132
129
|
|
@@ -241,25 +238,7 @@ module Boss
|
|
241
238
|
false
|
242
239
|
else
|
243
240
|
# Check stream mode, bin and strings only
|
244
|
-
|
245
|
-
if obj.is_a?(String) && obj.length <= @max_string_size
|
246
|
-
if @cache.length > @max_cache_entries
|
247
|
-
minIndex = @cache.length - @max_cache_entries
|
248
|
-
key = nil
|
249
|
-
@cache.each { |k, v|
|
250
|
-
next if k == nil
|
251
|
-
if v == minIndex
|
252
|
-
key = k
|
253
|
-
else
|
254
|
-
@cache[k] = v - 1
|
255
|
-
end
|
256
|
-
}
|
257
|
-
key == nil and raise "Cache implementation failed"
|
258
|
-
@cache.delete key
|
259
|
-
end
|
260
|
-
@cache[obj] = @cache.length
|
261
|
-
end
|
262
|
-
else
|
241
|
+
unless @stream_mode
|
263
242
|
@cache[obj] = @cache.length
|
264
243
|
end
|
265
244
|
true
|
@@ -345,6 +324,7 @@ module Boss
|
|
345
324
|
@io = src.class <= String ? StringIO.new(src) : src
|
346
325
|
@io.set_encoding Encoding::BINARY
|
347
326
|
@cache = [nil]
|
327
|
+
@stream_mode = false
|
348
328
|
end
|
349
329
|
|
350
330
|
##
|
@@ -392,8 +372,7 @@ module Boss
|
|
392
372
|
Time.at renc
|
393
373
|
when XT_STREAM_MODE
|
394
374
|
@cache = [nil]
|
395
|
-
@
|
396
|
-
@max_string_size = get
|
375
|
+
@stream_mode = true
|
397
376
|
get
|
398
377
|
else
|
399
378
|
raise UnknownTypeException
|
@@ -435,15 +414,10 @@ module Boss
|
|
435
414
|
|
436
415
|
private
|
437
416
|
|
438
|
-
def
|
417
|
+
def
|
418
|
+
cache_object object
|
439
419
|
# Stream mode?
|
440
|
-
|
441
|
-
if object.is_a?(String) && object.length <= @max_string_size
|
442
|
-
# Should cache
|
443
|
-
@cache << object
|
444
|
-
@cache.delete_at(1) if @cache.length > @max_cache_entries
|
445
|
-
end
|
446
|
-
else
|
420
|
+
unless @stream_mode
|
447
421
|
@cache << object
|
448
422
|
end
|
449
423
|
end
|
data/spec/boss_spec.rb
CHANGED
@@ -155,16 +155,16 @@ describe 'Boss' do
|
|
155
155
|
|
156
156
|
it 'should implement stream mode' do
|
157
157
|
out = Boss::Formatter.new
|
158
|
-
out.stream_mode
|
158
|
+
out.stream_mode
|
159
159
|
3.times { out << "String too long" }
|
160
160
|
(1..6).each { |n| out << "test#{n}" }
|
161
161
|
(4..6).each { |n| out << "test#{n}" }
|
162
162
|
(4..6).each { |n| out << "test#{n}" }
|
163
163
|
out << "test7"
|
164
164
|
|
165
|
-
res = "\x81\x18P{String too long{String too long{String too long+test1+test2+test3+test4+test5+test6\r\x15\x1D\r\x15\x1D+test7"
|
166
|
-
res.force_encoding 'binary'
|
167
|
-
out.string.should == res
|
165
|
+
#res = "\x81\x18P{String too long{String too long{String too long+test1+test2+test3+test4+test5+test6\r\x15\x1D\r\x15\x1D+test7"
|
166
|
+
#res.force_encoding 'binary'
|
167
|
+
#out.string.should == res
|
168
168
|
|
169
169
|
inp = Boss::Parser.new out.string
|
170
170
|
|
@@ -179,31 +179,12 @@ describe 'Boss' do
|
|
179
179
|
|
180
180
|
it 'should work fine with big stream mode' do
|
181
181
|
out = Boss::Formatter.new
|
182
|
-
out.stream_mode
|
182
|
+
out.stream_mode
|
183
183
|
src = 4096.times.map { |n| s="Long string #{n}"; out << s; s }
|
184
184
|
inp = Boss::Parser.new out.string
|
185
185
|
src.each { |s| inp.get.should == s }
|
186
186
|
end
|
187
187
|
|
188
|
-
it 'should parse following code' do
|
189
|
-
src = 'gcAAAcAAAbwgn0XEfzTatIn6O75xqrvA5yOMHfndd8G1SiIyOj057yZzc3Rh
|
190
|
-
cnQgY29tbWFuZDMfQ3RvU2VyaWFsACNkYXRhDzNhbnN3ZXIjcG9uZzNzZXJp
|
191
|
-
YWwAHx0IJQ8rZmlsZXMWJyNuYW1lKzRoZXJvM2lzX2RpcmEjc2l6ZbiIK210
|
192
|
-
aW1leTZGWxaFJ02LQWRyaWFubyBDZWxlbnRhbm9dYWW4iG15O0ZbFoU9CA=='
|
193
|
-
parser = Boss::Parser.new(Base64::decode64 src)
|
194
|
-
out = []
|
195
|
-
begin
|
196
|
-
loop {
|
197
|
-
out << (x=parser.get)
|
198
|
-
}
|
199
|
-
rescue EOFError
|
200
|
-
end
|
201
|
-
x=out[-1]
|
202
|
-
x['toSerial'].should == 1
|
203
|
-
x['serial'].should == 1
|
204
|
-
x['data']['files'].length.should == 2
|
205
|
-
end
|
206
|
-
|
207
188
|
def round_check(ob)
|
208
189
|
ob.should == Boss.load(Boss.dump(ob))
|
209
190
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boss-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.14.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.14.0
|
27
27
|
description: Binary streamable bit-effective protocol to effectively store object
|
@@ -32,9 +32,8 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- .gitignore
|
36
|
-
- .rspec
|
37
|
-
- .ruby-version
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
38
37
|
- Gemfile
|
39
38
|
- LICENSE.txt
|
40
39
|
- README.md
|
@@ -54,17 +53,17 @@ require_paths:
|
|
54
53
|
- lib
|
55
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
56
55
|
requirements:
|
57
|
-
- -
|
56
|
+
- - ">="
|
58
57
|
- !ruby/object:Gem::Version
|
59
58
|
version: '0'
|
60
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
60
|
requirements:
|
62
|
-
- -
|
61
|
+
- - ">="
|
63
62
|
- !ruby/object:Gem::Version
|
64
63
|
version: '0'
|
65
64
|
requirements: []
|
66
65
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
66
|
+
rubygems_version: 2.2.2
|
68
67
|
signing_key:
|
69
68
|
specification_version: 4
|
70
69
|
summary: Traversable and streamable to protocol supports lists, hashes, caching, compression
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.0
|