msgpack 1.3.3 → 1.6.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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yaml +57 -0
  3. data/.rubocop.yml +2 -2
  4. data/ChangeLog +74 -0
  5. data/Gemfile +1 -1
  6. data/README.md +266 -0
  7. data/Rakefile +1 -9
  8. data/bench/bench.rb +78 -0
  9. data/bin/console +8 -0
  10. data/doclib/msgpack/factory.rb +47 -3
  11. data/doclib/msgpack/packer.rb +5 -4
  12. data/doclib/msgpack/unpacker.rb +2 -2
  13. data/ext/java/org/msgpack/jruby/Buffer.java +23 -16
  14. data/ext/java/org/msgpack/jruby/Decoder.java +46 -23
  15. data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
  16. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +37 -49
  17. data/ext/java/org/msgpack/jruby/ExtensionValue.java +5 -8
  18. data/ext/java/org/msgpack/jruby/Factory.java +47 -7
  19. data/ext/java/org/msgpack/jruby/Packer.java +29 -17
  20. data/ext/java/org/msgpack/jruby/Unpacker.java +72 -37
  21. data/ext/msgpack/buffer.c +42 -68
  22. data/ext/msgpack/buffer.h +59 -14
  23. data/ext/msgpack/buffer_class.c +90 -52
  24. data/ext/msgpack/compat.h +1 -111
  25. data/ext/msgpack/extconf.rb +45 -19
  26. data/ext/msgpack/factory_class.c +133 -43
  27. data/ext/msgpack/packer.c +60 -36
  28. data/ext/msgpack/packer.h +27 -25
  29. data/ext/msgpack/packer_class.c +84 -77
  30. data/ext/msgpack/packer_class.h +11 -0
  31. data/ext/msgpack/packer_ext_registry.c +24 -32
  32. data/ext/msgpack/packer_ext_registry.h +40 -33
  33. data/ext/msgpack/sysdep.h +5 -2
  34. data/ext/msgpack/unpacker.c +132 -115
  35. data/ext/msgpack/unpacker.h +23 -10
  36. data/ext/msgpack/unpacker_class.c +83 -78
  37. data/ext/msgpack/unpacker_class.h +11 -0
  38. data/ext/msgpack/unpacker_ext_registry.c +42 -18
  39. data/ext/msgpack/unpacker_ext_registry.h +23 -16
  40. data/lib/msgpack/bigint.rb +69 -0
  41. data/lib/msgpack/factory.rb +103 -0
  42. data/lib/msgpack/symbol.rb +21 -4
  43. data/lib/msgpack/time.rb +1 -1
  44. data/lib/msgpack/version.rb +4 -8
  45. data/lib/msgpack.rb +6 -12
  46. data/msgpack.gemspec +4 -6
  47. data/spec/bigint_spec.rb +26 -0
  48. data/spec/cruby/buffer_spec.rb +17 -0
  49. data/spec/factory_spec.rb +351 -12
  50. data/spec/msgpack_spec.rb +1 -1
  51. data/spec/packer_spec.rb +18 -0
  52. data/spec/spec_helper.rb +37 -3
  53. data/spec/timestamp_spec.rb +38 -0
  54. data/spec/unpacker_spec.rb +157 -4
  55. metadata +31 -61
  56. data/.travis.yml +0 -43
  57. data/README.rdoc +0 -225
  58. data/bench/pack.rb +0 -23
  59. data/bench/pack_log.rb +0 -33
  60. data/bench/pack_log_long.rb +0 -65
  61. data/bench/pack_symbols.rb +0 -28
  62. data/bench/run.sh +0 -14
  63. data/bench/run_long.sh +0 -35
  64. data/bench/run_symbols.sh +0 -26
  65. data/bench/unpack.rb +0 -21
  66. data/bench/unpack_log.rb +0 -34
  67. data/bench/unpack_log_long.rb +0 -67
@@ -12,6 +12,8 @@ import org.jruby.RubyInteger;
12
12
  import org.jruby.RubyFixnum;
13
13
  import org.jruby.RubyString;
14
14
  import org.jruby.RubySymbol;
15
+ import org.jruby.RubyProc;
16
+ import org.jruby.RubyMethod;
15
17
  import org.jruby.runtime.builtin.IRubyObject;
16
18
  import org.jruby.anno.JRubyClass;
17
19
  import org.jruby.anno.JRubyMethod;
@@ -23,15 +25,18 @@ import static org.jruby.runtime.Visibility.PRIVATE;
23
25
 
24
26
  @JRubyClass(name="MessagePack::Factory")
25
27
  public class Factory extends RubyObject {
28
+ private static final long serialVersionUID = 8441284623445322492L;
26
29
  private final Ruby runtime;
27
- private final ExtensionRegistry extensionRegistry;
30
+ private ExtensionRegistry extensionRegistry;
28
31
  private boolean hasSymbolExtType;
32
+ private boolean hasBigIntExtType;
29
33
 
30
34
  public Factory(Ruby runtime, RubyClass type) {
31
35
  super(runtime, type);
32
36
  this.runtime = runtime;
33
37
  this.extensionRegistry = new ExtensionRegistry();
34
38
  this.hasSymbolExtType = false;
39
+ this.hasBigIntExtType = false;
35
40
  }
36
41
 
37
42
  static class FactoryAllocator implements ObjectAllocator {
@@ -49,9 +54,17 @@ public class Factory extends RubyObject {
49
54
  return this;
50
55
  }
51
56
 
52
- @JRubyMethod(name = "packer", optional = 1)
57
+ @JRubyMethod(name = "dup")
58
+ public IRubyObject dup() {
59
+ Factory clone = (Factory)super.dup();
60
+ clone.extensionRegistry = extensionRegistry();
61
+ clone.hasSymbolExtType = hasSymbolExtType;
62
+ return clone;
63
+ }
64
+
65
+ @JRubyMethod(name = "packer", optional = 2)
53
66
  public Packer packer(ThreadContext ctx, IRubyObject[] args) {
54
- return Packer.newPacker(ctx, extensionRegistry(), hasSymbolExtType, args);
67
+ return Packer.newPacker(ctx, extensionRegistry(), hasSymbolExtType, hasBigIntExtType, args);
55
68
  }
56
69
 
57
70
  @JRubyMethod(name = "unpacker", optional = 2)
@@ -61,7 +74,7 @@ public class Factory extends RubyObject {
61
74
 
62
75
  @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
63
76
  public IRubyObject registeredTypesInternal(ThreadContext ctx) {
64
- return RubyArray.newArray(ctx.getRuntime(), new IRubyObject[] {
77
+ return RubyArray.newArray(ctx.runtime, new IRubyObject[] {
65
78
  extensionRegistry.toInternalPackerRegistry(ctx),
66
79
  extensionRegistry.toInternalUnpackerRegistry(ctx)
67
80
  });
@@ -69,13 +82,15 @@ public class Factory extends RubyObject {
69
82
 
70
83
  @JRubyMethod(name = "register_type", required = 2, optional = 1)
71
84
  public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args) {
72
- Ruby runtime = ctx.getRuntime();
85
+ Ruby runtime = ctx.runtime;
73
86
  IRubyObject type = args[0];
74
87
  IRubyObject mod = args[1];
75
88
 
76
89
  IRubyObject packerArg;
77
90
  IRubyObject unpackerArg;
78
91
 
92
+ RubyHash options = null;
93
+
79
94
  if (isFrozen()) {
80
95
  throw runtime.newRuntimeError("can't modify frozen Factory");
81
96
  }
@@ -85,9 +100,13 @@ public class Factory extends RubyObject {
85
100
  unpackerArg = runtime.newSymbol("from_msgpack_ext");
86
101
  } else if (args.length == 3) {
87
102
  if (args[args.length - 1] instanceof RubyHash) {
88
- RubyHash options = (RubyHash) args[args.length - 1];
103
+ options = (RubyHash) args[args.length - 1];
89
104
  packerArg = options.fastARef(runtime.newSymbol("packer"));
90
105
  unpackerArg = options.fastARef(runtime.newSymbol("unpacker"));
106
+ IRubyObject optimizedSymbolsParsingArg = options.fastARef(runtime.newSymbol("optimized_symbols_parsing"));
107
+ if (optimizedSymbolsParsingArg != null && optimizedSymbolsParsingArg.isTrue()) {
108
+ throw runtime.newArgumentError("JRuby implementation does not support the optimized_symbols_parsing option");
109
+ }
91
110
  } else {
92
111
  throw runtime.newArgumentError(String.format("expected Hash but found %s.", args[args.length - 1].getType().getName()));
93
112
  }
@@ -113,17 +132,38 @@ public class Factory extends RubyObject {
113
132
  if (unpackerArg != null) {
114
133
  if (unpackerArg instanceof RubyString || unpackerArg instanceof RubySymbol) {
115
134
  unpackerProc = extModule.method(unpackerArg.callMethod(ctx, "to_sym"));
135
+ } else if (unpackerArg instanceof RubyProc || unpackerArg instanceof RubyMethod) {
136
+ unpackerProc = unpackerArg;
116
137
  } else {
117
138
  unpackerProc = unpackerArg.callMethod(ctx, "method", runtime.newSymbol("call"));
118
139
  }
119
140
  }
120
141
 
121
- extensionRegistry.put(extModule, (int) typeId, packerProc, packerArg, unpackerProc, unpackerArg);
142
+ boolean recursive = false;
143
+ if (options != null) {
144
+ IRubyObject recursiveExtensionArg = options.fastARef(runtime.newSymbol("recursive"));
145
+ if (recursiveExtensionArg != null && recursiveExtensionArg.isTrue()) {
146
+ recursive = true;
147
+ }
148
+ }
149
+
150
+ extensionRegistry.put(extModule, (int) typeId, recursive, packerProc, packerArg, unpackerProc, unpackerArg);
122
151
 
123
152
  if (extModule == runtime.getSymbol()) {
124
153
  hasSymbolExtType = true;
125
154
  }
126
155
 
156
+ if (options != null) {
157
+ IRubyObject oversizedIntegerExtensionArg = options.fastARef(runtime.newSymbol("oversized_integer_extension"));
158
+ if (oversizedIntegerExtensionArg != null && oversizedIntegerExtensionArg.isTrue()) {
159
+ if (extModule == runtime.getModule("Integer")) {
160
+ hasBigIntExtType = true;
161
+ } else {
162
+ throw runtime.newArgumentError("oversized_integer_extension: true is only for Integer class");
163
+ }
164
+ }
165
+ }
166
+
127
167
  return runtime.getNil();
128
168
  }
129
169
  }
@@ -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
+ private static final long serialVersionUID = 8451274621499362492L;
30
31
  public ExtensionRegistry registry;
31
32
  private Buffer buffer;
32
33
  private Encoder encoder;
33
34
  private boolean hasSymbolExtType;
35
+ private boolean hasBigintExtType;
34
36
  private 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
- if (args.length > 0 && args[args.length - 1] instanceof RubyHash) {
52
- RubyHash options = (RubyHash) args[args.length - 1];
53
- IRubyObject mode = options.fastARef(ctx.getRuntime().newSymbol("compatibility_mode"));
54
- compatibilityMode = (mode != null) && mode.isTrue();
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(ctx.getRuntime(), compatibilityMode, registry, hasSymbolExtType);
62
- this.buffer = new Buffer(ctx.getRuntime(), ctx.getRuntime().getModule("MessagePack").getClass("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 = ctx.getRuntime().getEncodingService().getAscii8bitEncoding();
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.getRuntime(), ctx.getRuntime().getModule("MessagePack").getClass("Packer"), extRegistry, hasSymbolExtType);
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.getRuntime().getTrue() : ctx.getRuntime().getFalse();
88
+ return encoder.isCompatibilityMode() ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
77
89
  }
78
90
 
79
91
  @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
@@ -83,7 +95,7 @@ public class Packer extends RubyObject {
83
95
 
84
96
  @JRubyMethod(name = "register_type", required = 2, optional = 1)
85
97
  public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args, final Block block) {
86
- Ruby runtime = ctx.getRuntime();
98
+ Ruby runtime = ctx.runtime;
87
99
  IRubyObject type = args[0];
88
100
  IRubyObject mod = args[1];
89
101
 
@@ -112,7 +124,7 @@ public class Packer extends RubyObject {
112
124
  }
113
125
  RubyModule extModule = (RubyModule) mod;
114
126
 
115
- registry.put(extModule, (int) typeId, proc, arg, null, null);
127
+ registry.put(extModule, (int) typeId, false, proc, arg, null, null);
116
128
 
117
129
  if (extModule == runtime.getSymbol()) {
118
130
  encoder.hasSymbolExtType = true;
@@ -182,12 +194,12 @@ public class Packer extends RubyObject {
182
194
 
183
195
  @JRubyMethod(name = "write_true")
184
196
  public IRubyObject writeTrue(ThreadContext ctx) {
185
- return write(ctx, ctx.getRuntime().getTrue());
197
+ return write(ctx, ctx.runtime.getTrue());
186
198
  }
187
199
 
188
200
  @JRubyMethod(name = "write_false")
189
201
  public IRubyObject writeFalse(ThreadContext ctx) {
190
- return write(ctx, ctx.getRuntime().getFalse());
202
+ return write(ctx, ctx.runtime.getFalse());
191
203
  }
192
204
 
193
205
  @JRubyMethod(name = "write_nil")
@@ -255,7 +267,7 @@ public class Packer extends RubyObject {
255
267
  return buffer.size(ctx);
256
268
  }
257
269
 
258
- @JRubyMethod(name = "clear")
270
+ @JRubyMethod(name = "clear", alias = { "reset" })
259
271
  public IRubyObject clear(ThreadContext ctx) {
260
272
  return buffer.clear(ctx);
261
273
  }
@@ -27,6 +27,7 @@ import static org.jruby.runtime.Visibility.PRIVATE;
27
27
 
28
28
  @JRubyClass(name="MessagePack::Unpacker")
29
29
  public class Unpacker extends RubyObject {
30
+ private static final long serialVersionUID = 8451264671199362492L;
30
31
  private final ExtensionRegistry registry;
31
32
 
32
33
  private IRubyObject stream;
@@ -34,6 +35,7 @@ public class Unpacker extends RubyObject {
34
35
  private Decoder decoder;
35
36
  private final RubyClass underflowErrorClass;
36
37
  private boolean symbolizeKeys;
38
+ private boolean freeze;
37
39
  private boolean allowUnknownExt;
38
40
 
39
41
  public Unpacker(Ruby runtime, RubyClass type) {
@@ -54,41 +56,70 @@ public class Unpacker extends RubyObject {
54
56
 
55
57
  @JRubyMethod(name = "initialize", optional = 2, visibility = PRIVATE)
56
58
  public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
59
+ Ruby runtime = ctx.runtime;
60
+
57
61
  symbolizeKeys = false;
58
62
  allowUnknownExt = false;
59
- if (args.length > 0) {
60
- if (args[args.length - 1] instanceof RubyHash) {
61
- RubyHash options = (RubyHash) args[args.length - 1];
62
- IRubyObject sk = options.fastARef(ctx.getRuntime().newSymbol("symbolize_keys"));
63
- if (sk != null) {
64
- symbolizeKeys = sk.isTrue();
65
- }
66
- IRubyObject au = options.fastARef(ctx.getRuntime().newSymbol("allow_unknown_ext"));
67
- if (au != null) {
68
- allowUnknownExt = au.isTrue();
69
- }
63
+ freeze = false;
64
+
65
+ IRubyObject io = null;
66
+ RubyHash options = null;
67
+
68
+ if (args.length >= 1) {
69
+ io = args[0];
70
+ }
71
+
72
+ if (args.length >= 2 && args[1] != runtime.getNil()) {
73
+ options = (RubyHash)args[1];
74
+ }
75
+
76
+ if (options == null && io != null && io instanceof RubyHash) {
77
+ options = (RubyHash)io;
78
+ io = null;
79
+ }
80
+
81
+ if (options != null) {
82
+ IRubyObject sk = options.fastARef(runtime.newSymbol("symbolize_keys"));
83
+ if (sk != null) {
84
+ symbolizeKeys = sk.isTrue();
85
+ }
86
+ IRubyObject f = options.fastARef(runtime.newSymbol("freeze"));
87
+ if (f != null) {
88
+ freeze = f.isTrue();
70
89
  }
71
- if (args[0] != ctx.getRuntime().getNil() && !(args[0] instanceof RubyHash)) {
72
- setStream(ctx, args[0]);
90
+ IRubyObject au = options.fastARef(runtime.newSymbol("allow_unknown_ext"));
91
+ if (au != null) {
92
+ allowUnknownExt = au.isTrue();
73
93
  }
94
+
95
+ }
96
+
97
+ if (io != null && io != runtime.getNil()) {
98
+ setStream(ctx, io);
74
99
  }
100
+
75
101
  return this;
76
102
  }
77
103
 
78
104
  public static Unpacker newUnpacker(ThreadContext ctx, ExtensionRegistry extRegistry, IRubyObject[] args) {
79
- Unpacker unpacker = new Unpacker(ctx.getRuntime(), ctx.getRuntime().getModule("MessagePack").getClass("Unpacker"), extRegistry);
105
+ Unpacker unpacker = new Unpacker(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Unpacker"), extRegistry);
80
106
  unpacker.initialize(ctx, args);
81
107
  return unpacker;
82
108
  }
83
109
 
84
110
  @JRubyMethod(name = "symbolize_keys?")
85
111
  public IRubyObject isSymbolizeKeys(ThreadContext ctx) {
86
- return symbolizeKeys ? ctx.getRuntime().getTrue() : ctx.getRuntime().getFalse();
112
+ return symbolizeKeys ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
113
+ }
114
+
115
+ @JRubyMethod(name = "freeze?")
116
+ public IRubyObject isFreeze(ThreadContext ctx) {
117
+ return freeze ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
87
118
  }
88
119
 
89
120
  @JRubyMethod(name = "allow_unknown_ext?")
90
121
  public IRubyObject isAllowUnknownExt(ThreadContext ctx) {
91
- return allowUnknownExt ? ctx.getRuntime().getTrue() : ctx.getRuntime().getFalse();
122
+ return allowUnknownExt ? ctx.runtime.getTrue() : ctx.runtime.getFalse();
92
123
  }
93
124
 
94
125
  @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE)
@@ -98,7 +129,7 @@ public class Unpacker extends RubyObject {
98
129
 
99
130
  @JRubyMethod(name = "register_type", required = 1, optional = 2)
100
131
  public IRubyObject registerType(ThreadContext ctx, IRubyObject[] args, final Block block) {
101
- Ruby runtime = ctx.getRuntime();
132
+ Ruby runtime = ctx.runtime;
102
133
  IRubyObject type = args[0];
103
134
 
104
135
  RubyModule extModule;
@@ -126,7 +157,7 @@ public class Unpacker extends RubyObject {
126
157
  throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId));
127
158
  }
128
159
 
129
- registry.put(extModule, (int) typeId, null, null, proc, arg);
160
+ registry.put(extModule, (int) typeId, false, null, null, proc, arg);
130
161
  return runtime.getNil();
131
162
  }
132
163
 
@@ -144,7 +175,7 @@ public class Unpacker extends RubyObject {
144
175
  if (limit == -1) {
145
176
  limit = byteList.length() - offset;
146
177
  }
147
- Decoder decoder = new Decoder(ctx.getRuntime(), registry, byteList.unsafeBytes(), byteList.begin() + offset, limit, symbolizeKeys, allowUnknownExt);
178
+ Decoder decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin() + offset, limit, symbolizeKeys, freeze, allowUnknownExt);
148
179
  try {
149
180
  data = null;
150
181
  data = decoder.next();
@@ -153,13 +184,13 @@ public class Unpacker extends RubyObject {
153
184
  throw re;
154
185
  }
155
186
  }
156
- return ctx.getRuntime().newFixnum(decoder.offset());
187
+ return ctx.runtime.newFixnum(decoder.offset());
157
188
  }
158
189
 
159
190
  @JRubyMethod(name = "data")
160
191
  public IRubyObject getData(ThreadContext ctx) {
161
192
  if (data == null) {
162
- return ctx.getRuntime().getNil();
193
+ return ctx.runtime.getNil();
163
194
  } else {
164
195
  return data;
165
196
  }
@@ -167,14 +198,14 @@ public class Unpacker extends RubyObject {
167
198
 
168
199
  @JRubyMethod(name = "finished?")
169
200
  public IRubyObject finished_p(ThreadContext ctx) {
170
- return data == null ? ctx.getRuntime().getFalse() : ctx.getRuntime().getTrue();
201
+ return data == null ? ctx.runtime.getFalse() : ctx.runtime.getTrue();
171
202
  }
172
203
 
173
204
  @JRubyMethod(required = 1, name = "feed", alias = { "feed_reference" })
174
205
  public IRubyObject feed(ThreadContext ctx, IRubyObject data) {
175
206
  ByteList byteList = data.asString().getByteList();
176
207
  if (decoder == null) {
177
- decoder = new Decoder(ctx.getRuntime(), registry, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, allowUnknownExt);
208
+ decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
178
209
  } else {
179
210
  decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length());
180
211
  }
@@ -191,7 +222,7 @@ public class Unpacker extends RubyObject {
191
222
  feed(ctx, data);
192
223
  if (block.isGiven()) {
193
224
  each(ctx, block);
194
- return ctx.getRuntime().getNil();
225
+ return ctx.runtime.getNil();
195
226
  } else {
196
227
  return callMethod(ctx, "to_enum");
197
228
  }
@@ -219,7 +250,7 @@ public class Unpacker extends RubyObject {
219
250
 
220
251
  @JRubyMethod
221
252
  public IRubyObject fill(ThreadContext ctx) {
222
- return ctx.getRuntime().getNil();
253
+ return ctx.runtime.getNil();
223
254
  }
224
255
 
225
256
  @JRubyMethod
@@ -227,13 +258,13 @@ public class Unpacker extends RubyObject {
227
258
  if (decoder != null) {
228
259
  decoder.reset();
229
260
  }
230
- return ctx.getRuntime().getNil();
261
+ return ctx.runtime.getNil();
231
262
  }
232
263
 
233
264
  @JRubyMethod(name = "read", alias = { "unpack" })
234
265
  public IRubyObject read(ThreadContext ctx) {
235
266
  if (decoder == null) {
236
- throw ctx.getRuntime().newEOFError();
267
+ throw ctx.runtime.newEOFError();
237
268
  }
238
269
  try {
239
270
  return decoder.next();
@@ -241,19 +272,19 @@ public class Unpacker extends RubyObject {
241
272
  if (re.getException().getType() != underflowErrorClass) {
242
273
  throw re;
243
274
  } else {
244
- throw ctx.getRuntime().newEOFError();
275
+ throw ctx.runtime.newEOFError();
245
276
  }
246
277
  }
247
278
  }
248
279
 
249
280
  @JRubyMethod(name = "skip")
250
281
  public IRubyObject skip(ThreadContext ctx) {
251
- throw ctx.getRuntime().newNotImplementedError("Not supported yet in JRuby implementation");
282
+ throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
252
283
  }
253
284
 
254
285
  @JRubyMethod(name = "skip_nil")
255
286
  public IRubyObject skipNil(ThreadContext ctx) {
256
- throw ctx.getRuntime().newNotImplementedError("Not supported yet in JRuby implementation");
287
+ throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation");
257
288
  }
258
289
 
259
290
  @JRubyMethod
@@ -265,11 +296,11 @@ public class Unpacker extends RubyObject {
265
296
  if (re.getException().getType() != underflowErrorClass) {
266
297
  throw re;
267
298
  } else {
268
- throw ctx.getRuntime().newEOFError();
299
+ throw ctx.runtime.newEOFError();
269
300
  }
270
301
  }
271
302
  }
272
- return ctx.getRuntime().getNil();
303
+ return ctx.runtime.getNil();
273
304
  }
274
305
 
275
306
  @JRubyMethod
@@ -281,17 +312,17 @@ public class Unpacker extends RubyObject {
281
312
  if (re.getException().getType() != underflowErrorClass) {
282
313
  throw re;
283
314
  } else {
284
- throw ctx.getRuntime().newEOFError();
315
+ throw ctx.runtime.newEOFError();
285
316
  }
286
317
  }
287
318
  }
288
- return ctx.getRuntime().getNil();
319
+ return ctx.runtime.getNil();
289
320
  }
290
321
 
291
322
  @JRubyMethod(name = "stream")
292
323
  public IRubyObject getStream(ThreadContext ctx) {
293
324
  if (stream == null) {
294
- return ctx.getRuntime().getNil();
325
+ return ctx.runtime.getNil();
295
326
  } else {
296
327
  return stream;
297
328
  }
@@ -307,12 +338,16 @@ public class Unpacker extends RubyObject {
307
338
  } else if (stream.respondsTo("read")) {
308
339
  str = stream.callMethod(ctx, "read").asString();
309
340
  } else {
310
- throw ctx.getRuntime().newTypeError(stream, "IO");
341
+ throw ctx.runtime.newTypeError(stream, "IO");
311
342
  }
312
343
  ByteList byteList = str.getByteList();
313
344
  this.stream = stream;
314
345
  this.decoder = null;
315
- this.decoder = new Decoder(ctx.getRuntime(), registry, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, allowUnknownExt);
346
+ this.decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt);
316
347
  return getStream(ctx);
317
348
  }
349
+
350
+ public ExtensionRegistry.ExtensionEntry lookupExtensionByTypeId(int typeId) {
351
+ return registry.lookupExtensionByTypeId(typeId);
352
+ }
318
353
  }