msgpack 1.4.2 → 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.
- checksums.yaml +4 -4
- data/ChangeLog +85 -0
- data/README.md +52 -1
- 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 +126 -108
- 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
@@ -18,26 +18,21 @@ public class ExtensionRegistry {
|
|
18
18
|
private final ExtensionEntry[] extensionsByTypeId;
|
19
19
|
|
20
20
|
public ExtensionRegistry() {
|
21
|
-
this(new HashMap<RubyModule, ExtensionEntry>());
|
21
|
+
this(new HashMap<RubyModule, ExtensionEntry>(), new ExtensionEntry[256]);
|
22
22
|
}
|
23
23
|
|
24
|
-
private ExtensionRegistry(Map<RubyModule, ExtensionEntry> extensionsByModule) {
|
24
|
+
private ExtensionRegistry(Map<RubyModule, ExtensionEntry> extensionsByModule, ExtensionEntry[] extensionsByTypeId) {
|
25
25
|
this.extensionsByModule = new HashMap<RubyModule, ExtensionEntry>(extensionsByModule);
|
26
26
|
this.extensionsByAncestor = new HashMap<RubyModule, ExtensionEntry>();
|
27
|
-
this.extensionsByTypeId =
|
28
|
-
for (ExtensionEntry entry : extensionsByModule.values()) {
|
29
|
-
if (entry.hasUnpacker()) {
|
30
|
-
extensionsByTypeId[entry.getTypeId() + 128] = entry;
|
31
|
-
}
|
32
|
-
}
|
27
|
+
this.extensionsByTypeId = extensionsByTypeId.clone();
|
33
28
|
}
|
34
29
|
|
35
30
|
public ExtensionRegistry dup() {
|
36
|
-
return new ExtensionRegistry(extensionsByModule);
|
31
|
+
return new ExtensionRegistry(extensionsByModule, extensionsByTypeId);
|
37
32
|
}
|
38
33
|
|
39
34
|
public IRubyObject toInternalPackerRegistry(ThreadContext ctx) {
|
40
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
35
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
41
36
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
42
37
|
ExtensionEntry entry = extensionsByModule.get(extensionModule);
|
43
38
|
if (entry.hasPacker()) {
|
@@ -48,75 +43,57 @@ public class ExtensionRegistry {
|
|
48
43
|
}
|
49
44
|
|
50
45
|
public IRubyObject toInternalUnpackerRegistry(ThreadContext ctx) {
|
51
|
-
RubyHash hash = RubyHash.newHash(ctx.
|
46
|
+
RubyHash hash = RubyHash.newHash(ctx.runtime);
|
52
47
|
for (int typeIdIndex = 0 ; typeIdIndex < 256 ; typeIdIndex++) {
|
53
48
|
ExtensionEntry entry = extensionsByTypeId[typeIdIndex];
|
54
49
|
if (entry != null && entry.hasUnpacker()) {
|
55
|
-
IRubyObject typeId = RubyFixnum.newFixnum(ctx.
|
50
|
+
IRubyObject typeId = RubyFixnum.newFixnum(ctx.runtime, typeIdIndex - 128);
|
56
51
|
hash.put(typeId, entry.toUnpackerTuple(ctx));
|
57
52
|
}
|
58
53
|
}
|
59
54
|
return hash;
|
60
55
|
}
|
61
56
|
|
62
|
-
public void put(RubyModule mod, int typeId,
|
63
|
-
ExtensionEntry entry = new ExtensionEntry(mod, typeId,
|
57
|
+
public void put(RubyModule mod, int typeId, boolean recursive, IRubyObject packerProc, IRubyObject unpackerProc) {
|
58
|
+
ExtensionEntry entry = new ExtensionEntry(mod, typeId, recursive, packerProc, unpackerProc);
|
64
59
|
extensionsByModule.put(mod, entry);
|
65
60
|
extensionsByTypeId[typeId + 128] = entry;
|
66
61
|
extensionsByAncestor.clear();
|
67
62
|
}
|
68
63
|
|
69
|
-
public
|
64
|
+
public ExtensionEntry lookupExtensionByTypeId(int typeId) {
|
70
65
|
ExtensionEntry e = extensionsByTypeId[typeId + 128];
|
71
66
|
if (e != null && e.hasUnpacker()) {
|
72
|
-
return e
|
73
|
-
} else {
|
74
|
-
return null;
|
67
|
+
return e;
|
75
68
|
}
|
69
|
+
return null;
|
76
70
|
}
|
77
71
|
|
78
|
-
public
|
72
|
+
public ExtensionEntry lookupExtensionForObject(IRubyObject object) {
|
79
73
|
RubyModule lookupClass = null;
|
80
|
-
|
74
|
+
ExtensionEntry entry = null;
|
81
75
|
/*
|
82
76
|
* Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen
|
83
77
|
* String have no singleton class and raise a TypeError when trying to get
|
84
78
|
* it.
|
85
|
-
*
|
86
|
-
* Since all but symbols are already filtered out when reaching this code
|
87
|
-
* only symbols are checked here.
|
88
79
|
*/
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
return pair;
|
94
|
-
}
|
80
|
+
lookupClass = object.getMetaClass();
|
81
|
+
entry = extensionsByModule.get(lookupClass);
|
82
|
+
if (entry != null && entry.hasPacker()) {
|
83
|
+
return entry;
|
95
84
|
}
|
96
85
|
|
97
|
-
|
98
|
-
if (
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
lookupClass = object.getType(); // only for Symbol
|
104
|
-
}
|
105
|
-
ExtensionEntry e = findEntryByModuleOrAncestor(lookupClass);
|
106
|
-
if (e != null && e.hasPacker()) {
|
107
|
-
extensionsByAncestor.put(e.getExtensionModule(), e);
|
108
|
-
return e.toPackerProcTypeIdPair(lookupClass.getRuntime().getCurrentContext());
|
86
|
+
RubyModule realClass = object.getType();
|
87
|
+
if (realClass != lookupClass) {
|
88
|
+
entry = extensionsByModule.get(realClass);
|
89
|
+
if (entry != null && entry.hasPacker()) {
|
90
|
+
return entry;
|
91
|
+
}
|
109
92
|
}
|
110
|
-
return null;
|
111
|
-
}
|
112
93
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
e = extensionsByAncestor.get(mod);
|
117
|
-
}
|
118
|
-
if (e != null && e.hasPacker()) {
|
119
|
-
return e.toPackerProcTypeIdPair(mod.getRuntime().getCurrentContext());
|
94
|
+
entry = findEntryByModuleOrAncestor(lookupClass);
|
95
|
+
if (entry != null && entry.hasPacker()) {
|
96
|
+
return entry;
|
120
97
|
}
|
121
98
|
return null;
|
122
99
|
}
|
@@ -124,7 +101,7 @@ public class ExtensionRegistry {
|
|
124
101
|
private ExtensionEntry findEntryByModuleOrAncestor(final RubyModule mod) {
|
125
102
|
ThreadContext ctx = mod.getRuntime().getCurrentContext();
|
126
103
|
for (RubyModule extensionModule : extensionsByModule.keySet()) {
|
127
|
-
RubyArray ancestors = (RubyArray)
|
104
|
+
RubyArray<?> ancestors = (RubyArray)mod.callMethod(ctx, "ancestors");
|
128
105
|
if (ancestors.callMethod(ctx, "include?", extensionModule).isTrue()) {
|
129
106
|
return extensionsByModule.get(extensionModule);
|
130
107
|
}
|
@@ -132,21 +109,19 @@ public class ExtensionRegistry {
|
|
132
109
|
return null;
|
133
110
|
}
|
134
111
|
|
135
|
-
|
112
|
+
public static class ExtensionEntry {
|
136
113
|
private final RubyModule mod;
|
137
114
|
private final int typeId;
|
115
|
+
private final boolean recursive;
|
138
116
|
private final IRubyObject packerProc;
|
139
|
-
private final IRubyObject packerArg;
|
140
117
|
private final IRubyObject unpackerProc;
|
141
|
-
private final IRubyObject unpackerArg;
|
142
118
|
|
143
|
-
public ExtensionEntry(RubyModule mod, int typeId,
|
119
|
+
public ExtensionEntry(RubyModule mod, int typeId, boolean recursive, IRubyObject packerProc, IRubyObject unpackerProc) {
|
144
120
|
this.mod = mod;
|
145
121
|
this.typeId = typeId;
|
122
|
+
this.recursive = recursive;
|
146
123
|
this.packerProc = packerProc;
|
147
|
-
this.packerArg = packerArg;
|
148
124
|
this.unpackerProc = unpackerProc;
|
149
|
-
this.unpackerArg = unpackerArg;
|
150
125
|
}
|
151
126
|
|
152
127
|
public RubyModule getExtensionModule() {
|
@@ -157,12 +132,16 @@ public class ExtensionRegistry {
|
|
157
132
|
return typeId;
|
158
133
|
}
|
159
134
|
|
135
|
+
public boolean isRecursive() {
|
136
|
+
return recursive;
|
137
|
+
}
|
138
|
+
|
160
139
|
public boolean hasPacker() {
|
161
|
-
return packerProc != null;
|
140
|
+
return packerProc != null && !packerProc.isNil();
|
162
141
|
}
|
163
142
|
|
164
143
|
public boolean hasUnpacker() {
|
165
|
-
return unpackerProc != null;
|
144
|
+
return unpackerProc != null && !unpackerProc.isNil();
|
166
145
|
}
|
167
146
|
|
168
147
|
public IRubyObject getPackerProc() {
|
@@ -173,16 +152,16 @@ public class ExtensionRegistry {
|
|
173
152
|
return unpackerProc;
|
174
153
|
}
|
175
154
|
|
176
|
-
public RubyArray toPackerTuple(ThreadContext ctx) {
|
177
|
-
return
|
155
|
+
public RubyArray<?> toPackerTuple(ThreadContext ctx) {
|
156
|
+
return ctx.runtime.newArray(new IRubyObject[] {ctx.runtime.newFixnum(typeId), packerProc});
|
178
157
|
}
|
179
158
|
|
180
|
-
public RubyArray toUnpackerTuple(ThreadContext ctx) {
|
181
|
-
return
|
159
|
+
public RubyArray<?> toUnpackerTuple(ThreadContext ctx) {
|
160
|
+
return ctx.runtime.newArray(new IRubyObject[] {mod, unpackerProc});
|
182
161
|
}
|
183
162
|
|
184
163
|
public IRubyObject[] toPackerProcTypeIdPair(ThreadContext ctx) {
|
185
|
-
return new IRubyObject[] {packerProc,
|
164
|
+
return new IRubyObject[] {packerProc, ctx.runtime.newFixnum(typeId)};
|
186
165
|
}
|
187
166
|
}
|
188
167
|
}
|
@@ -25,7 +25,8 @@ import static org.msgpack.jruby.Types.*;
|
|
25
25
|
|
26
26
|
@JRubyClass(name="MessagePack::ExtensionValue")
|
27
27
|
public class ExtensionValue extends RubyObject {
|
28
|
-
private final
|
28
|
+
private static final long serialVersionUID = 8451274621449322492L;
|
29
|
+
private transient final Encoding binaryEncoding;
|
29
30
|
|
30
31
|
private RubyFixnum type;
|
31
32
|
private RubyString payload;
|
@@ -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();
|
@@ -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 {
|
26
|
-
private final
|
27
|
-
private final
|
28
|
+
private static final long serialVersionUID = 8441284623445322492L;
|
29
|
+
private transient final Ruby runtime;
|
30
|
+
private transient 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 = "
|
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,39 +74,21 @@ 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.
|
77
|
+
return RubyArray.newArray(ctx.runtime, new IRubyObject[] {
|
65
78
|
extensionRegistry.toInternalPackerRegistry(ctx),
|
66
79
|
extensionRegistry.toInternalUnpackerRegistry(ctx)
|
67
80
|
});
|
68
81
|
}
|
69
82
|
|
70
|
-
@JRubyMethod(name = "
|
71
|
-
public IRubyObject
|
72
|
-
|
73
|
-
IRubyObject type = args[0];
|
74
|
-
IRubyObject mod = args[1];
|
83
|
+
@JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE)
|
84
|
+
public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject opts) {
|
85
|
+
testFrozen("MessagePack::Factory");
|
75
86
|
|
76
|
-
|
77
|
-
|
87
|
+
Ruby runtime = ctx.runtime;
|
88
|
+
RubyHash options = (RubyHash) opts;
|
78
89
|
|
79
|
-
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
if (args.length == 2) {
|
84
|
-
packerArg = runtime.newSymbol("to_msgpack_ext");
|
85
|
-
unpackerArg = runtime.newSymbol("from_msgpack_ext");
|
86
|
-
} else if (args.length == 3) {
|
87
|
-
if (args[args.length - 1] instanceof RubyHash) {
|
88
|
-
RubyHash options = (RubyHash) args[args.length - 1];
|
89
|
-
packerArg = options.fastARef(runtime.newSymbol("packer"));
|
90
|
-
unpackerArg = options.fastARef(runtime.newSymbol("unpacker"));
|
91
|
-
} else {
|
92
|
-
throw runtime.newArgumentError(String.format("expected Hash but found %s.", args[args.length - 1].getType().getName()));
|
93
|
-
}
|
94
|
-
} else {
|
95
|
-
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 2..3)", 2 + args.length));
|
96
|
-
}
|
90
|
+
IRubyObject packerProc = options.fastARef(runtime.newSymbol("packer"));
|
91
|
+
IRubyObject unpackerProc = options.fastARef(runtime.newSymbol("unpacker"));
|
97
92
|
|
98
93
|
long typeId = ((RubyFixnum) type).getLongValue();
|
99
94
|
if (typeId < -128 || typeId > 127) {
|
@@ -105,25 +100,31 @@ public class Factory extends RubyObject {
|
|
105
100
|
}
|
106
101
|
RubyModule extModule = (RubyModule) mod;
|
107
102
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if (unpackerArg != null) {
|
114
|
-
if (unpackerArg instanceof RubyString || unpackerArg instanceof RubySymbol) {
|
115
|
-
unpackerProc = extModule.method(unpackerArg.callMethod(ctx, "to_sym"));
|
116
|
-
} else {
|
117
|
-
unpackerProc = unpackerArg.callMethod(ctx, "method", runtime.newSymbol("call"));
|
103
|
+
boolean recursive = false;
|
104
|
+
if (options != null) {
|
105
|
+
IRubyObject recursiveExtensionArg = options.fastARef(runtime.newSymbol("recursive"));
|
106
|
+
if (recursiveExtensionArg != null && recursiveExtensionArg.isTrue()) {
|
107
|
+
recursive = true;
|
118
108
|
}
|
119
109
|
}
|
120
110
|
|
121
|
-
extensionRegistry.put(extModule, (int) typeId,
|
111
|
+
extensionRegistry.put(extModule, (int) typeId, recursive, packerProc, unpackerProc);
|
122
112
|
|
123
|
-
if (extModule == runtime.getSymbol()) {
|
113
|
+
if (extModule == runtime.getSymbol() && !packerProc.isNil()) {
|
124
114
|
hasSymbolExtType = true;
|
125
115
|
}
|
126
116
|
|
117
|
+
if (options != null) {
|
118
|
+
IRubyObject oversizedIntegerExtensionArg = options.fastARef(runtime.newSymbol("oversized_integer_extension"));
|
119
|
+
if (oversizedIntegerExtensionArg != null && oversizedIntegerExtensionArg.isTrue()) {
|
120
|
+
if (extModule == runtime.getModule("Integer")) {
|
121
|
+
hasBigIntExtType = true;
|
122
|
+
} else {
|
123
|
+
throw runtime.newArgumentError("oversized_integer_extension: true is only for Integer class");
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
127
128
|
return runtime.getNil();
|
128
129
|
}
|
129
130
|
}
|
@@ -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
|
}
|