msgpack 1.1.0-x86-mingw32 → 1.2.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/doclib/msgpack/factory.rb +33 -0
- data/ext/java/org/msgpack/jruby/Factory.java +5 -0
- data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +0 -92
- data/ext/java/org/msgpack/jruby/Packer.java +70 -0
- data/ext/java/org/msgpack/jruby/Unpacker.java +6 -1
- data/ext/msgpack/factory_class.c +4 -5
- data/ext/msgpack/factory_class.h +0 -2
- data/ext/msgpack/packer_class.c +94 -33
- data/ext/msgpack/packer_class.h +0 -2
- data/ext/msgpack/rbinit.c +0 -2
- data/ext/msgpack/unpacker_class.c +2 -37
- data/ext/msgpack/unpacker_class.h +0 -2
- data/lib/msgpack.rb +32 -0
- data/lib/msgpack/core_ext.rb +139 -0
- data/lib/msgpack/factory.rb +21 -0
- data/lib/msgpack/version.rb +1 -1
- data/msgpack.gemspec +2 -2
- data/spec/factory_spec.rb +26 -0
- data/spec/packer_spec.rb +22 -0
- metadata +12 -13
- data/ext/msgpack/core_ext.c +0 -159
- data/ext/msgpack/core_ext.h +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c14dafc60f8a2d68c22006e7891636397a3c93c
|
4
|
+
data.tar.gz: e67291dc047e8b406b3792bda09be8517152393c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9153cbc455911a43e90a833bc7923246a91a493acb0c996f901ea73660924a4fd605f17166ebf6005674345bc2feb4bc7449d1986d90612a01cf5dd2796a3b8
|
7
|
+
data.tar.gz: 0b3580e1e142564498353a02f86dba9e3e52da0364d5c79d9771fbe6cc7ce85f033af86964404698b3b36ac8efbf16953d4ef7c16cd8421675a157fb2d2254da
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
2017-12-07 version 1.2.0:
|
2
|
+
|
3
|
+
* Add MessagePack::Factory#dump and MessagePack::Factory#load as convenient methods
|
4
|
+
like MessagePack.dump and MessagePack.load
|
5
|
+
* Fix bug to accept MessagePack::Factory#register_type after #freeze
|
6
|
+
|
1
7
|
2017-02-28 version 1.1.0:
|
2
8
|
|
3
9
|
* Fix the extention type handling to accept modules in addition to classes
|
data/doclib/msgpack/factory.rb
CHANGED
@@ -19,6 +19,22 @@ module MessagePack
|
|
19
19
|
def packer(*args)
|
20
20
|
end
|
21
21
|
|
22
|
+
#
|
23
|
+
# Serialize the passed value
|
24
|
+
#
|
25
|
+
# If it could not serialize the object, it raises
|
26
|
+
# NoMethodError: undefined method `to_msgpack' for #<the_object>.
|
27
|
+
#
|
28
|
+
# @param obj [Object] object to serialize
|
29
|
+
# @param options [Hash]
|
30
|
+
# @return [String] serialized object
|
31
|
+
#
|
32
|
+
# See Packer#initialize for supported options.
|
33
|
+
#
|
34
|
+
def dump(obj, options={})
|
35
|
+
end
|
36
|
+
alias pack dump
|
37
|
+
|
22
38
|
#
|
23
39
|
# Creates a MessagePack::Unpacker instance, which has ext types already registered.
|
24
40
|
# Options are passed to MessagePack::Unpacker#initialized.
|
@@ -28,6 +44,23 @@ module MessagePack
|
|
28
44
|
def unpacker(*args)
|
29
45
|
end
|
30
46
|
|
47
|
+
#
|
48
|
+
# Deserializes an object from the string or io and returns it.
|
49
|
+
#
|
50
|
+
# If there're not enough data to deserialize one object, this method raises EOFError.
|
51
|
+
# If data format is invalid, this method raises MessagePack::MalformedFormatError.
|
52
|
+
# If the object nests too deeply, this method raises MessagePack::StackError.
|
53
|
+
#
|
54
|
+
# @param data [String]
|
55
|
+
# @param options [Hash]
|
56
|
+
# @return [Object] deserialized object
|
57
|
+
#
|
58
|
+
# See Unpacker#initialize for supported options.
|
59
|
+
#
|
60
|
+
def load(data, options={})
|
61
|
+
end
|
62
|
+
alias unpack load
|
63
|
+
|
31
64
|
#
|
32
65
|
# Register a type and Class to be registered for packer and/or unpacker.
|
33
66
|
# If options are not speicified, factory will use :to_msgpack_ext for packer, and
|
@@ -75,6 +75,11 @@ public class Factory extends RubyObject {
|
|
75
75
|
|
76
76
|
IRubyObject packerArg;
|
77
77
|
IRubyObject unpackerArg;
|
78
|
+
|
79
|
+
if (isFrozen()) {
|
80
|
+
throw runtime.newRuntimeError("can't modify frozen Factory");
|
81
|
+
}
|
82
|
+
|
78
83
|
if (args.length == 2) {
|
79
84
|
packerArg = runtime.newSymbol("to_msgpack_ext");
|
80
85
|
unpackerArg = runtime.newSymbol("from_msgpack_ext");
|
@@ -20,11 +20,8 @@ import org.jruby.internal.runtime.methods.DynamicMethod;
|
|
20
20
|
|
21
21
|
|
22
22
|
public class MessagePackLibrary implements Library {
|
23
|
-
public static Factory defaultFactory;
|
24
|
-
|
25
23
|
public void load(Ruby runtime, boolean wrap) {
|
26
24
|
RubyModule msgpackModule = runtime.defineModule("MessagePack");
|
27
|
-
msgpackModule.defineAnnotatedMethods(MessagePackModule.class);
|
28
25
|
RubyClass standardErrorClass = runtime.getStandardError();
|
29
26
|
RubyClass unpackErrorClass = msgpackModule.defineClassUnder("UnpackError", standardErrorClass, standardErrorClass.getAllocator());
|
30
27
|
RubyClass underflowErrorClass = msgpackModule.defineClassUnder("UnderflowError", unpackErrorClass, unpackErrorClass.getAllocator());
|
@@ -44,94 +41,5 @@ public class MessagePackLibrary implements Library {
|
|
44
41
|
bufferClass.defineAnnotatedMethods(Buffer.class);
|
45
42
|
RubyClass factoryClass = msgpackModule.defineClassUnder("Factory", runtime.getObject(), new Factory.FactoryAllocator());
|
46
43
|
factoryClass.defineAnnotatedMethods(Factory.class);
|
47
|
-
defaultFactory = new Factory(runtime, factoryClass);
|
48
|
-
defaultFactory.initialize(runtime.getCurrentContext());
|
49
|
-
msgpackModule.defineConstant("DefaultFactory", defaultFactory);
|
50
|
-
installCoreExtensions(runtime);
|
51
|
-
}
|
52
|
-
|
53
|
-
private void installCoreExtensions(Ruby runtime) {
|
54
|
-
RubyClass extensionValueClass = runtime.getModule("MessagePack").getClass("ExtensionValue");
|
55
|
-
installCoreExtensions(
|
56
|
-
runtime,
|
57
|
-
runtime.getNilClass(),
|
58
|
-
runtime.getTrueClass(),
|
59
|
-
runtime.getFalseClass(),
|
60
|
-
runtime.getFixnum(),
|
61
|
-
runtime.getBignum(),
|
62
|
-
runtime.getFloat(),
|
63
|
-
runtime.getString(),
|
64
|
-
runtime.getArray(),
|
65
|
-
runtime.getHash(),
|
66
|
-
runtime.getSymbol(),
|
67
|
-
extensionValueClass
|
68
|
-
);
|
69
|
-
}
|
70
|
-
|
71
|
-
private void installCoreExtensions(Ruby runtime, RubyClass... classes) {
|
72
|
-
for (RubyClass cls : classes) {
|
73
|
-
cls.addMethod("to_msgpack", createToMsgpackMethod(runtime, cls));
|
74
|
-
}
|
75
|
-
}
|
76
|
-
|
77
|
-
private DynamicMethod createToMsgpackMethod(final Ruby runtime, RubyClass cls) {
|
78
|
-
return new DynamicMethod(cls, Visibility.PUBLIC, CallConfiguration.FrameNoneScopeNone) {
|
79
|
-
@Override
|
80
|
-
public IRubyObject call(ThreadContext context, IRubyObject recv, RubyModule clazz, String name, IRubyObject[] args, Block block) {
|
81
|
-
if (args.length == 0) {
|
82
|
-
IRubyObject[] allArgs = { recv };
|
83
|
-
return MessagePackModule.pack(runtime.getCurrentContext(), null, allArgs);
|
84
|
-
} else if (args.length == 1 && args[0] instanceof Packer) {
|
85
|
-
Packer packer = (Packer)args[0];
|
86
|
-
return packer.write(runtime.getCurrentContext(), recv);
|
87
|
-
} else if (args.length == 1) {
|
88
|
-
IRubyObject[] allArgs = { recv, args[0] };
|
89
|
-
return MessagePackModule.pack(runtime.getCurrentContext(), null, allArgs);
|
90
|
-
} else {
|
91
|
-
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 0..1)", args.length));
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
@Override
|
96
|
-
public DynamicMethod dup() {
|
97
|
-
return this;
|
98
|
-
}
|
99
|
-
};
|
100
|
-
}
|
101
|
-
|
102
|
-
@JRubyModule(name = "MessagePack")
|
103
|
-
public static class MessagePackModule {
|
104
|
-
@JRubyMethod(module = true, required = 1, optional = 1, alias = {"dump"})
|
105
|
-
public static IRubyObject pack(ThreadContext ctx, IRubyObject recv, IRubyObject[] args) {
|
106
|
-
IRubyObject[] extraArgs = null;
|
107
|
-
if (args.length == 0) {
|
108
|
-
extraArgs = new IRubyObject[] {};
|
109
|
-
} else {
|
110
|
-
extraArgs = new IRubyObject[args.length - 1];
|
111
|
-
System.arraycopy(args, 1, extraArgs, 0, args.length - 1);
|
112
|
-
}
|
113
|
-
Packer packer = MessagePackLibrary.defaultFactory.packer(ctx, extraArgs);
|
114
|
-
packer.write(ctx, args[0]);
|
115
|
-
return packer.toS(ctx);
|
116
|
-
}
|
117
|
-
|
118
|
-
@JRubyMethod(module = true, required = 1, optional = 1, alias = {"load"})
|
119
|
-
public static IRubyObject unpack(ThreadContext ctx, IRubyObject recv, IRubyObject[] args) {
|
120
|
-
ExtensionRegistry registry = MessagePackLibrary.defaultFactory.extensionRegistry();
|
121
|
-
|
122
|
-
boolean symbolizeKeys = false;
|
123
|
-
boolean allowUnknownExt = false;
|
124
|
-
if (args.length > 1 && !args[args.length - 1].isNil()) {
|
125
|
-
RubyHash hash = args[args.length - 1].convertToHash();
|
126
|
-
IRubyObject symbolizeKeysVal = hash.fastARef(ctx.getRuntime().newSymbol("symbolize_keys"));
|
127
|
-
symbolizeKeys = symbolizeKeysVal != null && symbolizeKeysVal.isTrue();
|
128
|
-
IRubyObject allowUnknownExtVal = hash.fastARef(ctx.getRuntime().newSymbol("allow_unknown_ext"));
|
129
|
-
allowUnknownExt = (allowUnknownExtVal != null && allowUnknownExtVal.isTrue());
|
130
|
-
}
|
131
|
-
byte[] bytes = args[0].asString().getBytes();
|
132
|
-
Decoder decoder = new Decoder(ctx.getRuntime(), registry, bytes, 0, bytes.length, symbolizeKeys, allowUnknownExt);
|
133
|
-
|
134
|
-
return decoder.next();
|
135
|
-
}
|
136
44
|
}
|
137
45
|
}
|
@@ -18,6 +18,8 @@ import org.jruby.anno.JRubyMethod;
|
|
18
18
|
import org.jruby.runtime.ThreadContext;
|
19
19
|
import org.jruby.runtime.ObjectAllocator;
|
20
20
|
import org.jruby.util.ByteList;
|
21
|
+
import org.jruby.util.TypeConverter;
|
22
|
+
import org.msgpack.jruby.ExtensionValue;
|
21
23
|
|
22
24
|
import static org.jruby.runtime.Visibility.PRIVATE;
|
23
25
|
|
@@ -121,6 +123,62 @@ public class Packer extends RubyObject {
|
|
121
123
|
return this;
|
122
124
|
}
|
123
125
|
|
126
|
+
@JRubyMethod(name = "write_float")
|
127
|
+
public IRubyObject writeFloat(ThreadContext ctx, IRubyObject obj) {
|
128
|
+
checkType(ctx, obj, org.jruby.RubyFloat.class);
|
129
|
+
return write(ctx, obj);
|
130
|
+
}
|
131
|
+
|
132
|
+
@JRubyMethod(name = "write_array")
|
133
|
+
public IRubyObject writeArray(ThreadContext ctx, IRubyObject obj) {
|
134
|
+
checkType(ctx, obj, org.jruby.RubyArray.class);
|
135
|
+
return write(ctx, obj);
|
136
|
+
}
|
137
|
+
|
138
|
+
@JRubyMethod(name = "write_string")
|
139
|
+
public IRubyObject writeString(ThreadContext ctx, IRubyObject obj) {
|
140
|
+
checkType(ctx, obj, org.jruby.RubyString.class);
|
141
|
+
return write(ctx, obj);
|
142
|
+
}
|
143
|
+
|
144
|
+
@JRubyMethod(name = "write_hash")
|
145
|
+
public IRubyObject writeHash(ThreadContext ctx, IRubyObject obj) {
|
146
|
+
checkType(ctx, obj, org.jruby.RubyHash.class);
|
147
|
+
return write(ctx, obj);
|
148
|
+
}
|
149
|
+
|
150
|
+
@JRubyMethod(name = "write_symbol")
|
151
|
+
public IRubyObject writeSymbol(ThreadContext ctx, IRubyObject obj) {
|
152
|
+
checkType(ctx, obj, org.jruby.RubySymbol.class);
|
153
|
+
return write(ctx, obj);
|
154
|
+
}
|
155
|
+
|
156
|
+
@JRubyMethod(name = "write_int")
|
157
|
+
public IRubyObject writeInt(ThreadContext ctx, IRubyObject obj) {
|
158
|
+
if (!(obj instanceof RubyFixnum)) {
|
159
|
+
checkType(ctx, obj, org.jruby.RubyBignum.class);
|
160
|
+
}
|
161
|
+
return write(ctx, obj);
|
162
|
+
}
|
163
|
+
|
164
|
+
@JRubyMethod(name = "write_extension")
|
165
|
+
public IRubyObject writeExtension(ThreadContext ctx, IRubyObject obj) {
|
166
|
+
if (!(obj instanceof ExtensionValue)) {
|
167
|
+
throw ctx.runtime.newTypeError("Expected extension");
|
168
|
+
}
|
169
|
+
return write(ctx, obj);
|
170
|
+
}
|
171
|
+
|
172
|
+
@JRubyMethod(name = "write_true")
|
173
|
+
public IRubyObject writeTrue(ThreadContext ctx) {
|
174
|
+
return write(ctx, ctx.getRuntime().getTrue());
|
175
|
+
}
|
176
|
+
|
177
|
+
@JRubyMethod(name = "write_false")
|
178
|
+
public IRubyObject writeFalse(ThreadContext ctx) {
|
179
|
+
return write(ctx, ctx.getRuntime().getFalse());
|
180
|
+
}
|
181
|
+
|
124
182
|
@JRubyMethod(name = "write_nil")
|
125
183
|
public IRubyObject writeNil(ThreadContext ctx) {
|
126
184
|
write(ctx, null);
|
@@ -151,6 +209,11 @@ public class Packer extends RubyObject {
|
|
151
209
|
return this;
|
152
210
|
}
|
153
211
|
|
212
|
+
@JRubyMethod(name = "full_pack")
|
213
|
+
public IRubyObject fullPack(ThreadContext ctx) {
|
214
|
+
return toS(ctx);
|
215
|
+
}
|
216
|
+
|
154
217
|
@JRubyMethod(name = "to_s", alias = { "to_str" })
|
155
218
|
public IRubyObject toS(ThreadContext ctx) {
|
156
219
|
return buffer.toS(ctx);
|
@@ -175,4 +238,11 @@ public class Packer extends RubyObject {
|
|
175
238
|
public IRubyObject clear(ThreadContext ctx) {
|
176
239
|
return buffer.clear(ctx);
|
177
240
|
}
|
241
|
+
|
242
|
+
private void checkType(ThreadContext ctx, IRubyObject obj, Class<? extends IRubyObject> expectedType) {
|
243
|
+
if (!expectedType.isInstance(obj)) {
|
244
|
+
String expectedName = expectedType.getName().substring("org.jruby.Ruby".length());
|
245
|
+
throw ctx.runtime.newTypeError(String.format("wrong argument type %s (expected %s)", obj.getMetaClass().toString(), expectedName));
|
246
|
+
}
|
247
|
+
}
|
178
248
|
}
|
@@ -68,7 +68,7 @@ public class Unpacker extends RubyObject {
|
|
68
68
|
allowUnknownExt = au.isTrue();
|
69
69
|
}
|
70
70
|
}
|
71
|
-
if (!(args[0] instanceof RubyHash)) {
|
71
|
+
if (args[0] != ctx.getRuntime().getNil() && !(args[0] instanceof RubyHash)) {
|
72
72
|
setStream(ctx, args[0]);
|
73
73
|
}
|
74
74
|
}
|
@@ -181,6 +181,11 @@ public class Unpacker extends RubyObject {
|
|
181
181
|
return this;
|
182
182
|
}
|
183
183
|
|
184
|
+
@JRubyMethod(name = "full_unpack")
|
185
|
+
public IRubyObject fullUnpack(ThreadContext ctx) {
|
186
|
+
return decoder.next();
|
187
|
+
}
|
188
|
+
|
184
189
|
@JRubyMethod(name = "feed_each", required = 1)
|
185
190
|
public IRubyObject feedEach(ThreadContext ctx, IRubyObject data, Block block) {
|
186
191
|
feed(ctx, data);
|
data/ext/msgpack/factory_class.c
CHANGED
@@ -24,7 +24,6 @@
|
|
24
24
|
#include "unpacker_class.h"
|
25
25
|
|
26
26
|
VALUE cMessagePack_Factory;
|
27
|
-
VALUE cMessagePack_DefaultFactory;
|
28
27
|
|
29
28
|
struct msgpack_factory_t;
|
30
29
|
typedef struct msgpack_factory_t msgpack_factory_t;
|
@@ -146,6 +145,10 @@ static VALUE Factory_register_type(int argc, VALUE* argv, VALUE self)
|
|
146
145
|
VALUE packer_arg, unpacker_arg;
|
147
146
|
VALUE packer_proc, unpacker_proc;
|
148
147
|
|
148
|
+
if (OBJ_FROZEN(self)) {
|
149
|
+
rb_raise(rb_eRuntimeError, "can't modify frozen Factory");
|
150
|
+
}
|
151
|
+
|
149
152
|
switch (argc) {
|
150
153
|
case 2:
|
151
154
|
/* register_type(0x7f, Time) */
|
@@ -214,8 +217,4 @@ void MessagePack_Factory_module_init(VALUE mMessagePack)
|
|
214
217
|
|
215
218
|
rb_define_private_method(cMessagePack_Factory, "registered_types_internal", Factory_registered_types_internal, 0);
|
216
219
|
rb_define_method(cMessagePack_Factory, "register_type", Factory_register_type, -1);
|
217
|
-
|
218
|
-
cMessagePack_DefaultFactory = Factory_alloc(cMessagePack_Factory);
|
219
|
-
Factory_initialize(0, NULL, cMessagePack_DefaultFactory);
|
220
|
-
rb_define_const(mMessagePack, "DefaultFactory", cMessagePack_DefaultFactory);
|
221
220
|
}
|
data/ext/msgpack/factory_class.h
CHANGED
data/ext/msgpack/packer_class.c
CHANGED
@@ -135,6 +135,88 @@ static VALUE Packer_write_nil(VALUE self)
|
|
135
135
|
return self;
|
136
136
|
}
|
137
137
|
|
138
|
+
static VALUE Packer_write_true(VALUE self)
|
139
|
+
{
|
140
|
+
PACKER(self, pk);
|
141
|
+
msgpack_packer_write_true(pk);
|
142
|
+
return self;
|
143
|
+
}
|
144
|
+
|
145
|
+
static VALUE Packer_write_false(VALUE self)
|
146
|
+
{
|
147
|
+
PACKER(self, pk);
|
148
|
+
msgpack_packer_write_false(pk);
|
149
|
+
return self;
|
150
|
+
}
|
151
|
+
|
152
|
+
static VALUE Packer_write_float(VALUE self, VALUE obj)
|
153
|
+
{
|
154
|
+
PACKER(self, pk);
|
155
|
+
msgpack_packer_write_float_value(pk, obj);
|
156
|
+
return self;
|
157
|
+
}
|
158
|
+
|
159
|
+
static VALUE Packer_write_string(VALUE self, VALUE obj)
|
160
|
+
{
|
161
|
+
PACKER(self, pk);
|
162
|
+
Check_Type(obj, T_STRING);
|
163
|
+
msgpack_packer_write_string_value(pk, obj);
|
164
|
+
return self;
|
165
|
+
}
|
166
|
+
|
167
|
+
static VALUE Packer_write_array(VALUE self, VALUE obj)
|
168
|
+
{
|
169
|
+
PACKER(self, pk);
|
170
|
+
Check_Type(obj, T_ARRAY);
|
171
|
+
msgpack_packer_write_array_value(pk, obj);
|
172
|
+
return self;
|
173
|
+
}
|
174
|
+
|
175
|
+
static VALUE Packer_write_hash(VALUE self, VALUE obj)
|
176
|
+
{
|
177
|
+
PACKER(self, pk);
|
178
|
+
Check_Type(obj, T_HASH);
|
179
|
+
msgpack_packer_write_hash_value(pk, obj);
|
180
|
+
return self;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE Packer_write_symbol(VALUE self, VALUE obj)
|
184
|
+
{
|
185
|
+
PACKER(self, pk);
|
186
|
+
Check_Type(obj, T_SYMBOL);
|
187
|
+
msgpack_packer_write_symbol_value(pk, obj);
|
188
|
+
return self;
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE Packer_write_int(VALUE self, VALUE obj)
|
192
|
+
{
|
193
|
+
PACKER(self, pk);
|
194
|
+
|
195
|
+
if (FIXNUM_P(obj)) {
|
196
|
+
msgpack_packer_write_fixnum_value(pk, obj);
|
197
|
+
} else {
|
198
|
+
Check_Type(obj, T_BIGNUM);
|
199
|
+
msgpack_packer_write_bignum_value(pk, obj);
|
200
|
+
}
|
201
|
+
return self;
|
202
|
+
}
|
203
|
+
|
204
|
+
static VALUE Packer_write_extension(VALUE self, VALUE obj)
|
205
|
+
{
|
206
|
+
PACKER(self, pk);
|
207
|
+
Check_Type(obj, T_STRUCT);
|
208
|
+
|
209
|
+
int ext_type = FIX2INT(RSTRUCT_GET(obj, 0));
|
210
|
+
if(ext_type < -128 || ext_type > 127) {
|
211
|
+
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
212
|
+
}
|
213
|
+
VALUE payload = RSTRUCT_GET(obj, 1);
|
214
|
+
StringValue(payload);
|
215
|
+
msgpack_packer_write_ext(pk, ext_type, payload);
|
216
|
+
|
217
|
+
return self;
|
218
|
+
}
|
219
|
+
|
138
220
|
static VALUE Packer_write_array_header(VALUE self, VALUE n)
|
139
221
|
{
|
140
222
|
PACKER(self, pk);
|
@@ -293,21 +375,12 @@ static VALUE Packer_register_type(int argc, VALUE* argv, VALUE self)
|
|
293
375
|
return Qnil;
|
294
376
|
}
|
295
377
|
|
296
|
-
VALUE
|
378
|
+
VALUE Packer_full_pack(VALUE self)
|
297
379
|
{
|
298
|
-
VALUE
|
299
|
-
|
300
|
-
if (argc < 0 || argc > 3) {
|
301
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", argc);
|
302
|
-
}
|
303
|
-
v = argv[0];
|
380
|
+
VALUE retval;
|
304
381
|
|
305
|
-
VALUE self = MessagePack_Factory_packer(argc - 1, argv + 1, cMessagePack_DefaultFactory);
|
306
382
|
PACKER(self, pk);
|
307
383
|
|
308
|
-
msgpack_packer_write_value(pk, v);
|
309
|
-
|
310
|
-
VALUE retval;
|
311
384
|
if(msgpack_buffer_has_io(PACKER_BUFFER_(pk))) {
|
312
385
|
msgpack_buffer_flush(PACKER_BUFFER_(pk));
|
313
386
|
retval = Qnil;
|
@@ -317,27 +390,9 @@ VALUE MessagePack_pack(int argc, VALUE* argv)
|
|
317
390
|
|
318
391
|
msgpack_buffer_clear(PACKER_BUFFER_(pk)); /* to free rmem before GC */
|
319
392
|
|
320
|
-
#ifdef RB_GC_GUARD
|
321
|
-
/* This prevents compilers from optimizing out the `self` variable
|
322
|
-
* from stack. Otherwise GC free()s it. */
|
323
|
-
RB_GC_GUARD(self);
|
324
|
-
#endif
|
325
|
-
|
326
393
|
return retval;
|
327
394
|
}
|
328
395
|
|
329
|
-
static VALUE MessagePack_dump_module_method(int argc, VALUE* argv, VALUE mod)
|
330
|
-
{
|
331
|
-
UNUSED(mod);
|
332
|
-
return MessagePack_pack(argc, argv);
|
333
|
-
}
|
334
|
-
|
335
|
-
static VALUE MessagePack_pack_module_method(int argc, VALUE* argv, VALUE mod)
|
336
|
-
{
|
337
|
-
UNUSED(mod);
|
338
|
-
return MessagePack_pack(argc, argv);
|
339
|
-
}
|
340
|
-
|
341
396
|
void MessagePack_Packer_module_init(VALUE mMessagePack)
|
342
397
|
{
|
343
398
|
s_to_msgpack = rb_intern("to_msgpack");
|
@@ -356,6 +411,15 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
|
|
356
411
|
rb_define_method(cMessagePack_Packer, "write", Packer_write, 1);
|
357
412
|
rb_define_alias(cMessagePack_Packer, "pack", "write");
|
358
413
|
rb_define_method(cMessagePack_Packer, "write_nil", Packer_write_nil, 0);
|
414
|
+
rb_define_method(cMessagePack_Packer, "write_true", Packer_write_true, 0);
|
415
|
+
rb_define_method(cMessagePack_Packer, "write_false", Packer_write_false, 0);
|
416
|
+
rb_define_method(cMessagePack_Packer, "write_float", Packer_write_float, 1);
|
417
|
+
rb_define_method(cMessagePack_Packer, "write_string", Packer_write_string, 1);
|
418
|
+
rb_define_method(cMessagePack_Packer, "write_array", Packer_write_array, 1);
|
419
|
+
rb_define_method(cMessagePack_Packer, "write_hash", Packer_write_hash, 1);
|
420
|
+
rb_define_method(cMessagePack_Packer, "write_symbol", Packer_write_symbol, 1);
|
421
|
+
rb_define_method(cMessagePack_Packer, "write_int", Packer_write_int, 1);
|
422
|
+
rb_define_method(cMessagePack_Packer, "write_extension", Packer_write_extension, 1);
|
359
423
|
rb_define_method(cMessagePack_Packer, "write_array_header", Packer_write_array_header, 1);
|
360
424
|
rb_define_method(cMessagePack_Packer, "write_map_header", Packer_write_map_header, 1);
|
361
425
|
rb_define_method(cMessagePack_Packer, "write_ext", Packer_write_ext, 2);
|
@@ -380,8 +444,5 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
|
|
380
444
|
//rb_gc_register_address(&s_packer_value);
|
381
445
|
//Data_Get_Struct(s_packer_value, msgpack_packer_t, s_packer);
|
382
446
|
|
383
|
-
|
384
|
-
rb_define_module_function(mMessagePack, "pack", MessagePack_pack_module_method, -1);
|
385
|
-
rb_define_module_function(mMessagePack, "dump", MessagePack_dump_module_method, -1);
|
447
|
+
rb_define_method(cMessagePack_Packer, "full_pack", Packer_full_pack, 0);
|
386
448
|
}
|
387
|
-
|
data/ext/msgpack/packer_class.h
CHANGED
data/ext/msgpack/rbinit.c
CHANGED
@@ -21,7 +21,6 @@
|
|
21
21
|
#include "unpacker_class.h"
|
22
22
|
#include "factory_class.h"
|
23
23
|
#include "extension_value_class.h"
|
24
|
-
#include "core_ext.h"
|
25
24
|
|
26
25
|
void Init_msgpack(void)
|
27
26
|
{
|
@@ -32,6 +31,5 @@ void Init_msgpack(void)
|
|
32
31
|
MessagePack_Unpacker_module_init(mMessagePack);
|
33
32
|
MessagePack_Factory_module_init(mMessagePack);
|
34
33
|
MessagePack_ExtensionValue_module_init(mMessagePack);
|
35
|
-
MessagePack_core_ext_module_init();
|
36
34
|
}
|
37
35
|
|
@@ -383,23 +383,8 @@ static VALUE Unpacker_register_type(int argc, VALUE* argv, VALUE self)
|
|
383
383
|
return Qnil;
|
384
384
|
}
|
385
385
|
|
386
|
-
VALUE
|
386
|
+
static VALUE Unpacker_full_unpack(VALUE self)
|
387
387
|
{
|
388
|
-
VALUE src;
|
389
|
-
VALUE self;
|
390
|
-
|
391
|
-
if (argc < 0 || argc > 2) {
|
392
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
393
|
-
}
|
394
|
-
src = argv[0];
|
395
|
-
|
396
|
-
if(rb_type(src) == T_STRING) {
|
397
|
-
self = MessagePack_Factory_unpacker(argc - 1, argv + 1, cMessagePack_DefaultFactory);
|
398
|
-
UNPACKER(self, uk);
|
399
|
-
msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), src);
|
400
|
-
} else {
|
401
|
-
self = MessagePack_Factory_unpacker(argc, argv, cMessagePack_DefaultFactory);
|
402
|
-
}
|
403
388
|
UNPACKER(self, uk);
|
404
389
|
|
405
390
|
/* prefer reference than copying; see MessagePack_Unpacker_module_init */
|
@@ -416,27 +401,9 @@ VALUE MessagePack_unpack(int argc, VALUE* argv)
|
|
416
401
|
rb_raise(eMalformedFormatError, "%zd extra bytes after the deserialized object", extra);
|
417
402
|
}
|
418
403
|
|
419
|
-
#ifdef RB_GC_GUARD
|
420
|
-
/* This prevents compilers from optimizing out the `self` variable
|
421
|
-
* from stack. Otherwise GC free()s it. */
|
422
|
-
RB_GC_GUARD(self);
|
423
|
-
#endif
|
424
|
-
|
425
404
|
return msgpack_unpacker_get_last_object(uk);
|
426
405
|
}
|
427
406
|
|
428
|
-
static VALUE MessagePack_load_module_method(int argc, VALUE* argv, VALUE mod)
|
429
|
-
{
|
430
|
-
UNUSED(mod);
|
431
|
-
return MessagePack_unpack(argc, argv);
|
432
|
-
}
|
433
|
-
|
434
|
-
static VALUE MessagePack_unpack_module_method(int argc, VALUE* argv, VALUE mod)
|
435
|
-
{
|
436
|
-
UNUSED(mod);
|
437
|
-
return MessagePack_unpack(argc, argv);
|
438
|
-
}
|
439
|
-
|
440
407
|
VALUE MessagePack_Unpacker_new(int argc, VALUE* argv)
|
441
408
|
{
|
442
409
|
VALUE self = MessagePack_Unpacker_alloc(cMessagePack_Unpacker);
|
@@ -491,8 +458,6 @@ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
|
|
491
458
|
/* prefer reference than copying */
|
492
459
|
//msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
|
493
460
|
|
494
|
-
|
495
|
-
rb_define_module_function(mMessagePack, "load", MessagePack_load_module_method, -1);
|
496
|
-
rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack_module_method, -1);
|
461
|
+
rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0);
|
497
462
|
}
|
498
463
|
|
data/lib/msgpack.rb
CHANGED
@@ -16,3 +16,35 @@ require "msgpack/packer"
|
|
16
16
|
require "msgpack/unpacker"
|
17
17
|
require "msgpack/factory"
|
18
18
|
require "msgpack/symbol"
|
19
|
+
require "msgpack/core_ext"
|
20
|
+
|
21
|
+
module MessagePack
|
22
|
+
DefaultFactory = MessagePack::Factory.new
|
23
|
+
|
24
|
+
def load(src, param = nil)
|
25
|
+
unpacker = nil
|
26
|
+
|
27
|
+
if src.is_a? String
|
28
|
+
unpacker = DefaultFactory.unpacker param
|
29
|
+
unpacker.feed src
|
30
|
+
else
|
31
|
+
unpacker = DefaultFactory.unpacker src, param
|
32
|
+
end
|
33
|
+
|
34
|
+
unpacker.full_unpack
|
35
|
+
end
|
36
|
+
alias :unpack :load
|
37
|
+
|
38
|
+
module_function :load
|
39
|
+
module_function :unpack
|
40
|
+
|
41
|
+
def pack(v, *rest)
|
42
|
+
packer = DefaultFactory.packer(*rest)
|
43
|
+
packer.write v
|
44
|
+
packer.full_pack
|
45
|
+
end
|
46
|
+
alias :dump :pack
|
47
|
+
|
48
|
+
module_function :pack
|
49
|
+
module_function :dump
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module MessagePack
|
2
|
+
module CoreExt
|
3
|
+
def to_msgpack(packer_or_io = nil)
|
4
|
+
if packer_or_io
|
5
|
+
if packer_or_io.is_a?(MessagePack::Packer)
|
6
|
+
to_msgpack_with_packer packer_or_io
|
7
|
+
else
|
8
|
+
MessagePack.pack(self, packer_or_io)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
MessagePack.pack(self)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class NilClass
|
18
|
+
include MessagePack::CoreExt
|
19
|
+
|
20
|
+
private
|
21
|
+
def to_msgpack_with_packer(packer)
|
22
|
+
packer.write_nil
|
23
|
+
packer
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TrueClass
|
28
|
+
include MessagePack::CoreExt
|
29
|
+
|
30
|
+
private
|
31
|
+
def to_msgpack_with_packer(packer)
|
32
|
+
packer.write_true
|
33
|
+
packer
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class FalseClass
|
38
|
+
include MessagePack::CoreExt
|
39
|
+
|
40
|
+
private
|
41
|
+
def to_msgpack_with_packer(packer)
|
42
|
+
packer.write_false
|
43
|
+
packer
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Float
|
48
|
+
include MessagePack::CoreExt
|
49
|
+
|
50
|
+
private
|
51
|
+
def to_msgpack_with_packer(packer)
|
52
|
+
packer.write_float self
|
53
|
+
packer
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class String
|
58
|
+
include MessagePack::CoreExt
|
59
|
+
|
60
|
+
private
|
61
|
+
def to_msgpack_with_packer(packer)
|
62
|
+
packer.write_string self
|
63
|
+
packer
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Array
|
68
|
+
include MessagePack::CoreExt
|
69
|
+
|
70
|
+
private
|
71
|
+
def to_msgpack_with_packer(packer)
|
72
|
+
packer.write_array self
|
73
|
+
packer
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Hash
|
78
|
+
include MessagePack::CoreExt
|
79
|
+
|
80
|
+
private
|
81
|
+
def to_msgpack_with_packer(packer)
|
82
|
+
packer.write_hash self
|
83
|
+
packer
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class Symbol
|
88
|
+
include MessagePack::CoreExt
|
89
|
+
|
90
|
+
private
|
91
|
+
def to_msgpack_with_packer(packer)
|
92
|
+
packer.write_symbol self
|
93
|
+
packer
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
if 1.class.name == "Integer"
|
98
|
+
class Integer
|
99
|
+
include MessagePack::CoreExt
|
100
|
+
|
101
|
+
private
|
102
|
+
def to_msgpack_with_packer(packer)
|
103
|
+
packer.write_int self
|
104
|
+
packer
|
105
|
+
end
|
106
|
+
end
|
107
|
+
else
|
108
|
+
class Fixnum
|
109
|
+
include MessagePack::CoreExt
|
110
|
+
|
111
|
+
private
|
112
|
+
def to_msgpack_with_packer(packer)
|
113
|
+
packer.write_int self
|
114
|
+
packer
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Bignum
|
119
|
+
include MessagePack::CoreExt
|
120
|
+
|
121
|
+
private
|
122
|
+
def to_msgpack_with_packer(packer)
|
123
|
+
packer.write_int self
|
124
|
+
packer
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
module MessagePack
|
130
|
+
class ExtensionValue
|
131
|
+
include CoreExt
|
132
|
+
|
133
|
+
private
|
134
|
+
def to_msgpack_with_packer(packer)
|
135
|
+
packer.write_extension self
|
136
|
+
packer
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/msgpack/factory.rb
CHANGED
@@ -56,5 +56,26 @@ module MessagePack
|
|
56
56
|
raise ArgumentError, "class or type id"
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
def load(src, param = nil)
|
61
|
+
unpacker = nil
|
62
|
+
|
63
|
+
if src.is_a? String
|
64
|
+
unpacker = unpacker(param)
|
65
|
+
unpacker.feed(src)
|
66
|
+
else
|
67
|
+
unpacker = unpacker(src, param)
|
68
|
+
end
|
69
|
+
|
70
|
+
unpacker.full_unpack
|
71
|
+
end
|
72
|
+
alias :unpack :load
|
73
|
+
|
74
|
+
def dump(v, *rest)
|
75
|
+
packer = packer(*rest)
|
76
|
+
packer.write(v)
|
77
|
+
packer.full_pack
|
78
|
+
end
|
79
|
+
alias :pack :dump
|
59
80
|
end
|
60
81
|
end
|
data/lib/msgpack/version.rb
CHANGED
data/msgpack.gemspec
CHANGED
@@ -23,12 +23,12 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
24
24
|
|
25
25
|
s.add_development_dependency 'bundler', ['~> 1.0']
|
26
|
-
s.add_development_dependency 'rake'
|
26
|
+
s.add_development_dependency 'rake'
|
27
27
|
s.add_development_dependency 'rake-compiler', ['~> 1.0']
|
28
28
|
if /java/ !~ RUBY_PLATFORM
|
29
29
|
s.add_development_dependency 'rake-compiler-dock', ['~> 0.6.0']
|
30
30
|
end
|
31
31
|
s.add_development_dependency 'rspec', ['~> 3.3']
|
32
|
-
s.add_development_dependency 'yard'
|
32
|
+
s.add_development_dependency 'yard'
|
33
33
|
s.add_development_dependency 'json'
|
34
34
|
end
|
data/spec/factory_spec.rb
CHANGED
@@ -44,6 +44,32 @@ describe MessagePack::Factory do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
describe '#dump and #load' do
|
48
|
+
it 'can be used like a standard coder' do
|
49
|
+
subject.register_type(0x00, Symbol)
|
50
|
+
expect(subject.load(subject.dump(:symbol))).to be == :symbol
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is alias as pack and unpack' do
|
54
|
+
subject.register_type(0x00, Symbol)
|
55
|
+
expect(subject.unpack(subject.pack(:symbol))).to be == :symbol
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'accept options' do
|
59
|
+
hash = subject.unpack(MessagePack.pack('k' => 'v'), symbolize_keys: true)
|
60
|
+
expect(hash).to be == { k: 'v' }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#freeze' do
|
65
|
+
it 'can freeze factory instance to deny new registrations anymore' do
|
66
|
+
subject.register_type(0x00, Symbol)
|
67
|
+
subject.freeze
|
68
|
+
expect(subject.frozen?).to be_truthy
|
69
|
+
expect{ subject.register_type(0x01, Array) }.to raise_error(RuntimeError, "can't modify frozen Factory")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
47
73
|
class MyType
|
48
74
|
def initialize(a, b)
|
49
75
|
@a = a
|
data/spec/packer_spec.rb
CHANGED
@@ -178,6 +178,28 @@ describe MessagePack::Packer do
|
|
178
178
|
Array.new.to_msgpack.class.should == String
|
179
179
|
end
|
180
180
|
|
181
|
+
it 'to_msgpack with packer equals to_msgpack' do
|
182
|
+
nil.to_msgpack(MessagePack::Packer.new).to_str.should == nil.to_msgpack
|
183
|
+
true.to_msgpack(MessagePack::Packer.new).to_str.should == true.to_msgpack
|
184
|
+
false.to_msgpack(MessagePack::Packer.new).to_str.should == false.to_msgpack
|
185
|
+
1.to_msgpack(MessagePack::Packer.new).to_str.should == 1.to_msgpack
|
186
|
+
1.0.to_msgpack(MessagePack::Packer.new).to_str.should == 1.0.to_msgpack
|
187
|
+
"".to_msgpack(MessagePack::Packer.new).to_str.should == "".to_msgpack
|
188
|
+
Hash.new.to_msgpack(MessagePack::Packer.new).to_str.should == Hash.new.to_msgpack
|
189
|
+
Array.new.to_msgpack(MessagePack::Packer.new).to_str.should == Array.new.to_msgpack
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'raises type error on wrong type' do
|
193
|
+
packer = MessagePack::Packer.new
|
194
|
+
expect { packer.write_float "hello" }.to raise_error(TypeError)
|
195
|
+
expect { packer.write_string 1 }.to raise_error(TypeError)
|
196
|
+
expect { packer.write_array "hello" }.to raise_error(TypeError)
|
197
|
+
expect { packer.write_hash "hello" }.to raise_error(TypeError)
|
198
|
+
expect { packer.write_symbol "hello" }.to raise_error(TypeError)
|
199
|
+
expect { packer.write_int "hello" }.to raise_error(TypeError)
|
200
|
+
expect { packer.write_extension "hello" }.to raise_error(TypeError)
|
201
|
+
end
|
202
|
+
|
181
203
|
class CustomPack01
|
182
204
|
def to_msgpack(pk=nil)
|
183
205
|
return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: x86-mingw32
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-12-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -30,16 +30,16 @@ dependencies:
|
|
30
30
|
name: rake
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - "
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0
|
35
|
+
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - "
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0
|
42
|
+
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rake-compiler
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,16 +86,16 @@ dependencies:
|
|
86
86
|
name: yard
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- - "
|
89
|
+
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version: 0
|
91
|
+
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- - "
|
96
|
+
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
version: 0
|
98
|
+
version: '0'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
100
|
name: json
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,8 +163,6 @@ files:
|
|
163
163
|
- ext/msgpack/buffer_class.c
|
164
164
|
- ext/msgpack/buffer_class.h
|
165
165
|
- ext/msgpack/compat.h
|
166
|
-
- ext/msgpack/core_ext.c
|
167
|
-
- ext/msgpack/core_ext.h
|
168
166
|
- ext/msgpack/extconf.rb
|
169
167
|
- ext/msgpack/extension_value_class.c
|
170
168
|
- ext/msgpack/extension_value_class.h
|
@@ -194,6 +192,7 @@ files:
|
|
194
192
|
- lib/msgpack/2.2/msgpack.so
|
195
193
|
- lib/msgpack/2.3/msgpack.so
|
196
194
|
- lib/msgpack/2.4/msgpack.so
|
195
|
+
- lib/msgpack/core_ext.rb
|
197
196
|
- lib/msgpack/factory.rb
|
198
197
|
- lib/msgpack/packer.rb
|
199
198
|
- lib/msgpack/symbol.rb
|
@@ -247,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
247
246
|
version: '0'
|
248
247
|
requirements: []
|
249
248
|
rubyforge_project: msgpack
|
250
|
-
rubygems_version: 2.6.
|
249
|
+
rubygems_version: 2.6.12
|
251
250
|
signing_key:
|
252
251
|
specification_version: 4
|
253
252
|
summary: MessagePack, a binary-based efficient data interchange format.
|
data/ext/msgpack/core_ext.c
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* MessagePack for Ruby
|
3
|
-
*
|
4
|
-
* Copyright (C) 2008-2013 Sadayuki Furuhashi
|
5
|
-
*
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
* you may not use this file except in compliance with the License.
|
8
|
-
* You may obtain a copy of the License at
|
9
|
-
*
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
*
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
* See the License for the specific language governing permissions and
|
16
|
-
* limitations under the License.
|
17
|
-
*/
|
18
|
-
|
19
|
-
#include "core_ext.h"
|
20
|
-
#include "packer.h"
|
21
|
-
#include "packer_class.h"
|
22
|
-
#include "extension_value_class.h"
|
23
|
-
|
24
|
-
static inline VALUE delegete_to_pack(int argc, VALUE* argv, VALUE self)
|
25
|
-
{
|
26
|
-
if(argc == 0) {
|
27
|
-
return MessagePack_pack(1, &self);
|
28
|
-
} else if(argc == 1) {
|
29
|
-
/* write to io */
|
30
|
-
VALUE argv2[2];
|
31
|
-
argv2[0] = self;
|
32
|
-
argv2[1] = argv[0];
|
33
|
-
return MessagePack_pack(2, argv2);
|
34
|
-
} else {
|
35
|
-
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
#define ENSURE_PACKER(argc, argv, packer, pk) \
|
40
|
-
if(argc != 1 || rb_class_of(argv[0]) != cMessagePack_Packer) { \
|
41
|
-
return delegete_to_pack(argc, argv, self); \
|
42
|
-
} \
|
43
|
-
VALUE packer = argv[0]; \
|
44
|
-
msgpack_packer_t *pk; \
|
45
|
-
Data_Get_Struct(packer, msgpack_packer_t, pk);
|
46
|
-
|
47
|
-
static VALUE NilClass_to_msgpack(int argc, VALUE* argv, VALUE self)
|
48
|
-
{
|
49
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
50
|
-
msgpack_packer_write_nil(pk);
|
51
|
-
return packer;
|
52
|
-
}
|
53
|
-
|
54
|
-
static VALUE TrueClass_to_msgpack(int argc, VALUE* argv, VALUE self)
|
55
|
-
{
|
56
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
57
|
-
msgpack_packer_write_true(pk);
|
58
|
-
return packer;
|
59
|
-
}
|
60
|
-
|
61
|
-
static VALUE FalseClass_to_msgpack(int argc, VALUE* argv, VALUE self)
|
62
|
-
{
|
63
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
64
|
-
msgpack_packer_write_false(pk);
|
65
|
-
return packer;
|
66
|
-
}
|
67
|
-
|
68
|
-
static VALUE Integer_to_msgpack(int argc, VALUE* argv, VALUE self)
|
69
|
-
{
|
70
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
71
|
-
if (FIXNUM_P(self)) {
|
72
|
-
msgpack_packer_write_fixnum_value(pk, self);
|
73
|
-
} else {
|
74
|
-
msgpack_packer_write_bignum_value(pk, self);
|
75
|
-
}
|
76
|
-
return packer;
|
77
|
-
}
|
78
|
-
|
79
|
-
static VALUE Fixnum_to_msgpack(int argc, VALUE* argv, VALUE self)
|
80
|
-
{
|
81
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
82
|
-
msgpack_packer_write_fixnum_value(pk, self);
|
83
|
-
return packer;
|
84
|
-
}
|
85
|
-
|
86
|
-
static VALUE Bignum_to_msgpack(int argc, VALUE* argv, VALUE self)
|
87
|
-
{
|
88
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
89
|
-
msgpack_packer_write_bignum_value(pk, self);
|
90
|
-
return packer;
|
91
|
-
}
|
92
|
-
|
93
|
-
static VALUE Float_to_msgpack(int argc, VALUE* argv, VALUE self)
|
94
|
-
{
|
95
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
96
|
-
msgpack_packer_write_float_value(pk, self);
|
97
|
-
return packer;
|
98
|
-
}
|
99
|
-
|
100
|
-
static VALUE String_to_msgpack(int argc, VALUE* argv, VALUE self)
|
101
|
-
{
|
102
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
103
|
-
msgpack_packer_write_string_value(pk, self);
|
104
|
-
return packer;
|
105
|
-
}
|
106
|
-
|
107
|
-
static VALUE Array_to_msgpack(int argc, VALUE* argv, VALUE self)
|
108
|
-
{
|
109
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
110
|
-
msgpack_packer_write_array_value(pk, self);
|
111
|
-
return packer;
|
112
|
-
}
|
113
|
-
|
114
|
-
static VALUE Hash_to_msgpack(int argc, VALUE* argv, VALUE self)
|
115
|
-
{
|
116
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
117
|
-
msgpack_packer_write_hash_value(pk, self);
|
118
|
-
return packer;
|
119
|
-
}
|
120
|
-
|
121
|
-
static VALUE Symbol_to_msgpack(int argc, VALUE* argv, VALUE self)
|
122
|
-
{
|
123
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
124
|
-
msgpack_packer_write_symbol_value(pk, self);
|
125
|
-
return packer;
|
126
|
-
}
|
127
|
-
|
128
|
-
static VALUE ExtensionValue_to_msgpack(int argc, VALUE* argv, VALUE self)
|
129
|
-
{
|
130
|
-
ENSURE_PACKER(argc, argv, packer, pk);
|
131
|
-
int ext_type = FIX2INT(RSTRUCT_GET(self, 0));
|
132
|
-
if(ext_type < -128 || ext_type > 127) {
|
133
|
-
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
134
|
-
}
|
135
|
-
VALUE payload = RSTRUCT_GET(self, 1);
|
136
|
-
StringValue(payload);
|
137
|
-
msgpack_packer_write_ext(pk, ext_type, payload);
|
138
|
-
return packer;
|
139
|
-
}
|
140
|
-
|
141
|
-
void MessagePack_core_ext_module_init()
|
142
|
-
{
|
143
|
-
rb_define_method(rb_cNilClass, "to_msgpack", NilClass_to_msgpack, -1);
|
144
|
-
rb_define_method(rb_cTrueClass, "to_msgpack", TrueClass_to_msgpack, -1);
|
145
|
-
rb_define_method(rb_cFalseClass, "to_msgpack", FalseClass_to_msgpack, -1);
|
146
|
-
#ifdef RUBY_INTEGER_UNIFICATION
|
147
|
-
rb_define_method(rb_cInteger, "to_msgpack", Integer_to_msgpack, -1);
|
148
|
-
#else
|
149
|
-
rb_define_method(rb_cFixnum, "to_msgpack", Fixnum_to_msgpack, -1);
|
150
|
-
rb_define_method(rb_cBignum, "to_msgpack", Bignum_to_msgpack, -1);
|
151
|
-
#endif
|
152
|
-
rb_define_method(rb_cFloat, "to_msgpack", Float_to_msgpack, -1);
|
153
|
-
rb_define_method(rb_cString, "to_msgpack", String_to_msgpack, -1);
|
154
|
-
rb_define_method(rb_cArray, "to_msgpack", Array_to_msgpack, -1);
|
155
|
-
rb_define_method(rb_cHash, "to_msgpack", Hash_to_msgpack, -1);
|
156
|
-
rb_define_method(rb_cSymbol, "to_msgpack", Symbol_to_msgpack, -1);
|
157
|
-
rb_define_method(cMessagePack_ExtensionValue, "to_msgpack", ExtensionValue_to_msgpack, -1);
|
158
|
-
}
|
159
|
-
|
data/ext/msgpack/core_ext.h
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* MessagePack for Ruby
|
3
|
-
*
|
4
|
-
* Copyright (C) 2008-2013 Sadayuki Furuhashi
|
5
|
-
*
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
* you may not use this file except in compliance with the License.
|
8
|
-
* You may obtain a copy of the License at
|
9
|
-
*
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
*
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
* See the License for the specific language governing permissions and
|
16
|
-
* limitations under the License.
|
17
|
-
*/
|
18
|
-
#ifndef MSGPACK_RUBY_CORE_EXT_H__
|
19
|
-
#define MSGPACK_RUBY_CORE_EXT_H__
|
20
|
-
|
21
|
-
#include "compat.h"
|
22
|
-
|
23
|
-
void MessagePack_core_ext_module_init();
|
24
|
-
|
25
|
-
#endif
|
26
|
-
|