msgpack 1.4.2 → 1.7.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/ChangeLog +89 -0
- data/README.md +73 -13
- data/ext/java/org/msgpack/jruby/Buffer.java +26 -19
- data/ext/java/org/msgpack/jruby/Decoder.java +29 -21
- data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
- data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +43 -64
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +6 -9
- data/ext/java/org/msgpack/jruby/Factory.java +43 -42
- data/ext/java/org/msgpack/jruby/Packer.java +37 -40
- data/ext/java/org/msgpack/jruby/Unpacker.java +80 -73
- data/ext/msgpack/buffer.c +54 -74
- data/ext/msgpack/buffer.h +21 -18
- data/ext/msgpack/buffer_class.c +161 -52
- data/ext/msgpack/buffer_class.h +1 -0
- data/ext/msgpack/compat.h +0 -99
- data/ext/msgpack/extconf.rb +25 -46
- data/ext/msgpack/factory_class.c +143 -87
- data/ext/msgpack/packer.c +66 -43
- data/ext/msgpack/packer.h +25 -20
- data/ext/msgpack/packer_class.c +102 -130
- data/ext/msgpack/packer_class.h +11 -0
- data/ext/msgpack/packer_ext_registry.c +35 -40
- data/ext/msgpack/packer_ext_registry.h +41 -38
- data/ext/msgpack/rbinit.c +1 -1
- data/ext/msgpack/rmem.c +3 -4
- data/ext/msgpack/sysdep.h +5 -2
- data/ext/msgpack/unpacker.c +136 -111
- data/ext/msgpack/unpacker.h +16 -13
- data/ext/msgpack/unpacker_class.c +86 -126
- data/ext/msgpack/unpacker_class.h +11 -0
- data/ext/msgpack/unpacker_ext_registry.c +40 -28
- data/ext/msgpack/unpacker_ext_registry.h +21 -18
- data/lib/msgpack/bigint.rb +69 -0
- data/lib/msgpack/buffer.rb +9 -0
- data/lib/msgpack/factory.rb +140 -10
- data/lib/msgpack/packer.rb +10 -1
- data/lib/msgpack/symbol.rb +21 -4
- data/lib/msgpack/time.rb +1 -1
- data/lib/msgpack/unpacker.rb +14 -1
- data/lib/msgpack/version.rb +1 -1
- data/lib/msgpack.rb +6 -7
- data/msgpack.gemspec +8 -5
- metadata +37 -82
- data/.gitignore +0 -23
- data/.rubocop.yml +0 -36
- data/.travis.yml +0 -39
- data/Gemfile +0 -9
- data/Rakefile +0 -71
- data/appveyor.yml +0 -18
- data/bench/pack.rb +0 -23
- data/bench/pack_log.rb +0 -33
- data/bench/pack_log_long.rb +0 -65
- data/bench/pack_symbols.rb +0 -28
- data/bench/run.sh +0 -14
- data/bench/run_long.sh +0 -35
- data/bench/run_symbols.sh +0 -26
- data/bench/unpack.rb +0 -21
- data/bench/unpack_log.rb +0 -34
- data/bench/unpack_log_long.rb +0 -67
- data/doclib/msgpack/buffer.rb +0 -193
- data/doclib/msgpack/core_ext.rb +0 -101
- data/doclib/msgpack/error.rb +0 -19
- data/doclib/msgpack/extension_value.rb +0 -9
- data/doclib/msgpack/factory.rb +0 -101
- data/doclib/msgpack/packer.rb +0 -208
- data/doclib/msgpack/time.rb +0 -22
- data/doclib/msgpack/timestamp.rb +0 -44
- data/doclib/msgpack/unpacker.rb +0 -183
- data/doclib/msgpack.rb +0 -87
- data/msgpack.org.md +0 -46
- data/spec/cases.json +0 -1
- data/spec/cases.msg +0 -0
- data/spec/cases_compact.msg +0 -0
- data/spec/cases_spec.rb +0 -39
- data/spec/cruby/buffer_io_spec.rb +0 -255
- data/spec/cruby/buffer_packer.rb +0 -29
- data/spec/cruby/buffer_spec.rb +0 -575
- data/spec/cruby/buffer_unpacker.rb +0 -19
- data/spec/cruby/unpacker_spec.rb +0 -70
- data/spec/ext_value_spec.rb +0 -99
- data/spec/exttypes.rb +0 -51
- data/spec/factory_spec.rb +0 -367
- data/spec/format_spec.rb +0 -301
- data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
- data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
- data/spec/jruby/unpacker_spec.rb +0 -186
- data/spec/msgpack_spec.rb +0 -214
- data/spec/pack_spec.rb +0 -61
- data/spec/packer_spec.rb +0 -557
- data/spec/random_compat.rb +0 -24
- data/spec/spec_helper.rb +0 -55
- data/spec/timestamp_spec.rb +0 -121
- data/spec/unpack_spec.rb +0 -57
- data/spec/unpacker_spec.rb +0 -819
@@ -27,53 +27,65 @@ import static org.jruby.runtime.Visibility.PRIVATE;
|
|
27
27
|
|
28
28
|
@JRubyClass(name="MessagePack::Packer")
|
29
29
|
public class Packer extends RubyObject {
|
30
|
-
|
30
|
+
private static final long serialVersionUID = 8451274621499362492L;
|
31
|
+
public transient ExtensionRegistry registry;
|
31
32
|
private Buffer buffer;
|
32
|
-
private Encoder encoder;
|
33
|
+
private transient Encoder encoder;
|
33
34
|
private boolean hasSymbolExtType;
|
34
|
-
private
|
35
|
+
private boolean hasBigintExtType;
|
36
|
+
private transient Encoding binaryEncoding;
|
35
37
|
|
36
|
-
public Packer(Ruby runtime, RubyClass type, ExtensionRegistry registry, boolean hasSymbolExtType) {
|
38
|
+
public Packer(Ruby runtime, RubyClass type, ExtensionRegistry registry, boolean hasSymbolExtType, boolean hasBigintExtType) {
|
37
39
|
super(runtime, type);
|
38
40
|
this.registry = registry;
|
39
41
|
this.hasSymbolExtType = hasSymbolExtType;
|
42
|
+
this.hasBigintExtType = hasBigintExtType;
|
40
43
|
}
|
41
44
|
|
42
45
|
static class PackerAllocator implements ObjectAllocator {
|
43
46
|
public IRubyObject allocate(Ruby runtime, RubyClass type) {
|
44
|
-
return new Packer(runtime, type, null, false);
|
47
|
+
return new Packer(runtime, type, null, false, false);
|
45
48
|
}
|
46
49
|
}
|
47
50
|
|
48
51
|
@JRubyMethod(name = "initialize", optional = 2)
|
49
52
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
50
53
|
boolean compatibilityMode = false;
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
Ruby runtime = ctx.runtime;
|
55
|
+
if (args.length > 0) {
|
56
|
+
RubyHash options = null;
|
57
|
+
if (args[args.length - 1] instanceof RubyHash) {
|
58
|
+
options = (RubyHash) args[args.length - 1];
|
59
|
+
} else if (args.length > 1 && args[args.length - 2] instanceof RubyHash) {
|
60
|
+
options = (RubyHash) args[args.length - 2];
|
61
|
+
}
|
62
|
+
|
63
|
+
if (options != null) {
|
64
|
+
IRubyObject mode = options.fastARef(runtime.newSymbol("compatibility_mode"));
|
65
|
+
compatibilityMode = (mode != null) && mode.isTrue();
|
66
|
+
}
|
55
67
|
}
|
56
68
|
if (registry == null) {
|
57
69
|
// registry is null when allocate -> initialize
|
58
70
|
// registry is already initialized (and somthing might be registered) when newPacker from Factory
|
59
71
|
this.registry = new ExtensionRegistry();
|
60
72
|
}
|
61
|
-
this.encoder = new Encoder(
|
62
|
-
this.buffer = new Buffer(
|
73
|
+
this.encoder = new Encoder(runtime, this, compatibilityMode, registry, hasSymbolExtType, hasBigintExtType);
|
74
|
+
this.buffer = new Buffer(runtime, runtime.getModule("MessagePack").getClass("Buffer"));
|
63
75
|
this.buffer.initialize(ctx, args);
|
64
|
-
this.binaryEncoding =
|
76
|
+
this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding();
|
65
77
|
return this;
|
66
78
|
}
|
67
79
|
|
68
|
-
public static Packer newPacker(ThreadContext ctx, ExtensionRegistry extRegistry, boolean hasSymbolExtType, IRubyObject[] args) {
|
69
|
-
Packer packer = new Packer(ctx.
|
80
|
+
public static Packer newPacker(ThreadContext ctx, ExtensionRegistry extRegistry, boolean hasSymbolExtType, boolean hasBigintExtType, IRubyObject[] args) {
|
81
|
+
Packer packer = new Packer(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Packer"), extRegistry, hasSymbolExtType, hasBigintExtType);
|
70
82
|
packer.initialize(ctx, args);
|
71
83
|
return packer;
|
72
84
|
}
|
73
85
|
|
74
86
|
@JRubyMethod(name = "compatibility_mode?")
|
75
87
|
public IRubyObject isCompatibilityMode(ThreadContext ctx) {
|
76
|
-
return encoder.isCompatibilityMode() ? ctx.
|
88
|
+
return encoder.isCompatibilityMode() ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
77
89
|
}
|
78
90
|
|
79
91
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
@@ -81,26 +93,11 @@ public class Packer extends RubyObject {
|
|
81
93
|
return registry.toInternalPackerRegistry(ctx);
|
82
94
|
}
|
83
95
|
|
84
|
-
@JRubyMethod(name = "
|
85
|
-
public IRubyObject registerType(ThreadContext ctx, IRubyObject
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
IRubyObject arg;
|
91
|
-
IRubyObject proc;
|
92
|
-
if (args.length == 2) {
|
93
|
-
if (! block.isGiven()) {
|
94
|
-
throw runtime.newLocalJumpErrorNoBlock();
|
95
|
-
}
|
96
|
-
proc = block.getProcObject();
|
97
|
-
arg = proc;
|
98
|
-
} else if (args.length == 3) {
|
99
|
-
arg = args[2];
|
100
|
-
proc = arg.callMethod(ctx, "to_proc");
|
101
|
-
} else {
|
102
|
-
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 2..3)", 2 + args.length));
|
103
|
-
}
|
96
|
+
@JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE)
|
97
|
+
public IRubyObject registerType(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject proc) {
|
98
|
+
testFrozen("MessagePack::Packer");
|
99
|
+
|
100
|
+
Ruby runtime = ctx.runtime;
|
104
101
|
|
105
102
|
long typeId = ((RubyFixnum) type).getLongValue();
|
106
103
|
if (typeId < -128 || typeId > 127) {
|
@@ -112,9 +109,9 @@ public class Packer extends RubyObject {
|
|
112
109
|
}
|
113
110
|
RubyModule extModule = (RubyModule) mod;
|
114
111
|
|
115
|
-
registry.put(extModule, (int) typeId,
|
112
|
+
registry.put(extModule, (int) typeId, false, proc, null);
|
116
113
|
|
117
|
-
if (extModule == runtime.getSymbol()) {
|
114
|
+
if (extModule == runtime.getSymbol() && !proc.isNil()) {
|
118
115
|
encoder.hasSymbolExtType = true;
|
119
116
|
}
|
120
117
|
|
@@ -182,12 +179,12 @@ public class Packer extends RubyObject {
|
|
182
179
|
|
183
180
|
@JRubyMethod(name = "write_true")
|
184
181
|
public IRubyObject writeTrue(ThreadContext ctx) {
|
185
|
-
return write(ctx, ctx.
|
182
|
+
return write(ctx, ctx.runtime.getTrue());
|
186
183
|
}
|
187
184
|
|
188
185
|
@JRubyMethod(name = "write_false")
|
189
186
|
public IRubyObject writeFalse(ThreadContext ctx) {
|
190
|
-
return write(ctx, ctx.
|
187
|
+
return write(ctx, ctx.runtime.getFalse());
|
191
188
|
}
|
192
189
|
|
193
190
|
@JRubyMethod(name = "write_nil")
|
@@ -255,7 +252,7 @@ public class Packer extends RubyObject {
|
|
255
252
|
return buffer.size(ctx);
|
256
253
|
}
|
257
254
|
|
258
|
-
@JRubyMethod(name = "clear")
|
255
|
+
@JRubyMethod(name = "clear", alias = { "reset" })
|
259
256
|
public IRubyObject clear(ThreadContext ctx) {
|
260
257
|
return buffer.clear(ctx);
|
261
258
|
}
|
@@ -21,17 +21,17 @@ import org.jruby.runtime.ThreadContext;
|
|
21
21
|
import org.jruby.anno.JRubyClass;
|
22
22
|
import org.jruby.anno.JRubyMethod;
|
23
23
|
import org.jruby.util.ByteList;
|
24
|
-
import org.jruby.ext.stringio.StringIO;
|
25
24
|
|
26
25
|
import static org.jruby.runtime.Visibility.PRIVATE;
|
27
26
|
|
28
27
|
@JRubyClass(name="MessagePack::Unpacker")
|
29
28
|
public class Unpacker extends RubyObject {
|
30
|
-
private final
|
29
|
+
private static final long serialVersionUID = 8451264671199362492L;
|
30
|
+
private transient final ExtensionRegistry registry;
|
31
31
|
|
32
|
-
private IRubyObject stream;
|
33
|
-
private IRubyObject data;
|
34
|
-
private Decoder decoder;
|
32
|
+
private transient IRubyObject stream;
|
33
|
+
private transient IRubyObject data;
|
34
|
+
private transient Decoder decoder;
|
35
35
|
private final RubyClass underflowErrorClass;
|
36
36
|
private boolean symbolizeKeys;
|
37
37
|
private boolean freeze;
|
@@ -55,51 +55,70 @@ public class Unpacker extends RubyObject {
|
|
55
55
|
|
56
56
|
@JRubyMethod(name = "initialize", optional = 2, visibility = PRIVATE)
|
57
57
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
58
|
+
Ruby runtime = ctx.runtime;
|
59
|
+
|
58
60
|
symbolizeKeys = false;
|
59
61
|
allowUnknownExt = false;
|
60
62
|
freeze = false;
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
63
|
+
|
64
|
+
IRubyObject io = null;
|
65
|
+
RubyHash options = null;
|
66
|
+
|
67
|
+
if (args.length >= 1) {
|
68
|
+
io = args[0];
|
69
|
+
}
|
70
|
+
|
71
|
+
if (args.length >= 2 && args[1] != runtime.getNil()) {
|
72
|
+
options = (RubyHash)args[1];
|
73
|
+
}
|
74
|
+
|
75
|
+
if (options == null && io != null && io instanceof RubyHash) {
|
76
|
+
options = (RubyHash)io;
|
77
|
+
io = null;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (options != null) {
|
81
|
+
IRubyObject sk = options.fastARef(runtime.newSymbol("symbolize_keys"));
|
82
|
+
if (sk != null) {
|
83
|
+
symbolizeKeys = sk.isTrue();
|
84
|
+
}
|
85
|
+
IRubyObject f = options.fastARef(runtime.newSymbol("freeze"));
|
86
|
+
if (f != null) {
|
87
|
+
freeze = f.isTrue();
|
76
88
|
}
|
77
|
-
|
78
|
-
|
89
|
+
IRubyObject au = options.fastARef(runtime.newSymbol("allow_unknown_ext"));
|
90
|
+
if (au != null) {
|
91
|
+
allowUnknownExt = au.isTrue();
|
79
92
|
}
|
93
|
+
|
94
|
+
}
|
95
|
+
|
96
|
+
if (io != null && io != runtime.getNil()) {
|
97
|
+
setStream(ctx, io);
|
80
98
|
}
|
99
|
+
|
81
100
|
return this;
|
82
101
|
}
|
83
102
|
|
84
103
|
public static Unpacker newUnpacker(ThreadContext ctx, ExtensionRegistry extRegistry, IRubyObject[] args) {
|
85
|
-
Unpacker unpacker = new Unpacker(ctx.
|
104
|
+
Unpacker unpacker = new Unpacker(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Unpacker"), extRegistry);
|
86
105
|
unpacker.initialize(ctx, args);
|
87
106
|
return unpacker;
|
88
107
|
}
|
89
108
|
|
90
109
|
@JRubyMethod(name = "symbolize_keys?")
|
91
110
|
public IRubyObject isSymbolizeKeys(ThreadContext ctx) {
|
92
|
-
return symbolizeKeys ? ctx.
|
111
|
+
return symbolizeKeys ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
93
112
|
}
|
94
113
|
|
95
114
|
@JRubyMethod(name = "freeze?")
|
96
115
|
public IRubyObject isFreeze(ThreadContext ctx) {
|
97
|
-
return freeze ? ctx.
|
116
|
+
return freeze ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
98
117
|
}
|
99
118
|
|
100
119
|
@JRubyMethod(name = "allow_unknown_ext?")
|
101
120
|
public IRubyObject isAllowUnknownExt(ThreadContext ctx) {
|
102
|
-
return allowUnknownExt ? ctx.
|
121
|
+
return allowUnknownExt ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
|
103
122
|
}
|
104
123
|
|
105
124
|
@JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
|
@@ -107,37 +126,23 @@ public class Unpacker extends RubyObject {
|
|
107
126
|
return registry.toInternalUnpackerRegistry(ctx);
|
108
127
|
}
|
109
128
|
|
110
|
-
@JRubyMethod(name = "
|
111
|
-
public IRubyObject
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
RubyModule extModule;
|
116
|
-
IRubyObject arg;
|
117
|
-
IRubyObject proc;
|
118
|
-
if (args.length == 1) {
|
119
|
-
if (! block.isGiven()) {
|
120
|
-
throw runtime.newLocalJumpErrorNoBlock();
|
121
|
-
}
|
122
|
-
proc = RubyProc.newProc(runtime, block, block.type);
|
123
|
-
if (proc == null)
|
124
|
-
System.err.println("proc from Block is null");
|
125
|
-
arg = proc;
|
126
|
-
extModule = null;
|
127
|
-
} else if (args.length == 3) {
|
128
|
-
extModule = (RubyModule) args[1];
|
129
|
-
arg = args[2];
|
130
|
-
proc = extModule.method(arg);
|
131
|
-
} else {
|
132
|
-
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 1 or 3)", 2 + args.length));
|
133
|
-
}
|
129
|
+
@JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE)
|
130
|
+
public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject proc) {
|
131
|
+
testFrozen("MessagePack::Unpacker");
|
132
|
+
|
133
|
+
Ruby runtime = ctx.runtime;
|
134
134
|
|
135
135
|
long typeId = ((RubyFixnum) type).getLongValue();
|
136
136
|
if (typeId < -128 || typeId > 127) {
|
137
137
|
throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId));
|
138
138
|
}
|
139
139
|
|
140
|
-
|
140
|
+
RubyModule extModule = null;
|
141
|
+
if (mod != runtime.getNil()) {
|
142
|
+
extModule = (RubyModule)mod;
|
143
|
+
}
|
144
|
+
|
145
|
+
registry.put(extModule, (int) typeId, false, null, proc);
|
141
146
|
return runtime.getNil();
|
142
147
|
}
|
143
148
|
|
@@ -155,7 +160,7 @@ public class Unpacker extends RubyObject {
|
|
155
160
|
if (limit == -1) {
|
156
161
|
limit = byteList.length() - offset;
|
157
162
|
}
|
158
|
-
Decoder decoder = new Decoder(ctx.
|
163
|
+
Decoder decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin() + offset, limit, symbolizeKeys, freeze, allowUnknownExt);
|
159
164
|
try {
|
160
165
|
data = null;
|
161
166
|
data = decoder.next();
|
@@ -164,13 +169,13 @@ public class Unpacker extends RubyObject {
|
|
164
169
|
throw re;
|
165
170
|
}
|
166
171
|
}
|
167
|
-
return ctx.
|
172
|
+
return ctx.runtime.newFixnum(decoder.offset());
|
168
173
|
}
|
169
174
|
|
170
175
|
@JRubyMethod(name = "data")
|
171
176
|
public IRubyObject getData(ThreadContext ctx) {
|
172
177
|
if (data == null) {
|
173
|
-
return ctx.
|
178
|
+
return ctx.runtime.getNil();
|
174
179
|
} else {
|
175
180
|
return data;
|
176
181
|
}
|
@@ -178,14 +183,14 @@ public class Unpacker extends RubyObject {
|
|
178
183
|
|
179
184
|
@JRubyMethod(name = "finished?")
|
180
185
|
public IRubyObject finished_p(ThreadContext ctx) {
|
181
|
-
return data == null ? ctx.
|
186
|
+
return data == null ? ctx.runtime.getFalse() : ctx.runtime.getTrue();
|
182
187
|
}
|
183
188
|
|
184
189
|
@JRubyMethod(required = 1, name = "feed", alias = { "feed_reference" })
|
185
190
|
public IRubyObject feed(ThreadContext ctx, IRubyObject data) {
|
186
191
|
ByteList byteList = data.asString().getByteList();
|
187
192
|
if (decoder == null) {
|
188
|
-
decoder = new Decoder(ctx.
|
193
|
+
decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
|
189
194
|
} else {
|
190
195
|
decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length());
|
191
196
|
}
|
@@ -202,7 +207,7 @@ public class Unpacker extends RubyObject {
|
|
202
207
|
feed(ctx, data);
|
203
208
|
if (block.isGiven()) {
|
204
209
|
each(ctx, block);
|
205
|
-
return ctx.
|
210
|
+
return ctx.runtime.getNil();
|
206
211
|
} else {
|
207
212
|
return callMethod(ctx, "to_enum");
|
208
213
|
}
|
@@ -230,7 +235,7 @@ public class Unpacker extends RubyObject {
|
|
230
235
|
|
231
236
|
@JRubyMethod
|
232
237
|
public IRubyObject fill(ThreadContext ctx) {
|
233
|
-
return ctx.
|
238
|
+
return ctx.runtime.getNil();
|
234
239
|
}
|
235
240
|
|
236
241
|
@JRubyMethod
|
@@ -238,13 +243,13 @@ public class Unpacker extends RubyObject {
|
|
238
243
|
if (decoder != null) {
|
239
244
|
decoder.reset();
|
240
245
|
}
|
241
|
-
return ctx.
|
246
|
+
return ctx.runtime.getNil();
|
242
247
|
}
|
243
248
|
|
244
249
|
@JRubyMethod(name = "read", alias = { "unpack" })
|
245
250
|
public IRubyObject read(ThreadContext ctx) {
|
246
251
|
if (decoder == null) {
|
247
|
-
throw ctx.
|
252
|
+
throw ctx.runtime.newEOFError();
|
248
253
|
}
|
249
254
|
try {
|
250
255
|
return decoder.next();
|
@@ -252,19 +257,19 @@ public class Unpacker extends RubyObject {
|
|
252
257
|
if (re.getException().getType() != underflowErrorClass) {
|
253
258
|
throw re;
|
254
259
|
} else {
|
255
|
-
throw ctx.
|
260
|
+
throw ctx.runtime.newEOFError();
|
256
261
|
}
|
257
262
|
}
|
258
263
|
}
|
259
264
|
|
260
265
|
@JRubyMethod(name = "skip")
|
261
266
|
public IRubyObject skip(ThreadContext ctx) {
|
262
|
-
throw ctx.
|
267
|
+
throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
|
263
268
|
}
|
264
269
|
|
265
270
|
@JRubyMethod(name = "skip_nil")
|
266
271
|
public IRubyObject skipNil(ThreadContext ctx) {
|
267
|
-
throw ctx.
|
272
|
+
throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
|
268
273
|
}
|
269
274
|
|
270
275
|
@JRubyMethod
|
@@ -276,11 +281,11 @@ public class Unpacker extends RubyObject {
|
|
276
281
|
if (re.getException().getType() != underflowErrorClass) {
|
277
282
|
throw re;
|
278
283
|
} else {
|
279
|
-
throw ctx.
|
284
|
+
throw ctx.runtime.newEOFError();
|
280
285
|
}
|
281
286
|
}
|
282
287
|
}
|
283
|
-
return ctx.
|
288
|
+
return ctx.runtime.getNil();
|
284
289
|
}
|
285
290
|
|
286
291
|
@JRubyMethod
|
@@ -292,17 +297,17 @@ public class Unpacker extends RubyObject {
|
|
292
297
|
if (re.getException().getType() != underflowErrorClass) {
|
293
298
|
throw re;
|
294
299
|
} else {
|
295
|
-
throw ctx.
|
300
|
+
throw ctx.runtime.newEOFError();
|
296
301
|
}
|
297
302
|
}
|
298
303
|
}
|
299
|
-
return ctx.
|
304
|
+
return ctx.runtime.getNil();
|
300
305
|
}
|
301
306
|
|
302
307
|
@JRubyMethod(name = "stream")
|
303
308
|
public IRubyObject getStream(ThreadContext ctx) {
|
304
309
|
if (stream == null) {
|
305
|
-
return ctx.
|
310
|
+
return ctx.runtime.getNil();
|
306
311
|
} else {
|
307
312
|
return stream;
|
308
313
|
}
|
@@ -311,19 +316,21 @@ public class Unpacker extends RubyObject {
|
|
311
316
|
@JRubyMethod(name = "stream=", required = 1)
|
312
317
|
public IRubyObject setStream(ThreadContext ctx, IRubyObject stream) {
|
313
318
|
RubyString str;
|
314
|
-
if (stream instanceof
|
315
|
-
str = stream.callMethod(ctx, "string").asString();
|
316
|
-
} else if (stream instanceof RubyIO) {
|
319
|
+
if (stream instanceof RubyIO) {
|
317
320
|
str = stream.callMethod(ctx, "read").asString();
|
318
321
|
} else if (stream.respondsTo("read")) {
|
319
322
|
str = stream.callMethod(ctx, "read").asString();
|
320
323
|
} else {
|
321
|
-
throw ctx.
|
324
|
+
throw ctx.runtime.newTypeError(stream, "IO");
|
322
325
|
}
|
323
326
|
ByteList byteList = str.getByteList();
|
324
327
|
this.stream = stream;
|
325
328
|
this.decoder = null;
|
326
|
-
this.decoder = new Decoder(ctx.
|
329
|
+
this.decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
|
327
330
|
return getStream(ctx);
|
328
331
|
}
|
332
|
+
|
333
|
+
public ExtensionRegistry.ExtensionEntry lookupExtensionByTypeId(int typeId) {
|
334
|
+
return registry.lookupExtensionByTypeId(typeId);
|
335
|
+
}
|
329
336
|
}
|