msgpack 1.3.3 → 1.7.2

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