msgpack 0.6.2-x86-mingw32 → 0.7.0dev1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -0
- data/README.rdoc +2 -6
- data/Rakefile +9 -0
- data/appveyor.yml +18 -0
- data/doclib/msgpack/error.rb +6 -1
- data/doclib/msgpack/extension_value.rb +9 -0
- data/doclib/msgpack/factory.rb +68 -0
- data/doclib/msgpack/packer.rb +38 -0
- data/doclib/msgpack/unpacker.rb +39 -2
- data/ext/java/org/msgpack/jruby/Buffer.java +4 -0
- data/ext/java/org/msgpack/jruby/Decoder.java +44 -0
- data/ext/java/org/msgpack/jruby/Encoder.java +46 -4
- data/ext/java/org/msgpack/jruby/ExtensionValue.java +55 -60
- data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +18 -5
- data/ext/java/org/msgpack/jruby/Packer.java +17 -4
- data/ext/java/org/msgpack/jruby/Unpacker.java +59 -2
- data/ext/msgpack/buffer_class.c +2 -2
- data/ext/msgpack/buffer_class.h +1 -1
- data/ext/msgpack/compat.h +12 -0
- data/ext/msgpack/core_ext.c +15 -0
- data/ext/msgpack/extconf.rb +4 -1
- data/ext/msgpack/extension_value_class.c +34 -0
- data/ext/msgpack/extension_value_class.h +31 -0
- data/ext/msgpack/factory_class.c +213 -0
- data/ext/msgpack/factory_class.h +35 -0
- data/ext/msgpack/packer.c +14 -7
- data/ext/msgpack/packer.h +46 -8
- data/ext/msgpack/packer_class.c +92 -45
- data/ext/msgpack/packer_class.h +4 -2
- data/ext/msgpack/packer_ext_registry.c +87 -0
- data/ext/msgpack/packer_ext_registry.h +101 -0
- data/ext/msgpack/rbinit.c +4 -0
- data/ext/msgpack/unpacker.c +128 -23
- data/ext/msgpack/unpacker.h +11 -0
- data/ext/msgpack/unpacker_class.c +117 -38
- data/ext/msgpack/unpacker_class.h +4 -2
- data/ext/msgpack/unpacker_ext_registry.c +68 -0
- data/ext/msgpack/unpacker_ext_registry.h +62 -0
- data/lib/msgpack.rb +4 -0
- data/lib/msgpack/factory.rb +60 -0
- data/lib/msgpack/packer.rb +28 -0
- data/lib/msgpack/unpacker.rb +28 -0
- data/lib/msgpack/version.rb +1 -1
- data/msgpack.gemspec +4 -3
- data/spec/cruby/buffer_io_spec.rb +2 -3
- data/spec/cruby/buffer_spec.rb +1 -3
- data/spec/cruby/unpacker_spec.rb +14 -2
- data/spec/ext_value_spec.rb +99 -0
- data/spec/exttypes.rb +51 -0
- data/spec/factory_spec.rb +236 -0
- data/spec/jruby/msgpack/unpacker_spec.rb +25 -0
- data/spec/{jruby/msgpack_spec.rb → msgpack_spec.rb} +1 -1
- data/spec/pack_spec.rb +0 -6
- data/spec/packer_spec.rb +95 -0
- data/spec/spec_helper.rb +12 -1
- data/spec/unpack_spec.rb +1 -4
- data/spec/unpacker_spec.rb +133 -0
- metadata +50 -15
- data/Dockerfile +0 -55
@@ -55,62 +55,6 @@ public class ExtensionValue extends RubyObject {
|
|
55
55
|
return this;
|
56
56
|
}
|
57
57
|
|
58
|
-
@JRubyMethod(name = "to_msgpack")
|
59
|
-
public IRubyObject toMsgpack() {
|
60
|
-
ByteList payloadBytes = payload.getByteList();
|
61
|
-
int payloadSize = payloadBytes.length();
|
62
|
-
int outputSize = 0;
|
63
|
-
boolean fixSize = payloadSize == 1 || payloadSize == 2 || payloadSize == 4 || payloadSize == 8 || payloadSize == 16;
|
64
|
-
if (fixSize) {
|
65
|
-
outputSize = 2 + payloadSize;
|
66
|
-
} else if (payloadSize < 0x100) {
|
67
|
-
outputSize = 3 + payloadSize;
|
68
|
-
} else if (payloadSize < 0x10000) {
|
69
|
-
outputSize = 4 + payloadSize;
|
70
|
-
} else {
|
71
|
-
outputSize = 6 + payloadSize;
|
72
|
-
}
|
73
|
-
byte[] bytes = new byte[outputSize];
|
74
|
-
ByteBuffer buffer = ByteBuffer.wrap(bytes);
|
75
|
-
if (payloadSize == 1) {
|
76
|
-
buffer.put(FIXEXT1);
|
77
|
-
buffer.put((byte) type.getLongValue());
|
78
|
-
buffer.put((byte) payloadBytes.get(0));
|
79
|
-
} else if (payloadSize == 2) {
|
80
|
-
buffer.put(FIXEXT2);
|
81
|
-
buffer.put((byte) type.getLongValue());
|
82
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), 2);
|
83
|
-
} else if (payloadSize == 4) {
|
84
|
-
buffer.put(FIXEXT4);
|
85
|
-
buffer.put((byte) type.getLongValue());
|
86
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), 4);
|
87
|
-
} else if (payloadSize == 8) {
|
88
|
-
buffer.put(FIXEXT8);
|
89
|
-
buffer.put((byte) type.getLongValue());
|
90
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), 8);
|
91
|
-
} else if (payloadSize == 16) {
|
92
|
-
buffer.put(FIXEXT16);
|
93
|
-
buffer.put((byte) type.getLongValue());
|
94
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), 16);
|
95
|
-
} else if (payloadSize < 0x100) {
|
96
|
-
buffer.put(VAREXT8);
|
97
|
-
buffer.put((byte) payloadSize);
|
98
|
-
buffer.put((byte) type.getLongValue());
|
99
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), payloadSize);
|
100
|
-
} else if (payloadSize < 0x10000) {
|
101
|
-
buffer.put(VAREXT16);
|
102
|
-
buffer.putShort((short) payloadSize);
|
103
|
-
buffer.put((byte) type.getLongValue());
|
104
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), payloadSize);
|
105
|
-
} else {
|
106
|
-
buffer.put(VAREXT32);
|
107
|
-
buffer.putInt(payloadSize);
|
108
|
-
buffer.put((byte) type.getLongValue());
|
109
|
-
buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), payloadSize);
|
110
|
-
}
|
111
|
-
return getRuntime().newString(new ByteList(bytes, binaryEncoding, false));
|
112
|
-
}
|
113
|
-
|
114
58
|
@JRubyMethod(name = {"to_s", "inspect"})
|
115
59
|
@Override
|
116
60
|
public IRubyObject to_s() {
|
@@ -121,16 +65,67 @@ public class ExtensionValue extends RubyObject {
|
|
121
65
|
@JRubyMethod(name = "hash")
|
122
66
|
@Override
|
123
67
|
public RubyFixnum hash() {
|
124
|
-
long hash = payload.hashCode()
|
68
|
+
long hash = payload.hashCode() ^ (type.getLongValue() << 56);
|
125
69
|
return RubyFixnum.newFixnum(getRuntime(), hash);
|
126
70
|
}
|
127
71
|
|
128
72
|
@JRubyMethod(name = "eql?")
|
129
73
|
public IRubyObject eql_p(ThreadContext ctx, IRubyObject o) {
|
74
|
+
Ruby runtime = ctx.runtime;
|
75
|
+
if (this == o) {
|
76
|
+
return runtime.getTrue();
|
77
|
+
}
|
130
78
|
if (o instanceof ExtensionValue) {
|
131
79
|
ExtensionValue other = (ExtensionValue) o;
|
132
|
-
|
80
|
+
if (!this.type.eql_p(other.type).isTrue())
|
81
|
+
return runtime.getFalse();
|
82
|
+
if (runtime.is1_8()) {
|
83
|
+
return this.payload.str_eql_p(ctx, other.payload);
|
84
|
+
} else {
|
85
|
+
return this.payload.str_eql_p19(ctx, other.payload);
|
86
|
+
}
|
133
87
|
}
|
134
|
-
return
|
88
|
+
return runtime.getFalse();
|
89
|
+
}
|
90
|
+
|
91
|
+
@JRubyMethod(name = "==")
|
92
|
+
public IRubyObject op_equal(ThreadContext ctx, IRubyObject o) {
|
93
|
+
Ruby runtime = ctx.runtime;
|
94
|
+
if (this == o) {
|
95
|
+
return runtime.getTrue();
|
96
|
+
}
|
97
|
+
if (o instanceof ExtensionValue) {
|
98
|
+
ExtensionValue other = (ExtensionValue) o;
|
99
|
+
if (!this.type.op_equal(ctx, other.type).isTrue())
|
100
|
+
return runtime.getFalse();
|
101
|
+
if (runtime.is1_8()) {
|
102
|
+
return this.payload.op_equal(ctx, other.payload);
|
103
|
+
} else {
|
104
|
+
return this.payload.op_equal19(ctx, other.payload);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
return runtime.getFalse();
|
108
|
+
}
|
109
|
+
|
110
|
+
@JRubyMethod(name = "type")
|
111
|
+
public IRubyObject get_type() {
|
112
|
+
return type;
|
113
|
+
}
|
114
|
+
|
115
|
+
@JRubyMethod
|
116
|
+
public IRubyObject payload() {
|
117
|
+
return payload;
|
118
|
+
}
|
119
|
+
|
120
|
+
@JRubyMethod(name = "type=", required = 1)
|
121
|
+
public IRubyObject set_type(final IRubyObject tpe) {
|
122
|
+
type = (RubyFixnum)tpe;
|
123
|
+
return tpe;
|
124
|
+
}
|
125
|
+
|
126
|
+
@JRubyMethod(name = "payload=", required = 1)
|
127
|
+
public IRubyObject set_payload(final IRubyObject pld) {
|
128
|
+
payload = (RubyString)pld;
|
129
|
+
return pld;
|
135
130
|
}
|
136
|
-
}
|
131
|
+
}
|
@@ -26,6 +26,9 @@ public class MessagePackLibrary implements Library {
|
|
26
26
|
RubyClass standardErrorClass = runtime.getStandardError();
|
27
27
|
RubyClass unpackErrorClass = msgpackModule.defineClassUnder("UnpackError", standardErrorClass, standardErrorClass.getAllocator());
|
28
28
|
RubyClass underflowErrorClass = msgpackModule.defineClassUnder("UnderflowError", unpackErrorClass, unpackErrorClass.getAllocator());
|
29
|
+
RubyModule typeErrorModule = msgpackModule.defineModuleUnder("TypeError");
|
30
|
+
RubyClass unexpectedTypeErrorClass = msgpackModule.defineClassUnder("UnexpetedTypeError", unpackErrorClass, standardErrorClass.getAllocator());
|
31
|
+
unexpectedTypeErrorClass.includeModule(typeErrorModule);
|
29
32
|
RubyClass extensionValueClass = msgpackModule.defineClassUnder("ExtensionValue", runtime.getObject(), new ExtensionValue.ExtensionValueAllocator());
|
30
33
|
extensionValueClass.defineAnnotatedMethods(ExtensionValue.class);
|
31
34
|
RubyClass packerClass = msgpackModule.defineClassUnder("Packer", runtime.getObject(), new Packer.PackerAllocator());
|
@@ -38,6 +41,7 @@ public class MessagePackLibrary implements Library {
|
|
38
41
|
}
|
39
42
|
|
40
43
|
private void installCoreExtensions(Ruby runtime) {
|
44
|
+
RubyClass extensionValueClass = runtime.getModule("MessagePack").getClass("ExtensionValue");
|
41
45
|
installCoreExtensions(
|
42
46
|
runtime,
|
43
47
|
runtime.getNilClass(),
|
@@ -49,7 +53,8 @@ public class MessagePackLibrary implements Library {
|
|
49
53
|
runtime.getString(),
|
50
54
|
runtime.getArray(),
|
51
55
|
runtime.getHash(),
|
52
|
-
runtime.getSymbol()
|
56
|
+
runtime.getSymbol(),
|
57
|
+
extensionValueClass
|
53
58
|
);
|
54
59
|
}
|
55
60
|
|
@@ -63,10 +68,18 @@ public class MessagePackLibrary implements Library {
|
|
63
68
|
return new DynamicMethod(cls, Visibility.PUBLIC, CallConfiguration.FrameNoneScopeNone) {
|
64
69
|
@Override
|
65
70
|
public IRubyObject call(ThreadContext context, IRubyObject recv, RubyModule clazz, String name, IRubyObject[] args, Block block) {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
71
|
+
if (args.length == 0) {
|
72
|
+
IRubyObject[] allArgs = { recv };
|
73
|
+
return MessagePackModule.pack(runtime.getCurrentContext(), null, allArgs);
|
74
|
+
} else if (args.length == 1 && args[0] instanceof Packer) {
|
75
|
+
Packer packer = (Packer)args[0];
|
76
|
+
return packer.write(runtime.getCurrentContext(), recv);
|
77
|
+
} else if (args.length == 1) {
|
78
|
+
IRubyObject[] allArgs = { recv, args[0] };
|
79
|
+
return MessagePackModule.pack(runtime.getCurrentContext(), null, allArgs);
|
80
|
+
} else {
|
81
|
+
throw runtime.newArgumentError(String.format("wrong number of arguments (%d for 0..1)", args.length));
|
82
|
+
}
|
70
83
|
}
|
71
84
|
|
72
85
|
@Override
|
@@ -45,24 +45,28 @@ public class Packer extends RubyObject {
|
|
45
45
|
|
46
46
|
@JRubyMethod(name = "write")
|
47
47
|
public IRubyObject write(ThreadContext ctx, IRubyObject obj) {
|
48
|
-
|
48
|
+
buffer.write(ctx, encoder.encode(obj, this));
|
49
|
+
return this;
|
49
50
|
}
|
50
51
|
|
51
52
|
@JRubyMethod(name = "write_nil")
|
52
53
|
public IRubyObject writeNil(ThreadContext ctx) {
|
53
|
-
|
54
|
+
write(ctx, null);
|
55
|
+
return this;
|
54
56
|
}
|
55
57
|
|
56
58
|
@JRubyMethod(name = "write_array_header")
|
57
59
|
public IRubyObject writeArrayHeader(ThreadContext ctx, IRubyObject size) {
|
58
60
|
int s = (int) size.convertToInteger().getLongValue();
|
59
|
-
|
61
|
+
buffer.write(ctx, encoder.encodeArrayHeader(s));
|
62
|
+
return this;
|
60
63
|
}
|
61
64
|
|
62
65
|
@JRubyMethod(name = "write_map_header")
|
63
66
|
public IRubyObject writeMapHeader(ThreadContext ctx, IRubyObject size) {
|
64
67
|
int s = (int) size.convertToInteger().getLongValue();
|
65
|
-
|
68
|
+
buffer.write(ctx, encoder.encodeMapHeader(s));
|
69
|
+
return this;
|
66
70
|
}
|
67
71
|
|
68
72
|
@JRubyMethod(name = "to_s")
|
@@ -80,4 +84,13 @@ public class Packer extends RubyObject {
|
|
80
84
|
return buffer.flush(ctx);
|
81
85
|
}
|
82
86
|
|
87
|
+
@JRubyMethod(name = "size")
|
88
|
+
public IRubyObject size(ThreadContext ctx) {
|
89
|
+
return buffer.size(ctx);
|
90
|
+
}
|
91
|
+
|
92
|
+
@JRubyMethod(name = "clear")
|
93
|
+
public IRubyObject clear(ThreadContext ctx) {
|
94
|
+
return buffer.clear(ctx);
|
95
|
+
}
|
83
96
|
}
|
@@ -27,6 +27,7 @@ public class Unpacker extends RubyObject {
|
|
27
27
|
private IRubyObject data;
|
28
28
|
private Decoder decoder;
|
29
29
|
private final RubyClass underflowErrorClass;
|
30
|
+
private boolean symbolizeKeys;
|
30
31
|
|
31
32
|
public Unpacker(Ruby runtime, RubyClass type) {
|
32
33
|
super(runtime, type);
|
@@ -41,9 +42,14 @@ public class Unpacker extends RubyObject {
|
|
41
42
|
|
42
43
|
@JRubyMethod(name = "initialize", optional = 1, visibility = PRIVATE)
|
43
44
|
public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
|
45
|
+
symbolizeKeys = false;
|
44
46
|
if (args.length > 0) {
|
45
47
|
if (args[args.length - 1] instanceof RubyHash) {
|
46
|
-
|
48
|
+
RubyHash options = (RubyHash) args[args.length - 1];
|
49
|
+
IRubyObject sk = options.fastARef(ctx.getRuntime().newSymbol("symbolize_keys"));
|
50
|
+
if (sk != null) {
|
51
|
+
symbolizeKeys = sk.isTrue();
|
52
|
+
}
|
47
53
|
} else if (!(args[0] instanceof RubyHash)) {
|
48
54
|
setStream(ctx, args[0]);
|
49
55
|
}
|
@@ -66,6 +72,7 @@ public class Unpacker extends RubyObject {
|
|
66
72
|
limit = byteList.length() - offset;
|
67
73
|
}
|
68
74
|
Decoder decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin() + offset, limit);
|
75
|
+
decoder.symbolizeKeys(symbolizeKeys);
|
69
76
|
try {
|
70
77
|
this.data = null;
|
71
78
|
this.data = decoder.next();
|
@@ -96,10 +103,11 @@ public class Unpacker extends RubyObject {
|
|
96
103
|
ByteList byteList = data.asString().getByteList();
|
97
104
|
if (decoder == null) {
|
98
105
|
decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin(), byteList.length());
|
106
|
+
decoder.symbolizeKeys(symbolizeKeys);
|
99
107
|
} else {
|
100
108
|
decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length());
|
101
109
|
}
|
102
|
-
return
|
110
|
+
return this;
|
103
111
|
}
|
104
112
|
|
105
113
|
@JRubyMethod(name = "feed_each", required = 1)
|
@@ -142,6 +150,54 @@ public class Unpacker extends RubyObject {
|
|
142
150
|
return ctx.getRuntime().getNil();
|
143
151
|
}
|
144
152
|
|
153
|
+
@JRubyMethod
|
154
|
+
public IRubyObject read(ThreadContext ctx) {
|
155
|
+
if (decoder != null) {
|
156
|
+
try {
|
157
|
+
return decoder.next();
|
158
|
+
} catch (RaiseException re) {
|
159
|
+
if (re.getException().getType() != underflowErrorClass) {
|
160
|
+
throw re;
|
161
|
+
} else {
|
162
|
+
throw ctx.getRuntime().newEOFError();
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
return ctx.getRuntime().getNil();
|
167
|
+
}
|
168
|
+
|
169
|
+
@JRubyMethod
|
170
|
+
public IRubyObject read_array_header(ThreadContext ctx) {
|
171
|
+
if (decoder != null) {
|
172
|
+
try {
|
173
|
+
return decoder.read_array_header();
|
174
|
+
} catch (RaiseException re) {
|
175
|
+
if (re.getException().getType() != underflowErrorClass) {
|
176
|
+
throw re;
|
177
|
+
} else {
|
178
|
+
throw ctx.getRuntime().newEOFError();
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
return ctx.getRuntime().getNil();
|
183
|
+
}
|
184
|
+
|
185
|
+
@JRubyMethod
|
186
|
+
public IRubyObject read_map_header(ThreadContext ctx) {
|
187
|
+
if (decoder != null) {
|
188
|
+
try {
|
189
|
+
return decoder.read_map_header();
|
190
|
+
} catch (RaiseException re) {
|
191
|
+
if (re.getException().getType() != underflowErrorClass) {
|
192
|
+
throw re;
|
193
|
+
} else {
|
194
|
+
throw ctx.getRuntime().newEOFError();
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
return ctx.getRuntime().getNil();
|
199
|
+
}
|
200
|
+
|
145
201
|
@JRubyMethod(name = "stream")
|
146
202
|
public IRubyObject getStream(ThreadContext ctx) {
|
147
203
|
if (stream == null) {
|
@@ -165,6 +221,7 @@ public class Unpacker extends RubyObject {
|
|
165
221
|
this.stream = stream;
|
166
222
|
this.decoder = null;
|
167
223
|
this.decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin(), byteList.length());
|
224
|
+
decoder.symbolizeKeys(symbolizeKeys);
|
168
225
|
return getStream(ctx);
|
169
226
|
}
|
170
227
|
}
|
data/ext/msgpack/buffer_class.c
CHANGED
@@ -82,7 +82,7 @@ static ID get_write_all_method(VALUE io)
|
|
82
82
|
}
|
83
83
|
}
|
84
84
|
|
85
|
-
void
|
85
|
+
void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options)
|
86
86
|
{
|
87
87
|
b->io = io;
|
88
88
|
b->io_partial_read_method = get_partial_read_method(io);
|
@@ -143,7 +143,7 @@ static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
|
|
143
143
|
|
144
144
|
BUFFER(self, b);
|
145
145
|
|
146
|
-
|
146
|
+
MessagePack_Buffer_set_options(b, io, options);
|
147
147
|
|
148
148
|
return self;
|
149
149
|
}
|
data/ext/msgpack/buffer_class.h
CHANGED
@@ -26,7 +26,7 @@ void MessagePack_Buffer_module_init(VALUE mMessagePack);
|
|
26
26
|
|
27
27
|
VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner);
|
28
28
|
|
29
|
-
void
|
29
|
+
void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options);
|
30
30
|
|
31
31
|
#endif
|
32
32
|
|
data/ext/msgpack/compat.h
CHANGED
@@ -110,5 +110,17 @@
|
|
110
110
|
#endif
|
111
111
|
|
112
112
|
|
113
|
+
/*
|
114
|
+
* RSTRUCT_GET
|
115
|
+
*/
|
116
|
+
#ifndef RSTRUCT_GET
|
117
|
+
# ifdef RSTRUCT_PTR /* MRI <= 2.0.0 */
|
118
|
+
# define RSTRUCT_GET(st, idx) (RSTRUCT_PTR(st)[idx])
|
119
|
+
# else /* Rubinius */
|
120
|
+
# define RSTRUCT_GET(st, idx) (rb_struct_aref(st, INT2FIX(idx)))
|
121
|
+
# endif
|
122
|
+
#endif
|
123
|
+
|
124
|
+
|
113
125
|
#endif
|
114
126
|
|
data/ext/msgpack/core_ext.c
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
#include "core_ext.h"
|
20
20
|
#include "packer.h"
|
21
21
|
#include "packer_class.h"
|
22
|
+
#include "extension_value_class.h"
|
22
23
|
|
23
24
|
static inline VALUE delegete_to_pack(int argc, VALUE* argv, VALUE self)
|
24
25
|
{
|
@@ -113,6 +114,19 @@ static VALUE Symbol_to_msgpack(int argc, VALUE* argv, VALUE self)
|
|
113
114
|
return packer;
|
114
115
|
}
|
115
116
|
|
117
|
+
static VALUE ExtensionValue_to_msgpack(int argc, VALUE* argv, VALUE self)
|
118
|
+
{
|
119
|
+
ENSURE_PACKER(argc, argv, packer, pk);
|
120
|
+
int ext_type = FIX2INT(RSTRUCT_GET(self, 0));
|
121
|
+
if(ext_type < -128 || ext_type > 127) {
|
122
|
+
rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type);
|
123
|
+
}
|
124
|
+
VALUE payload = RSTRUCT_GET(self, 1);
|
125
|
+
StringValue(payload);
|
126
|
+
msgpack_packer_write_ext(pk, ext_type, payload);
|
127
|
+
return packer;
|
128
|
+
}
|
129
|
+
|
116
130
|
void MessagePack_core_ext_module_init()
|
117
131
|
{
|
118
132
|
rb_define_method(rb_cNilClass, "to_msgpack", NilClass_to_msgpack, -1);
|
@@ -125,5 +139,6 @@ void MessagePack_core_ext_module_init()
|
|
125
139
|
rb_define_method(rb_cArray, "to_msgpack", Array_to_msgpack, -1);
|
126
140
|
rb_define_method(rb_cHash, "to_msgpack", Hash_to_msgpack, -1);
|
127
141
|
rb_define_method(rb_cSymbol, "to_msgpack", Symbol_to_msgpack, -1);
|
142
|
+
rb_define_method(cMessagePack_ExtensionValue, "to_msgpack", ExtensionValue_to_msgpack, -1);
|
128
143
|
}
|
129
144
|
|
data/ext/msgpack/extconf.rb
CHANGED
@@ -6,9 +6,12 @@ have_func("rb_str_replace", ["ruby.h"])
|
|
6
6
|
have_func("rb_intern_str", ["ruby.h"])
|
7
7
|
have_func("rb_sym2str", ["ruby.h"])
|
8
8
|
have_func("rb_str_intern", ["ruby.h"])
|
9
|
+
have_func("rb_block_lambda", ["ruby.h"])
|
10
|
+
have_func("rb_hash_dup", ["ruby.h"])
|
11
|
+
have_func("rb_hash_clear", ["ruby.h"])
|
9
12
|
|
10
13
|
unless RUBY_PLATFORM.include? 'mswin'
|
11
|
-
$CFLAGS << %[ -I.. -Wall -O3 -g -std=
|
14
|
+
$CFLAGS << %[ -I.. -Wall -O3 -g -std=gnu99]
|
12
15
|
end
|
13
16
|
#$CFLAGS << %[ -DDISABLE_RMEM]
|
14
17
|
#$CFLAGS << %[ -DDISABLE_RMEM_REUSE_INTERNAL_FRAGMENT]
|
@@ -0,0 +1,34 @@
|
|
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 "factory_class.h"
|
20
|
+
|
21
|
+
VALUE cMessagePack_ExtensionValue;
|
22
|
+
|
23
|
+
VALUE MessagePack_ExtensionValue_new(int ext_type, VALUE payload)
|
24
|
+
{
|
25
|
+
return rb_struct_new(cMessagePack_ExtensionValue, INT2FIX(ext_type), payload);
|
26
|
+
}
|
27
|
+
|
28
|
+
void MessagePack_ExtensionValue_module_init(VALUE mMessagePack)
|
29
|
+
{
|
30
|
+
/* rb_struct_define_under is not available ruby < 2.1 */
|
31
|
+
//cMessagePack_ExtensionValue = rb_struct_define_under(mMessagePack, "ExtensionValue", "type", "payload", NULL);
|
32
|
+
cMessagePack_ExtensionValue = rb_struct_define(NULL, "type", "payload", NULL);
|
33
|
+
rb_define_const(mMessagePack, "ExtensionValue", cMessagePack_ExtensionValue);
|
34
|
+
}
|