transit-ruby 0.8.572-java → 0.8.586-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd9efa9d2e7a8bda1da0e2e5070ad44075049766
4
- data.tar.gz: bf3e8d7779391c62a6558015e4663efa214cc145
3
+ metadata.gz: 8ba4c772139a74b3be6f8ce528034e96fb1cb0d3
4
+ data.tar.gz: d3908376d545f35d67a9c4cc368fc1301ea9dafc
5
5
  SHA512:
6
- metadata.gz: 404a8b0a1b058825ebc0bd1f181823f977d9c9818dd05923331e3a2e6041caeb8c8a04ffd12f70aba0fd35d1e8c0815b79b8b67aaf422d8c08bbda254f82d989
7
- data.tar.gz: a365ea8f732d373ad6bb323bba1a5541da81d071dc44da584b389b6a4380dc063ba670c1766ec0d37c1efa8b7a08c72780e6544833fd460b90fcee80e6c7f393
6
+ metadata.gz: d2a10f2cbe42c671eead5cdfddbde8e404a4f21b899f0a82aee1be460a0008a56066f2b1dbb18cecc7742c1abad0295620d3b0c5b067aebb9df5f0a96d8f3d0b
7
+ data.tar.gz: 7a3e044915d97cda616ac1ad445a6b320b04536155b900ec88647bf21578a99ff7e3b0b0d5abe96148f1083f1bdb57c2a5cf85bc9e71a278e52b1a4b998d3c69
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 0.8.586 / 2015-03-13
2
+
3
+ * Add handler caching for MRI
4
+ * Bump to transit-java-0.8.285 for handler caching in JRuby
5
+
6
+ ### 0.8.572 / 2015-01-15
7
+
8
+ * Marshal int map keys as ints in msgpack
9
+
1
10
  ### 0.8.569 / 2014-12-03
2
11
 
3
12
  * ByteArray#to_s forces default encoding for platform
data/Jarfile CHANGED
@@ -3,7 +3,7 @@
3
3
  # dependency to transit-java
4
4
  # this setup uses maven central for the repository
5
5
 
6
- jar "com.cognitect:transit-java:0.8.269"
6
+ jar "com.cognitect:transit-java:0.8.285"
7
7
 
8
8
  group 'development' do
9
9
  jar "org.jruby:jruby-complete:1.7.13"
data/lib/transit.jar CHANGED
Binary file
@@ -16,6 +16,9 @@ module Transit
16
16
  # Converts a transit value to an instance of a type
17
17
  # @api private
18
18
  class Decoder
19
+ MUTEX = Mutex.new
20
+ HANDLER_CACHE = {}
21
+
19
22
  ESC_ESC = "#{ESC}#{ESC}"
20
23
  ESC_SUB = "#{ESC}#{SUB}"
21
24
  ESC_RES = "#{ESC}#{RES}"
@@ -27,7 +30,14 @@ module Transit
27
30
  def initialize(options={})
28
31
  custom_handlers = options[:handlers] || {}
29
32
  custom_handlers.each {|k,v| validate_handler(k,v)}
30
- @handlers = ReadHandlers::DEFAULT_READ_HANDLERS.merge(custom_handlers)
33
+ MUTEX.synchronize do
34
+ if HANDLER_CACHE.has_key?(custom_handlers)
35
+ @handlers = HANDLER_CACHE[custom_handlers]
36
+ else
37
+ @handlers = ReadHandlers::DEFAULT_READ_HANDLERS.merge(custom_handlers)
38
+ end
39
+
40
+ end
31
41
  @default_handler = options[:default_handler] || ReadHandlers::DEFAULT_READ_HANDLER
32
42
  end
33
43
 
@@ -17,21 +17,49 @@ module Transit
17
17
  # @see https://github.com/cognitect/transit-format
18
18
  module Marshaler
19
19
 
20
+ HANDLER_CACHE = {}
21
+ VERBOSE_HANDLER_CACHE = {}
22
+ MUTEX = Mutex.new
23
+
24
+ # @api private
25
+ # Included in VerboseJson subclasses. Defined here to make it
26
+ # available in CRuby and JRuby environments.
27
+ module VerboseHandlers
28
+ def build_handlers(custom_handlers)
29
+ if VERBOSE_HANDLER_CACHE.has_key?(custom_handlers)
30
+ VERBOSE_HANDLER_CACHE[custom_handlers]
31
+ else
32
+ handlers = super(custom_handlers).reduce({}) do |h, (k,v)|
33
+ if v.respond_to?(:verbose_handler) && vh = v.verbose_handler
34
+ h.store(k, vh)
35
+ else
36
+ h.store(k, v)
37
+ end
38
+ h
39
+ end
40
+ VERBOSE_HANDLER_CACHE[custom_handlers] = handlers
41
+ handlers
42
+ end
43
+ end
44
+ end
45
+
20
46
  # @api private
21
47
  module Base
22
48
  def parse_options(opts)
23
- @cache_enabled = !opts[:verbose]
24
- @prefer_strings = opts[:prefer_strings]
25
- @max_int = opts[:max_int]
26
- @min_int = opts[:min_int]
27
-
28
- handlers = WriteHandlers::DEFAULT_WRITE_HANDLERS.dup
29
- handlers = handlers.merge!(opts[:handlers]) if opts[:handlers]
30
- @handlers = (opts[:verbose] ? verbose_handlers(handlers) : handlers)
31
- @handlers.values.each do |h|
32
- if h.respond_to?(:handlers=)
33
- h.handlers=(@handlers)
34
- end
49
+ MUTEX.synchronize do
50
+ @handlers = build_handlers(opts[:handlers])
51
+ end
52
+ @handlers.values.each { |h| h.handlers=(@handlers) if h.respond_to?(:handlers=) }
53
+ end
54
+
55
+ def build_handlers(custom_handlers)
56
+ if HANDLER_CACHE.has_key?(custom_handlers)
57
+ HANDLER_CACHE[custom_handlers]
58
+ else
59
+ handlers = WriteHandlers::DEFAULT_WRITE_HANDLERS.dup
60
+ handlers.merge!(custom_handlers) if custom_handlers
61
+ HANDLER_CACHE[custom_handlers] = handlers
62
+ handlers
35
63
  end
36
64
  end
37
65
 
@@ -44,15 +72,6 @@ module Transit
44
72
  nil
45
73
  end
46
74
 
47
- def verbose_handlers(handlers)
48
- handlers.each do |k, v|
49
- if v.respond_to?(:verbose_handler) && vh = v.verbose_handler
50
- handlers.store(k, vh)
51
- end
52
- end
53
- handlers
54
- end
55
-
56
75
  def escape(s)
57
76
  if s.start_with?(SUB,ESC,RES) && s != "#{SUB} "
58
77
  "#{ESC}#{s}"
@@ -67,7 +86,7 @@ module Transit
67
86
 
68
87
  def emit_string(prefix, tag, value, as_map_key, cache)
69
88
  encoded = "#{prefix}#{tag}#{value}"
70
- if @cache_enabled && cache.cacheable?(encoded, as_map_key)
89
+ if cache.cacheable?(encoded, as_map_key)
71
90
  emit_value(cache.write(encoded), as_map_key)
72
91
  else
73
92
  emit_value(encoded, as_map_key)
@@ -15,11 +15,10 @@
15
15
  module Transit
16
16
  module Marshaler
17
17
 
18
+ # @api private
18
19
  module JsonBase
19
- def default_opts
20
- {:prefer_strings => true,
21
- :max_int => JSON_MAX_INT,
22
- :min_int => JSON_MIN_INT}
20
+ def initialize(io, opts)
21
+ parse_options(opts)
23
22
  end
24
23
  end
25
24
 
@@ -27,20 +26,13 @@ module Transit
27
26
  class Json
28
27
  include Transit::Marshaler::Base
29
28
  include Transit::Marshaler::JsonBase
30
-
31
- def initialize(io, opts)
32
- parse_options(default_opts.merge(opts))
33
- end
34
29
  end
35
30
 
36
31
  # @api private
37
32
  class VerboseJson
38
33
  include Transit::Marshaler::Base
39
34
  include Transit::Marshaler::JsonBase
40
-
41
- def initialize(io, opts)
42
- parse_options(default_opts.merge(opts))
43
- end
35
+ include Transit::Marshaler::VerboseHandlers
44
36
  end
45
37
  end
46
38
  end
@@ -17,14 +17,8 @@ module Transit
17
17
  class MessagePack
18
18
  include Transit::Marshaler::Base
19
19
 
20
- def default_opts
21
- {:prefer_strings => false,
22
- :max_int => MAX_INT,
23
- :min_int => MIN_INT}
24
- end
25
-
26
20
  def initialize(io, opts)
27
- parse_options(default_opts.merge(opts))
21
+ parse_options(opts)
28
22
  end
29
23
  end
30
24
  end
@@ -39,21 +39,12 @@ module Transit
39
39
  def initialize(format, io, opts={})
40
40
  @marshaler = case format
41
41
  when :json
42
- Marshaler::Json.new(io,
43
- {:prefer_strings => true,
44
- :verbose => false,
45
- :handlers => {},
46
- :oj_opts => {:indent => -1}}.merge(opts))
42
+ Marshaler::Json.new(io, {:handlers => {},
43
+ :oj_opts => {:indent => -1}}.merge(opts))
47
44
  when :json_verbose
48
- Marshaler::VerboseJson.new(io,
49
- {:prefer_strings => true,
50
- :verbose => true,
51
- :handlers => {}}.merge(opts))
45
+ Marshaler::VerboseJson.new(io, {:handlers => {}}.merge(opts))
52
46
  else
53
- Marshaler::MessagePack.new(io,
54
- {:prefer_strings => false,
55
- :verbose => false,
56
- :handlers => {}}.merge(opts))
47
+ Marshaler::MessagePack.new(io, {:handlers => {}}.merge(opts))
57
48
  end
58
49
  end
59
50
 
@@ -0,0 +1,30 @@
1
+ module Transit
2
+ describe Marshaler do
3
+ it "caches non-verbose handlers" do
4
+ io = StringIO.new
5
+ first = Transit::Marshaler::Json.new(io,{}).instance_variable_get("@handlers")
6
+ second = Transit::Marshaler::Json.new(io,{}).instance_variable_get("@handlers")
7
+ third = Transit::Marshaler::MessagePack.new(io,{}).instance_variable_get("@handlers")
8
+ assert { first }
9
+ assert { first.equal?(second) }
10
+ assert { second.equal?(third) }
11
+ end
12
+
13
+ it "caches verbose handlers" do
14
+ io = StringIO.new
15
+ first = Transit::Marshaler::VerboseJson.new(io,{}).instance_variable_get("@handlers")
16
+ second = Transit::Marshaler::VerboseJson.new(io,{}).instance_variable_get("@handlers")
17
+ assert { first }
18
+ assert { first.equal?(second) }
19
+ end
20
+
21
+ it "caches verbose and non-verbose handlers separately" do
22
+ io = StringIO.new
23
+ first = Transit::Marshaler::Json.new(io,{}).instance_variable_get("@handlers")
24
+ second = Transit::Marshaler::VerboseJson.new(io,{}).instance_variable_get("@handlers")
25
+ assert { first }
26
+ assert { second }
27
+ assert { !first.equal?(second) }
28
+ end
29
+ end
30
+ end
@@ -47,7 +47,12 @@ module Transit
47
47
  writer = Transit::Writer.new(type, io)
48
48
  inputs.each {|i| writer.write(i)}
49
49
  reader = Transit::Reader.new(type, StringIO.new(io.string))
50
- reader.read {|val| outputs << val}
50
+ if Transit::jruby?
51
+ # Ignore expected EOFException raised after the StringIO is exhausted
52
+ reader.read {|val| outputs << val} rescue nil
53
+ else
54
+ reader.read {|val| outputs << val}
55
+ end
51
56
 
52
57
  assert { outputs == inputs }
53
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transit-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.572
4
+ version: 0.8.586
5
5
  platform: java
6
6
  authors:
7
7
  - Russ Olsen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-16 00:00:00.000000000 Z
13
+ date: 2015-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +128,7 @@ files:
128
128
  - spec/transit/date_time_util_spec.rb
129
129
  - spec/transit/decoder_spec.rb
130
130
  - spec/transit/exemplar_spec.rb
131
+ - spec/transit/marshaler_spec.rb
131
132
  - spec/transit/reader_spec.rb
132
133
  - spec/transit/rolling_cache_spec.rb
133
134
  - spec/transit/round_trip_spec.rb
@@ -162,6 +163,7 @@ test_files:
162
163
  - spec/transit/date_time_util_spec.rb
163
164
  - spec/transit/decoder_spec.rb
164
165
  - spec/transit/exemplar_spec.rb
166
+ - spec/transit/marshaler_spec.rb
165
167
  - spec/transit/reader_spec.rb
166
168
  - spec/transit/rolling_cache_spec.rb
167
169
  - spec/transit/round_trip_spec.rb