msgpack 1.4.2 → 1.4.3
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/.github/workflows/ci.yaml +56 -0
- data/ChangeLog +8 -0
- data/Rakefile +2 -2
- data/doclib/msgpack/factory.rb +1 -0
- data/ext/java/org/msgpack/jruby/Buffer.java +17 -16
- data/ext/java/org/msgpack/jruby/Decoder.java +6 -2
- data/ext/java/org/msgpack/jruby/Encoder.java +22 -12
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +9 -9
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
- data/ext/java/org/msgpack/jruby/Factory.java +7 -2
- data/ext/java/org/msgpack/jruby/Packer.java +11 -9
- data/ext/java/org/msgpack/jruby/Unpacker.java +30 -28
- data/ext/msgpack/buffer.c +0 -5
- data/ext/msgpack/buffer.h +5 -0
- data/ext/msgpack/extconf.rb +0 -7
- data/ext/msgpack/factory_class.c +10 -5
- data/ext/msgpack/packer.c +18 -5
- data/ext/msgpack/packer.h +0 -9
- data/ext/msgpack/packer_class.c +0 -9
- data/ext/msgpack/packer_ext_registry.c +0 -22
- data/ext/msgpack/unpacker.c +28 -22
- data/ext/msgpack/unpacker.h +2 -0
- data/ext/msgpack/unpacker_class.c +0 -5
- data/lib/msgpack/symbol.rb +14 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +1 -2
- data/spec/factory_spec.rb +17 -0
- data/spec/msgpack_spec.rb +1 -1
- data/spec/packer_spec.rb +18 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/timestamp_spec.rb +40 -0
- data/spec/unpacker_spec.rb +10 -1
- metadata +4 -4
- data/.travis.yml +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 750c05b37865e3da4e2ca909840dfb4afd732799f756a89465c26f2e6e77ef91
|
4
|
+
data.tar.gz: afc8dfd5103e65068fa054d7daf2811c65fbb7627e2986a1a50ad0307d643113
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01af679c600ae449256f30a3beb5f9993266e1e8bcd11e5ec8e635301a713c3175131e112540660d8adc67ae06470043eee48d1a3b1ecc69b2e436eb0010579c
|
7
|
+
data.tar.gz: 13a82671e440447415c22d930dd795d4f1d6e07ea9328078ed25c887890bbc27080f38fb5d33da6cb15dc8dac2789e3a930548a64d298b1ca44b510bb3978d5f
|
@@ -0,0 +1,56 @@
|
|
1
|
+
name: ci
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches: '*'
|
6
|
+
push:
|
7
|
+
branches:
|
8
|
+
- master
|
9
|
+
- main
|
10
|
+
- 'release-*'
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
mri:
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
os: [ubuntu, macos, windows]
|
17
|
+
ruby: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1']
|
18
|
+
runs-on: ${{ matrix.os }}-latest
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
- run: bundle install
|
25
|
+
- run: bundle exec rake
|
26
|
+
|
27
|
+
jruby:
|
28
|
+
strategy:
|
29
|
+
matrix:
|
30
|
+
os: [ubuntu]
|
31
|
+
# TODO: update to 9.3.3.0 once supported
|
32
|
+
# https://github.com/ruby/setup-ruby#supported-versions
|
33
|
+
ruby: ['jruby-9.2.19.0', 'jruby-9.3.2.0']
|
34
|
+
runs-on: ${{ matrix.os }}-latest
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v2
|
37
|
+
- uses: ruby/setup-ruby@v1
|
38
|
+
with:
|
39
|
+
ruby-version: ${{ matrix.ruby }}
|
40
|
+
- run: bundle install
|
41
|
+
- run: bundle exec rake
|
42
|
+
|
43
|
+
head-versions:
|
44
|
+
continue-on-error: true
|
45
|
+
strategy:
|
46
|
+
matrix:
|
47
|
+
os: [ubuntu]
|
48
|
+
ruby: ['ruby-head', 'jruby-head', 'truffleruby']
|
49
|
+
runs-on: ${{ matrix.os }}-latest
|
50
|
+
steps:
|
51
|
+
- uses: actions/checkout@v2
|
52
|
+
- uses: ruby/setup-ruby@v1
|
53
|
+
with:
|
54
|
+
ruby-version: ${{ matrix.ruby }}
|
55
|
+
- run: bundle install
|
56
|
+
- run: bundle exec rake || echo "failed, but ignore it"
|
data/ChangeLog
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
2022-01-20 version 1.4.3:
|
2
|
+
|
3
|
+
* Optimize serialization/deserialization of Symbols
|
4
|
+
* Support registering ext types for objects of subclasses of primitive types (like Hash)
|
5
|
+
* Add optimized_symbols_parsing option to Factory#register_type on MRI implementation
|
6
|
+
* Optimize to deduplicate Hash keys on JRuby
|
7
|
+
* Support JRuby 9.3 (and drop 9.1)
|
8
|
+
|
1
9
|
2021-02-01 version 1.4.2:
|
2
10
|
|
3
11
|
* Add the required Ruby version (>= 2.4) to avoid compilation errors on older Ruby runtimes
|
data/Rakefile
CHANGED
@@ -34,8 +34,8 @@ if RUBY_PLATFORM =~ /java/
|
|
34
34
|
jars = ["#{jruby_home}/lib/jruby.jar"]
|
35
35
|
ext.classpath = jars.map { |x| File.expand_path(x) }.join(':')
|
36
36
|
ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
|
37
|
-
ext.source_version = '1.
|
38
|
-
ext.target_version = '1.
|
37
|
+
ext.source_version = '1.8'
|
38
|
+
ext.target_version = '1.8'
|
39
39
|
end
|
40
40
|
else
|
41
41
|
require 'rake/extensiontask'
|
data/doclib/msgpack/factory.rb
CHANGED
@@ -75,6 +75,7 @@ module MessagePack
|
|
75
75
|
#
|
76
76
|
# * *:packer* specify symbol or proc object for packer
|
77
77
|
# * *:unpacker* specify symbol or proc object for unpacker
|
78
|
+
# * *:optimized_symbols_parsing* specify true to use the optimized symbols parsing (not supported on JRuby now)
|
78
79
|
#
|
79
80
|
def register_type(type, klass, options={})
|
80
81
|
end
|
@@ -21,6 +21,7 @@ import org.jcodings.Encoding;
|
|
21
21
|
|
22
22
|
@JRubyClass(name="MessagePack::Buffer")
|
23
23
|
public class Buffer extends RubyObject {
|
24
|
+
private static final long serialVersionUID = 8441244627425629412L;
|
24
25
|
private IRubyObject io;
|
25
26
|
private ByteBuffer buffer;
|
26
27
|
private boolean writeMode;
|
@@ -49,7 +50,7 @@ public class Buffer extends RubyObject {
|
|
49
50
|
}
|
50
51
|
this.buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE);
|
51
52
|
this.writeMode = true;
|
52
|
-
this.binaryEncoding = ctx.
|
53
|
+
this.binaryEncoding = ctx.runtime.getEncodingService().getAscii8bitEncoding();
|
53
54
|
return this;
|
54
55
|
}
|
55
56
|
|
@@ -87,17 +88,17 @@ public class Buffer extends RubyObject {
|
|
87
88
|
writeMode = true;
|
88
89
|
}
|
89
90
|
buffer.clear();
|
90
|
-
return ctx.
|
91
|
+
return ctx.runtime.getNil();
|
91
92
|
}
|
92
93
|
|
93
94
|
@JRubyMethod(name = "size")
|
94
95
|
public IRubyObject size(ThreadContext ctx) {
|
95
|
-
return ctx.
|
96
|
+
return ctx.runtime.newFixnum(rawSize());
|
96
97
|
}
|
97
98
|
|
98
99
|
@JRubyMethod(name = "empty?")
|
99
100
|
public IRubyObject isEmpty(ThreadContext ctx) {
|
100
|
-
return rawSize() == 0 ? ctx.
|
101
|
+
return rawSize() == 0 ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
101
102
|
}
|
102
103
|
|
103
104
|
private IRubyObject bufferWrite(ThreadContext ctx, IRubyObject str) {
|
@@ -105,7 +106,7 @@ public class Buffer extends RubyObject {
|
|
105
106
|
int length = bytes.length();
|
106
107
|
ensureRemainingCapacity(length);
|
107
108
|
buffer.put(bytes.unsafeBytes(), bytes.begin(), length);
|
108
|
-
return ctx.
|
109
|
+
return ctx.runtime.newFixnum(length);
|
109
110
|
|
110
111
|
}
|
111
112
|
|
@@ -131,19 +132,19 @@ public class Buffer extends RubyObject {
|
|
131
132
|
length = (int) args[0].convertToInteger().getLongValue();
|
132
133
|
}
|
133
134
|
if (raiseOnUnderflow && rawSize() < length) {
|
134
|
-
throw ctx.
|
135
|
+
throw ctx.runtime.newEOFError();
|
135
136
|
}
|
136
137
|
int readLength = Math.min(length, rawSize());
|
137
138
|
if (readLength == 0 && length > 0) {
|
138
|
-
return ctx.
|
139
|
+
return ctx.runtime.getNil();
|
139
140
|
} else if (readLength == 0) {
|
140
|
-
return ctx.
|
141
|
+
return ctx.runtime.newString();
|
141
142
|
} else {
|
142
143
|
ensureReadMode();
|
143
144
|
byte[] bytes = new byte[readLength];
|
144
145
|
buffer.get(bytes);
|
145
146
|
ByteList byteList = new ByteList(bytes, binaryEncoding);
|
146
|
-
return ctx.
|
147
|
+
return ctx.runtime.newString(byteList);
|
147
148
|
}
|
148
149
|
}
|
149
150
|
|
@@ -161,12 +162,12 @@ public class Buffer extends RubyObject {
|
|
161
162
|
feed(ctx);
|
162
163
|
int length = (int) _length.convertToInteger().getLongValue();
|
163
164
|
if (raiseOnUnderflow && rawSize() < length) {
|
164
|
-
throw ctx.
|
165
|
+
throw ctx.runtime.newEOFError();
|
165
166
|
}
|
166
167
|
ensureReadMode();
|
167
168
|
int skipLength = Math.min(length, rawSize());
|
168
169
|
buffer.position(buffer.position() + skipLength);
|
169
|
-
return ctx.
|
170
|
+
return ctx.runtime.newFixnum(skipLength);
|
170
171
|
}
|
171
172
|
|
172
173
|
@JRubyMethod(name = "skip")
|
@@ -188,23 +189,23 @@ public class Buffer extends RubyObject {
|
|
188
189
|
ensureReadMode();
|
189
190
|
int length = buffer.limit() - buffer.position();
|
190
191
|
ByteList str = new ByteList(buffer.array(), buffer.position(), length, binaryEncoding, true);
|
191
|
-
return ctx.
|
192
|
+
return ctx.runtime.newString(str);
|
192
193
|
}
|
193
194
|
|
194
195
|
@JRubyMethod(name = "to_a")
|
195
196
|
public IRubyObject toA(ThreadContext ctx) {
|
196
|
-
return ctx.
|
197
|
+
return ctx.runtime.newArray(toS(ctx));
|
197
198
|
}
|
198
199
|
|
199
200
|
@JRubyMethod(name = "io")
|
200
201
|
public IRubyObject getIo(ThreadContext ctx) {
|
201
|
-
return io == null ? ctx.
|
202
|
+
return io == null ? ctx.runtime.getNil() : io;
|
202
203
|
}
|
203
204
|
|
204
205
|
@JRubyMethod(name = "flush")
|
205
206
|
public IRubyObject flush(ThreadContext ctx) {
|
206
207
|
if (io == null) {
|
207
|
-
return ctx.
|
208
|
+
return ctx.runtime.getNil();
|
208
209
|
} else {
|
209
210
|
return io.callMethod(ctx, "flush");
|
210
211
|
}
|
@@ -213,7 +214,7 @@ public class Buffer extends RubyObject {
|
|
213
214
|
@JRubyMethod(name = "close")
|
214
215
|
public IRubyObject close(ThreadContext ctx) {
|
215
216
|
if (io == null) {
|
216
|
-
return ctx.
|
217
|
+
return ctx.runtime.getNil();
|
217
218
|
} else {
|
218
219
|
return io.callMethod(ctx, "close");
|
219
220
|
}
|
@@ -122,7 +122,6 @@ public class Decoder implements Iterator<IRubyObject> {
|
|
122
122
|
ByteList byteList = new ByteList(bytes, encoding);
|
123
123
|
RubyString string = runtime.newString(byteList);
|
124
124
|
if (this.freeze) {
|
125
|
-
string.setFrozen(true);
|
126
125
|
string = runtime.freezeAndDedupString(string);
|
127
126
|
}
|
128
127
|
return string;
|
@@ -140,9 +139,14 @@ public class Decoder implements Iterator<IRubyObject> {
|
|
140
139
|
RubyHash hash = RubyHash.newHash(runtime);
|
141
140
|
for (int i = 0; i < size; i++) {
|
142
141
|
IRubyObject key = next();
|
143
|
-
if (
|
142
|
+
if (key instanceof RubyString) {
|
143
|
+
if (this.symbolizeKeys) {
|
144
144
|
key = ((RubyString) key).intern();
|
145
|
+
} else {
|
146
|
+
key = runtime.freezeAndDedupString((RubyString) key);
|
147
|
+
}
|
145
148
|
}
|
149
|
+
|
146
150
|
hash.fastASet(key, next());
|
147
151
|
}
|
148
152
|
return hash;
|
@@ -119,7 +119,9 @@ public class Encoder {
|
|
119
119
|
} else if (object instanceof RubyFloat) {
|
120
120
|
appendFloat((RubyFloat) object);
|
121
121
|
} else if (object instanceof RubyString) {
|
122
|
-
|
122
|
+
if (object.getType() == runtime.getString() || !tryAppendWithExtTypeLookup(object)) {
|
123
|
+
appendString((RubyString) object);
|
124
|
+
}
|
123
125
|
} else if (object instanceof RubySymbol) {
|
124
126
|
if (hasSymbolExtType) {
|
125
127
|
appendOther(object, destination);
|
@@ -127,9 +129,13 @@ public class Encoder {
|
|
127
129
|
appendString(((RubySymbol) object).asString());
|
128
130
|
}
|
129
131
|
} else if (object instanceof RubyArray) {
|
130
|
-
|
132
|
+
if (object.getType() == runtime.getArray() || !tryAppendWithExtTypeLookup(object)) {
|
133
|
+
appendArray((RubyArray) object);
|
134
|
+
}
|
131
135
|
} else if (object instanceof RubyHash) {
|
132
|
-
|
136
|
+
if (object.getType() == runtime.getHash() || !tryAppendWithExtTypeLookup(object)) {
|
137
|
+
appendHash((RubyHash) object);
|
138
|
+
}
|
133
139
|
} else if (object instanceof ExtensionValue) {
|
134
140
|
appendExtensionValue((ExtensionValue) object);
|
135
141
|
} else {
|
@@ -153,7 +159,7 @@ public class Encoder {
|
|
153
159
|
}
|
154
160
|
|
155
161
|
private void appendInteger(RubyInteger object) {
|
156
|
-
long value =
|
162
|
+
long value = object.getLongValue();
|
157
163
|
if (value < 0) {
|
158
164
|
if (value < Short.MIN_VALUE) {
|
159
165
|
if (value < Integer.MIN_VALUE) {
|
@@ -241,7 +247,7 @@ public class Encoder {
|
|
241
247
|
} else {
|
242
248
|
ensureRemainingCapacity(5 + length);
|
243
249
|
buffer.put(binary ? BIN32 : STR32);
|
244
|
-
buffer.putInt(
|
250
|
+
buffer.putInt(length);
|
245
251
|
}
|
246
252
|
}
|
247
253
|
|
@@ -249,7 +255,7 @@ public class Encoder {
|
|
249
255
|
Encoding encoding = object.getEncoding();
|
250
256
|
boolean binary = !compatibilityMode && encoding == binaryEncoding;
|
251
257
|
if (encoding != utf8Encoding && encoding != binaryEncoding) {
|
252
|
-
object = (RubyString)
|
258
|
+
object = (RubyString)(object).encode(runtime.getCurrentContext(), runtime.getEncodingService().getEncoding(utf8Encoding));
|
253
259
|
}
|
254
260
|
ByteList bytes = object.getByteList();
|
255
261
|
int length = bytes.length();
|
@@ -257,12 +263,12 @@ public class Encoder {
|
|
257
263
|
buffer.put(bytes.unsafeBytes(), bytes.begin(), length);
|
258
264
|
}
|
259
265
|
|
260
|
-
private void appendArray(RubyArray object) {
|
266
|
+
private void appendArray(RubyArray<?> object) {
|
261
267
|
appendArrayHeader(object);
|
262
268
|
appendArrayElements(object);
|
263
269
|
}
|
264
270
|
|
265
|
-
private void appendArrayHeader(RubyArray object) {
|
271
|
+
private void appendArrayHeader(RubyArray<?> object) {
|
266
272
|
appendArrayHeader(object.size());
|
267
273
|
}
|
268
274
|
|
@@ -281,7 +287,7 @@ public class Encoder {
|
|
281
287
|
}
|
282
288
|
}
|
283
289
|
|
284
|
-
private void appendArrayElements(RubyArray object) {
|
290
|
+
private void appendArrayElements(RubyArray<?> object) {
|
285
291
|
int size = object.size();
|
286
292
|
for (int i = 0; i < size; i++) {
|
287
293
|
appendObject(object.eltOk(i));
|
@@ -383,7 +389,7 @@ public class Encoder {
|
|
383
389
|
appendExt((int) type, payloadBytes);
|
384
390
|
}
|
385
391
|
|
386
|
-
private
|
392
|
+
private boolean tryAppendWithExtTypeLookup(IRubyObject object) {
|
387
393
|
if (registry != null) {
|
388
394
|
RubyModule lookupClass;
|
389
395
|
|
@@ -398,10 +404,14 @@ public class Encoder {
|
|
398
404
|
RubyString bytes = pair[0].callMethod(runtime.getCurrentContext(), "call", object).asString();
|
399
405
|
int type = (int) ((RubyFixnum) pair[1]).getLongValue();
|
400
406
|
appendExt(type, bytes.getByteList());
|
401
|
-
return;
|
407
|
+
return true;
|
402
408
|
}
|
403
409
|
}
|
404
|
-
|
410
|
+
return false;
|
411
|
+
}
|
412
|
+
|
413
|
+
private void appendOther(IRubyObject object, IRubyObject destination) {
|
414
|
+
if (!tryAppendWithExtTypeLookup(object)) { appendCustom(object, destination); }
|
405
415
|
}
|
406
416
|
|
407
417
|
private void appendCustom(IRubyObject object, IRubyObject destination) {
|
@@ -37,7 +37,7 @@ public class ExtensionRegistry {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
public IRubyObject toInternalPackerRegistry(ThreadContext ctx) {
|
40
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
40
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
41
41
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
42
42
|
ExtensionEntry entry = extensionsByModule.get(extensionModule);
|
43
43
|
if (entry.hasPacker()) {
|
@@ -48,11 +48,11 @@ public class ExtensionRegistry {
|
|
48
48
|
}
|
49
49
|
|
50
50
|
public IRubyObject toInternalUnpackerRegistry(ThreadContext ctx) {
|
51
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
51
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
52
52
|
for (int typeIdIndex = 0 ; typeIdIndex < 256 ; typeIdIndex++) {
|
53
53
|
ExtensionEntry entry = extensionsByTypeId[typeIdIndex];
|
54
54
|
if (entry != null && entry.hasUnpacker()) {
|
55
|
-
IRubyObject typeId = RubyFixnum.newFixnum(ctx.
|
55
|
+
IRubyObject typeId = RubyFixnum.newFixnum(ctx.runtime, typeIdIndex - 128);
|
56
56
|
hash.put(typeId, entry.toUnpackerTuple(ctx));
|
57
57
|
}
|
58
58
|
}
|
@@ -124,7 +124,7 @@ public class ExtensionRegistry {
|
|
124
124
|
private ExtensionEntry findEntryByModuleOrAncestor(final RubyModule mod) {
|
125
125
|
ThreadContext ctx = mod.getRuntime().getCurrentContext();
|
126
126
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
127
|
-
RubyArray ancestors = (RubyArray)
|
127
|
+
RubyArray<?> ancestors = (RubyArray)mod.callMethod(ctx, "ancestors");
|
128
128
|
if (ancestors.callMethod(ctx, "include?", extensionModule).isTrue()) {
|
129
129
|
return extensionsByModule.get(extensionModule);
|
130
130
|
}
|
@@ -173,16 +173,16 @@ public class ExtensionRegistry {
|
|
173
173
|
return unpackerProc;
|
174
174
|
}
|
175
175
|
|
176
|
-
public RubyArray toPackerTuple(ThreadContext ctx) {
|
177
|
-
return
|
176
|
+
public RubyArray<?> toPackerTuple(ThreadContext ctx) {
|
177
|
+
return ctx.runtime.newArray(new IRubyObject[] {ctx.runtime.newFixnum(typeId), packerProc, packerArg});
|
178
178
|
}
|
179
179
|
|
180
|
-
public RubyArray toUnpackerTuple(ThreadContext ctx) {
|
181
|
-
return
|
180
|
+
public RubyArray<?> toUnpackerTuple(ThreadContext ctx) {
|
181
|
+
return ctx.runtime.newArray(new IRubyObject[] {mod, unpackerProc, unpackerArg});
|
182
182
|
}
|
183
183
|
|
184
184
|
public IRubyObject[] toPackerProcTypeIdPair(ThreadContext ctx) {
|
185
|
-
return new IRubyObject[] {packerProc,
|
185
|
+
return new IRubyObject[] {packerProc, ctx.runtime.newFixnum(typeId)};
|
186
186
|
}
|
187
187
|
}
|
188
188
|
}
|
@@ -25,6 +25,7 @@ import static org.msgpack.jruby.Types.*;
|
|
25
25
|
|
26
26
|
@JRubyClass(name="MessagePack::ExtensionValue")
|
27
27
|
public class ExtensionValue extends RubyObject {
|
28
|
+
private static final long serialVersionUID = 8451274621449322492L;
|
28
29
|
private final Encoding binaryEncoding;
|
29
30
|
|
30
31
|
private RubyFixnum type;
|
@@ -77,12 +78,10 @@ public class ExtensionValue extends RubyObject {
|
|
77
78
|
}
|
78
79
|
if (o instanceof ExtensionValue) {
|
79
80
|
ExtensionValue other = (ExtensionValue) o;
|
80
|
-
if (!this.type.eql_p(other.type).isTrue())
|
81
|
+
if (!this.type.eql_p(other.type).isTrue()) {
|
81
82
|
return runtime.getFalse();
|
82
|
-
if (runtime.is1_8()) {
|
83
|
-
return this.payload.str_eql_p(ctx, other.payload);
|
84
83
|
} else {
|
85
|
-
return this.payload.
|
84
|
+
return this.payload.str_eql_p(ctx, other.payload);
|
86
85
|
}
|
87
86
|
}
|
88
87
|
return runtime.getFalse();
|
@@ -96,12 +95,10 @@ public class ExtensionValue extends RubyObject {
|
|
96
95
|
}
|
97
96
|
if (o instanceof ExtensionValue) {
|
98
97
|
ExtensionValue other = (ExtensionValue) o;
|
99
|
-
if (!this.type.op_equal(ctx, other.type).isTrue())
|
98
|
+
if (!this.type.op_equal(ctx, other.type).isTrue()) {
|
100
99
|
return runtime.getFalse();
|
101
|
-
if (runtime.is1_8()) {
|
102
|
-
return this.payload.op_equal(ctx, other.payload);
|
103
100
|
} else {
|
104
|
-
return this.payload.
|
101
|
+
return this.payload.op_equal(ctx, other.payload);
|
105
102
|
}
|
106
103
|
}
|
107
104
|
return runtime.getFalse();
|
@@ -23,6 +23,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
23
23
|
|
24
24
|
@JRubyClass(name="MessagePack::Factory")
|
25
25
|
public class Factory extends RubyObject {
|
26
|
+
private static final long serialVersionUID = 8441284623445322492L;
|
26
27
|
private final Ruby runtime;
|
27
28
|
private final ExtensionRegistry extensionRegistry;
|
28
29
|
private boolean hasSymbolExtType;
|
@@ -61,7 +62,7 @@ public class Factory extends RubyObject {
|
|
61
62
|
|
62
63
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
63
64
|
public IRubyObject registeredTypesInternal(ThreadContext ctx) {
|
64
|
-
return RubyArray.newArray(ctx.
|
65
|
+
return RubyArray.newArray(ctx.runtime, new IRubyObject[] {
|
65
66
|
extensionRegistry.toInternalPackerRegistry(ctx),
|
66
67
|
extensionRegistry.toInternalUnpackerRegistry(ctx)
|
67
68
|
});
|
@@ -69,7 +70,7 @@ public class Factory extends RubyObject {
|
|
69
70
|
|
70
71
|
@JRubyMethod(name = "register_type", required = 2, optional = 1)
|
71
72
|
public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args) {
|
72
|
-
Ruby runtime = ctx.
|
73
|
+
Ruby runtime = ctx.runtime;
|
73
74
|
IRubyObject type = args[0];
|
74
75
|
IRubyObject mod = args[1];
|
75
76
|
|
@@ -88,6 +89,10 @@ public class Factory extends RubyObject {
|
|
88
89
|
RubyHash options = (RubyHash) args[args.length - 1];
|
89
90
|
packerArg = options.fastARef(runtime.newSymbol("packer"));
|
90
91
|
unpackerArg = options.fastARef(runtime.newSymbol("unpacker"));
|
92
|
+
IRubyObject optimizedSymbolsParsingArg = options.fastARef(runtime.newSymbol("optimized_symbols_parsing"));
|
93
|
+
if (optimizedSymbolsParsingArg != null && optimizedSymbolsParsingArg.isTrue()) {
|
94
|
+
throw runtime.newArgumentError("JRuby implementation does not support the optimized_symbols_parsing option");
|
95
|
+
}
|
91
96
|
} else {
|
92
97
|
throw runtime.newArgumentError(String.format("expected Hash but found %s.", args[args.length - 1].getType().getName()));
|
93
98
|
}
|
@@ -27,6 +27,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
27
27
|
|
28
28
|
@JRubyClass(name="MessagePack::Packer")
|
29
29
|
public class Packer extends RubyObject {
|
30
|
+
private static final long serialVersionUID = 8451274621499362492L;
|
30
31
|
public ExtensionRegistry registry;
|
31
32
|
private Buffer buffer;
|
32
33
|
private Encoder encoder;
|
@@ -48,9 +49,10 @@ public class Packer extends RubyObject {
|
|
48
49
|
@JRubyMethod(name = "initialize", optional = 2)
|
49
50
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
50
51
|
boolean compatibilityMode = false;
|
52
|
+
Ruby runtime = ctx.runtime;
|
51
53
|
if (args.length > 0 && args[args.length - 1] instanceof RubyHash) {
|
52
54
|
RubyHash options = (RubyHash) args[args.length - 1];
|
53
|
-
IRubyObject mode = options.fastARef(
|
55
|
+
IRubyObject mode = options.fastARef(runtime.newSymbol("compatibility_mode"));
|
54
56
|
compatibilityMode = (mode != null) && mode.isTrue();
|
55
57
|
}
|
56
58
|
if (registry == null) {
|
@@ -58,22 +60,22 @@ public class Packer extends RubyObject {
|
|
58
60
|
// registry is already initialized (and somthing might be registered) when newPacker from Factory
|
59
61
|
this.registry = new ExtensionRegistry();
|
60
62
|
}
|
61
|
-
this.encoder = new Encoder(
|
62
|
-
this.buffer = new Buffer(
|
63
|
+
this.encoder = new Encoder(runtime, compatibilityMode, registry, hasSymbolExtType);
|
64
|
+
this.buffer = new Buffer(runtime, runtime.getModule("MessagePack").getClass("Buffer"));
|
63
65
|
this.buffer.initialize(ctx, args);
|
64
|
-
this.binaryEncoding =
|
66
|
+
this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding();
|
65
67
|
return this;
|
66
68
|
}
|
67
69
|
|
68
70
|
public static Packer newPacker(ThreadContext ctx, ExtensionRegistry extRegistry, boolean hasSymbolExtType, IRubyObject[] args) {
|
69
|
-
Packer packer = new Packer(ctx.
|
71
|
+
Packer packer = new Packer(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Packer"), extRegistry, hasSymbolExtType);
|
70
72
|
packer.initialize(ctx, args);
|
71
73
|
return packer;
|
72
74
|
}
|
73
75
|
|
74
76
|
@JRubyMethod(name = "compatibility_mode?")
|
75
77
|
public IRubyObject isCompatibilityMode(ThreadContext ctx) {
|
76
|
-
return encoder.isCompatibilityMode() ? ctx.
|
78
|
+
return encoder.isCompatibilityMode() ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
77
79
|
}
|
78
80
|
|
79
81
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
@@ -83,7 +85,7 @@ public class Packer extends RubyObject {
|
|
83
85
|
|
84
86
|
@JRubyMethod(name = "register_type", required = 2, optional = 1)
|
85
87
|
public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args, final Block block) {
|
86
|
-
Ruby runtime = ctx.
|
88
|
+
Ruby runtime = ctx.runtime;
|
87
89
|
IRubyObject type = args[0];
|
88
90
|
IRubyObject mod = args[1];
|
89
91
|
|
@@ -182,12 +184,12 @@ public class Packer extends RubyObject {
|
|
182
184
|
|
183
185
|
@JRubyMethod(name = "write_true")
|
184
186
|
public IRubyObject writeTrue(ThreadContext ctx) {
|
185
|
-
return write(ctx, ctx.
|
187
|
+
return write(ctx, ctx.runtime.getTrue());
|
186
188
|
}
|
187
189
|
|
188
190
|
@JRubyMethod(name = "write_false")
|
189
191
|
public IRubyObject writeFalse(ThreadContext ctx) {
|
190
|
-
return write(ctx, ctx.
|
192
|
+
return write(ctx, ctx.runtime.getFalse());
|
191
193
|
}
|
192
194
|
|
193
195
|
@JRubyMethod(name = "write_nil")
|