msgpack-jruby 1.2.0-java → 1.3.0-java
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/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm --create use jruby-1.
|
1
|
+
rvm --create use jruby-1.7.1@msgpack-jruby
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ task :package => :compile do
|
|
20
20
|
exit($?.exitstatus) unless $?.success?
|
21
21
|
end
|
22
22
|
|
23
|
-
task :release do
|
23
|
+
task :release => :package do
|
24
24
|
version_string = "v#{MessagePack::VERSION}"
|
25
25
|
unless %x(git tag -l).include?(version_string)
|
26
26
|
system %(git tag -a #{version_string} -m #{version_string})
|
@@ -91,7 +91,7 @@ public class MessagePackLibrary implements Library {
|
|
91
91
|
private MessagePackUnpacker streamUnpacker;
|
92
92
|
private IRubyObject stream;
|
93
93
|
private IRubyObject data;
|
94
|
-
private
|
94
|
+
private RubyObjectUnpacker.CompiledOptions options;
|
95
95
|
|
96
96
|
public Unpacker(Ruby runtime, RubyClass type, MessagePack msgPack) {
|
97
97
|
super(runtime, type);
|
@@ -106,13 +106,15 @@ public class MessagePackLibrary implements Library {
|
|
106
106
|
@JRubyMethod(name = "initialize", optional = 2, visibility = PRIVATE)
|
107
107
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
108
108
|
if (args.length == 0) {
|
109
|
-
options =
|
109
|
+
options = new RubyObjectUnpacker.CompiledOptions();
|
110
110
|
} else if (args.length == 1 && args[0] instanceof RubyHash) {
|
111
|
-
options = (RubyHash) args[0];
|
111
|
+
options = new RubyObjectUnpacker.CompiledOptions((RubyHash) args[0]);
|
112
112
|
} else if (args.length > 0) {
|
113
113
|
setStream(ctx, args[0]);
|
114
114
|
if (args.length > 2) {
|
115
|
-
options = (RubyHash) args[1];
|
115
|
+
options = new RubyObjectUnpacker.CompiledOptions((RubyHash) args[1]);
|
116
|
+
} else {
|
117
|
+
options = new RubyObjectUnpacker.CompiledOptions();
|
116
118
|
}
|
117
119
|
}
|
118
120
|
return this;
|
@@ -30,6 +30,8 @@ import org.jruby.RubyHash;
|
|
30
30
|
import org.jruby.runtime.builtin.IRubyObject;
|
31
31
|
import org.jruby.runtime.ThreadContext;
|
32
32
|
|
33
|
+
import org.jcodings.Encoding;
|
34
|
+
|
33
35
|
|
34
36
|
public class RubyObjectUnpacker {
|
35
37
|
private final MessagePack msgPack;
|
@@ -38,17 +40,49 @@ public class RubyObjectUnpacker {
|
|
38
40
|
this.msgPack = msgPack;
|
39
41
|
}
|
40
42
|
|
43
|
+
public static class CompiledOptions {
|
44
|
+
public final boolean symbolizeKeys;
|
45
|
+
public final Encoding encoding;
|
46
|
+
|
47
|
+
public CompiledOptions() {
|
48
|
+
this(null);
|
49
|
+
}
|
50
|
+
|
51
|
+
public CompiledOptions(RubyHash options) {
|
52
|
+
if (options == null) {
|
53
|
+
symbolizeKeys = false;
|
54
|
+
encoding = null;
|
55
|
+
} else {
|
56
|
+
Ruby runtime = options.getRuntime();
|
57
|
+
ThreadContext ctx = runtime.getCurrentContext();
|
58
|
+
RubySymbol key = runtime.newSymbol("symbolize_keys");
|
59
|
+
IRubyObject value = options.fastARef(key);
|
60
|
+
symbolizeKeys = value != null && value.isTrue();
|
61
|
+
IRubyObject rubyEncoding = options.fastARef(runtime.newSymbol("encoding"));
|
62
|
+
encoding = runtime.getEncodingService().getEncodingFromObject(rubyEncoding);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
41
67
|
public IRubyObject unpack(RubyString str, RubyHash options) throws IOException {
|
42
|
-
return unpack(str.getRuntime(), str.getBytes(), options);
|
68
|
+
return unpack(str.getRuntime(), str.getBytes(), new CompiledOptions(options));
|
43
69
|
}
|
44
70
|
|
45
71
|
public IRubyObject unpack(Ruby runtime, byte[] data, RubyHash options) throws IOException {
|
72
|
+
return unpack(runtime, data, new CompiledOptions(options));
|
73
|
+
}
|
74
|
+
|
75
|
+
public IRubyObject unpack(Ruby runtime, byte[] data, CompiledOptions options) throws IOException {
|
46
76
|
MessagePackBufferUnpacker unpacker = new MessagePackBufferUnpacker(msgPack);
|
47
77
|
unpacker.wrap(data);
|
48
78
|
return valueToRubyObject(runtime, unpacker.readValue(), options);
|
49
79
|
}
|
50
80
|
|
51
|
-
IRubyObject valueToRubyObject(Ruby runtime, Value value, RubyHash options) {
|
81
|
+
IRubyObject valueToRubyObject(Ruby runtime, Value value, RubyHash options) throws IOException {
|
82
|
+
return valueToRubyObject(runtime, value, new CompiledOptions(options));
|
83
|
+
}
|
84
|
+
|
85
|
+
IRubyObject valueToRubyObject(Ruby runtime, Value value, CompiledOptions options) {
|
52
86
|
switch (value.getType()) {
|
53
87
|
case NIL:
|
54
88
|
return runtime.getNil();
|
@@ -63,7 +97,7 @@ public class RubyObjectUnpacker {
|
|
63
97
|
case MAP:
|
64
98
|
return convert(runtime, value.asMapValue(), options);
|
65
99
|
case RAW:
|
66
|
-
return convert(runtime, value.asRawValue());
|
100
|
+
return convert(runtime, value.asRawValue(), options);
|
67
101
|
default:
|
68
102
|
throw runtime.newArgumentError(String.format("Unexpected value: %s", value.toString()));
|
69
103
|
}
|
@@ -87,7 +121,7 @@ public class RubyObjectUnpacker {
|
|
87
121
|
return RubyFloat.newFloat(runtime, value.asFloatValue().getDouble());
|
88
122
|
}
|
89
123
|
|
90
|
-
private IRubyObject convert(Ruby runtime, ArrayValue value,
|
124
|
+
private IRubyObject convert(Ruby runtime, ArrayValue value, CompiledOptions options) {
|
91
125
|
Value[] elements = value.asArrayValue().getElementArray();
|
92
126
|
int elementCount = elements.length;
|
93
127
|
IRubyObject[] rubyObjects = new IRubyObject[elementCount];
|
@@ -97,7 +131,7 @@ public class RubyObjectUnpacker {
|
|
97
131
|
return RubyArray.newArray(runtime, rubyObjects);
|
98
132
|
}
|
99
133
|
|
100
|
-
private IRubyObject convert(Ruby runtime, MapValue value,
|
134
|
+
private IRubyObject convert(Ruby runtime, MapValue value, CompiledOptions options) {
|
101
135
|
Value[] keysAndValues = value.asMapValue().getKeyValueArray();
|
102
136
|
int kvCount = keysAndValues.length;
|
103
137
|
RubyHash hash = RubyHash.newHash(runtime);
|
@@ -106,7 +140,7 @@ public class RubyObjectUnpacker {
|
|
106
140
|
Value v = keysAndValues[i + 1];
|
107
141
|
IRubyObject kk = valueToRubyObject(runtime, k, options);
|
108
142
|
IRubyObject vv = valueToRubyObject(runtime, v, options);
|
109
|
-
if (
|
143
|
+
if (options.symbolizeKeys) {
|
110
144
|
kk = runtime.newSymbol(kk.asString().getByteList());
|
111
145
|
}
|
112
146
|
hash.put(kk, vv);
|
@@ -114,23 +148,11 @@ public class RubyObjectUnpacker {
|
|
114
148
|
return hash;
|
115
149
|
}
|
116
150
|
|
117
|
-
private IRubyObject convert(Ruby runtime, RawValue value) {
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
private boolean symbolizeKeysEnabled(RubyHash options) {
|
122
|
-
if (options == null) {
|
123
|
-
return false;
|
124
|
-
} else {
|
125
|
-
Ruby runtime = options.getRuntime();
|
126
|
-
ThreadContext ctx = runtime.getCurrentContext();
|
127
|
-
RubySymbol key = runtime.newSymbol("symbolize_keys");
|
128
|
-
IRubyObject value = options.fastARef(key);
|
129
|
-
if (value == null) {
|
130
|
-
return false;
|
131
|
-
} else {
|
132
|
-
return value.isTrue();
|
133
|
-
}
|
151
|
+
private IRubyObject convert(Ruby runtime, RawValue value, CompiledOptions options) {
|
152
|
+
RubyString string = RubyString.newString(runtime, value.asRawValue().getByteArray());
|
153
|
+
if (options.encoding != null) {
|
154
|
+
string.setEncoding(options.encoding);
|
134
155
|
}
|
156
|
+
return string;
|
135
157
|
}
|
136
158
|
}
|
data/lib/ext/msgpack_jruby.jar
CHANGED
Binary file
|
data/lib/msgpack/version.rb
CHANGED
@@ -189,5 +189,57 @@ describe ::MessagePack::Unpacker do
|
|
189
189
|
objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}]
|
190
190
|
end
|
191
191
|
end
|
192
|
+
|
193
|
+
context 'encoding' do
|
194
|
+
|
195
|
+
def flatten(struct, results = [])
|
196
|
+
case struct
|
197
|
+
when Array
|
198
|
+
struct.each { |v| flatten(v, results) }
|
199
|
+
when Hash
|
200
|
+
struct.each { |k, v| flatten(v, flatten(k, results)) }
|
201
|
+
else
|
202
|
+
results << struct
|
203
|
+
end
|
204
|
+
results
|
205
|
+
end
|
206
|
+
|
207
|
+
let :buffer do
|
208
|
+
MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]})
|
209
|
+
end
|
210
|
+
|
211
|
+
let :unpacker do
|
212
|
+
described_class.new(:encoding => 'UTF-8')
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'can symbolize keys when using #execute' do
|
216
|
+
unpacker.execute(buffer, 0)
|
217
|
+
strings = flatten(unpacker.data).grep(String)
|
218
|
+
strings.should == %w[hello world nested object structure]
|
219
|
+
strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'can symbolize keys when using #each' do
|
223
|
+
objs = []
|
224
|
+
unpacker.feed(buffer)
|
225
|
+
unpacker.each do |obj|
|
226
|
+
objs << obj
|
227
|
+
end
|
228
|
+
strings = flatten(objs).grep(String)
|
229
|
+
strings.should == %w[hello world nested object structure]
|
230
|
+
strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'can symbolize keys when using #feed_each' do
|
234
|
+
objs = []
|
235
|
+
unpacker.feed_each(buffer) do |obj|
|
236
|
+
objs << obj
|
237
|
+
end
|
238
|
+
strings = flatten(objs).grep(String)
|
239
|
+
strings.should == %w[hello world nested object structure]
|
240
|
+
strings.map(&:encoding).uniq.should == [Encoding::UTF_8]
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
192
244
|
end
|
193
245
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack-jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 1.2.0
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Theo Hultberg
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: JRuby compatible MessagePack implementation that does not use FFI
|
15
15
|
email:
|
@@ -52,20 +52,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
segments:
|
54
54
|
- 0
|
55
|
+
version: !binary |-
|
56
|
+
MA==
|
55
57
|
hash: 2
|
56
|
-
version: '0'
|
57
58
|
none: false
|
58
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
60
|
requirements:
|
60
61
|
- - ! '>='
|
61
62
|
- !ruby/object:Gem::Version
|
62
|
-
version:
|
63
|
+
version: !binary |-
|
64
|
+
MA==
|
63
65
|
none: false
|
64
66
|
requirements: []
|
65
67
|
rubyforge_project: msgpack-jruby
|
66
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.24
|
67
69
|
signing_key:
|
68
70
|
specification_version: 3
|
69
71
|
summary: MessagePack implementation for JRuby
|
70
72
|
test_files: []
|
71
|
-
...
|