msgpack 0.6.0pre1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +26 -0
  4. data/ChangeLog +117 -0
  5. data/Dockerfile +30 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +177 -0
  8. data/README.rdoc +129 -0
  9. data/Rakefile +114 -0
  10. data/bench/pack.rb +23 -0
  11. data/bench/pack_log.rb +33 -0
  12. data/bench/pack_log_long.rb +65 -0
  13. data/bench/run.sh +14 -0
  14. data/bench/run_long.sh +35 -0
  15. data/bench/unpack.rb +21 -0
  16. data/bench/unpack_log.rb +34 -0
  17. data/bench/unpack_log_long.rb +67 -0
  18. data/cross-build.sh +9 -0
  19. data/doclib/msgpack/buffer.rb +193 -0
  20. data/doclib/msgpack/core_ext.rb +101 -0
  21. data/doclib/msgpack/error.rb +14 -0
  22. data/doclib/msgpack/packer.rb +134 -0
  23. data/doclib/msgpack/unpacker.rb +146 -0
  24. data/doclib/msgpack.rb +77 -0
  25. data/ext/java/org/msgpack/jruby/Buffer.java +221 -0
  26. data/ext/java/org/msgpack/jruby/Decoder.java +201 -0
  27. data/ext/java/org/msgpack/jruby/Encoder.java +308 -0
  28. data/ext/java/org/msgpack/jruby/ExtensionValue.java +136 -0
  29. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +107 -0
  30. data/ext/java/org/msgpack/jruby/Packer.java +78 -0
  31. data/ext/java/org/msgpack/jruby/Types.java +37 -0
  32. data/ext/java/org/msgpack/jruby/Unpacker.java +170 -0
  33. data/ext/msgpack/buffer.c +695 -0
  34. data/ext/msgpack/buffer.h +447 -0
  35. data/ext/msgpack/buffer_class.c +507 -0
  36. data/ext/msgpack/buffer_class.h +32 -0
  37. data/ext/msgpack/compat.h +113 -0
  38. data/ext/msgpack/core_ext.c +129 -0
  39. data/ext/msgpack/core_ext.h +26 -0
  40. data/ext/msgpack/extconf.rb +28 -0
  41. data/ext/msgpack/packer.c +168 -0
  42. data/ext/msgpack/packer.h +441 -0
  43. data/ext/msgpack/packer_class.c +302 -0
  44. data/ext/msgpack/packer_class.h +30 -0
  45. data/ext/msgpack/rbinit.c +33 -0
  46. data/ext/msgpack/rmem.c +94 -0
  47. data/ext/msgpack/rmem.h +109 -0
  48. data/ext/msgpack/sysdep.h +115 -0
  49. data/ext/msgpack/sysdep_endian.h +50 -0
  50. data/ext/msgpack/sysdep_types.h +46 -0
  51. data/ext/msgpack/unpacker.c +771 -0
  52. data/ext/msgpack/unpacker.h +122 -0
  53. data/ext/msgpack/unpacker_class.c +405 -0
  54. data/ext/msgpack/unpacker_class.h +32 -0
  55. data/lib/msgpack/msgpack.so +0 -0
  56. data/lib/msgpack/version.rb +3 -0
  57. data/lib/msgpack.rb +13 -0
  58. data/msgpack.gemspec +31 -0
  59. data/msgpack.org.md +46 -0
  60. data/spec/cases.json +1 -0
  61. data/spec/cases.msg +0 -0
  62. data/spec/cases_compact.msg +0 -0
  63. data/spec/cases_spec.rb +39 -0
  64. data/spec/cruby/buffer_io_spec.rb +256 -0
  65. data/spec/cruby/buffer_packer.rb +29 -0
  66. data/spec/cruby/buffer_spec.rb +572 -0
  67. data/spec/cruby/buffer_unpacker.rb +19 -0
  68. data/spec/cruby/packer_spec.rb +120 -0
  69. data/spec/cruby/unpacker_spec.rb +305 -0
  70. data/spec/format_spec.rb +282 -0
  71. data/spec/jruby/benchmarks/shootout_bm.rb +73 -0
  72. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +25 -0
  73. data/spec/jruby/msgpack/unpacker_spec.rb +290 -0
  74. data/spec/jruby/msgpack_spec.rb +142 -0
  75. data/spec/pack_spec.rb +67 -0
  76. data/spec/random_compat.rb +24 -0
  77. data/spec/spec_helper.rb +27 -0
  78. data/spec/unpack_spec.rb +60 -0
  79. metadata +209 -0
@@ -0,0 +1,170 @@
1
+ package org.msgpack.jruby;
2
+
3
+
4
+ import org.jruby.Ruby;
5
+ import org.jruby.RubyClass;
6
+ import org.jruby.RubyString;
7
+ import org.jruby.RubyObject;
8
+ import org.jruby.RubyHash;
9
+ import org.jruby.RubyNumeric;
10
+ import org.jruby.RubyIO;
11
+ import org.jruby.exceptions.RaiseException;
12
+ import org.jruby.runtime.builtin.IRubyObject;
13
+ import org.jruby.runtime.Block;
14
+ import org.jruby.runtime.ObjectAllocator;
15
+ import org.jruby.runtime.ThreadContext;
16
+ import org.jruby.anno.JRubyClass;
17
+ import org.jruby.anno.JRubyMethod;
18
+ import org.jruby.util.ByteList;
19
+ import org.jruby.ext.stringio.StringIO;
20
+
21
+ import static org.jruby.runtime.Visibility.PRIVATE;
22
+
23
+
24
+ @JRubyClass(name="MessagePack::Unpacker")
25
+ public class Unpacker extends RubyObject {
26
+ private IRubyObject stream;
27
+ private IRubyObject data;
28
+ private Decoder decoder;
29
+ private final RubyClass underflowErrorClass;
30
+
31
+ public Unpacker(Ruby runtime, RubyClass type) {
32
+ super(runtime, type);
33
+ this.underflowErrorClass = runtime.getModule("MessagePack").getClass("UnderflowError");
34
+ }
35
+
36
+ static class UnpackerAllocator implements ObjectAllocator {
37
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
38
+ return new Unpacker(runtime, klass);
39
+ }
40
+ }
41
+
42
+ @JRubyMethod(name = "initialize", optional = 1, visibility = PRIVATE)
43
+ public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
44
+ if (args.length > 0) {
45
+ if (args[args.length - 1] instanceof RubyHash) {
46
+ //TODO: symbolize_keys
47
+ } else if (!(args[0] instanceof RubyHash)) {
48
+ setStream(ctx, args[0]);
49
+ }
50
+ }
51
+ return this;
52
+ }
53
+
54
+ @JRubyMethod(required = 2)
55
+ public IRubyObject execute(ThreadContext ctx, IRubyObject data, IRubyObject offset) {
56
+ return executeLimit(ctx, data, offset, null);
57
+ }
58
+
59
+ @JRubyMethod(name = "execute_limit", required = 3)
60
+ public IRubyObject executeLimit(ThreadContext ctx, IRubyObject str, IRubyObject off, IRubyObject lim) {
61
+ RubyString input = str.asString();
62
+ int offset = RubyNumeric.fix2int(off);
63
+ int limit = lim == null || lim.isNil() ? -1 : RubyNumeric.fix2int(lim);
64
+ ByteList byteList = input.getByteList();
65
+ if (limit == -1) {
66
+ limit = byteList.length() - offset;
67
+ }
68
+ Decoder decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin() + offset, limit);
69
+ try {
70
+ this.data = null;
71
+ this.data = decoder.next();
72
+ } catch (RaiseException re) {
73
+ if (re.getException().getType() != underflowErrorClass) {
74
+ throw re;
75
+ }
76
+ }
77
+ return ctx.getRuntime().newFixnum(decoder.offset());
78
+ }
79
+
80
+ @JRubyMethod(name = "data")
81
+ public IRubyObject getData(ThreadContext ctx) {
82
+ if (data == null) {
83
+ return ctx.getRuntime().getNil();
84
+ } else {
85
+ return data;
86
+ }
87
+ }
88
+
89
+ @JRubyMethod(name = "finished?")
90
+ public IRubyObject finished_p(ThreadContext ctx) {
91
+ return data == null ? ctx.getRuntime().getFalse() : ctx.getRuntime().getTrue();
92
+ }
93
+
94
+ @JRubyMethod(required = 1)
95
+ public IRubyObject feed(ThreadContext ctx, IRubyObject data) {
96
+ ByteList byteList = data.asString().getByteList();
97
+ if (decoder == null) {
98
+ decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin(), byteList.length());
99
+ } else {
100
+ decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length());
101
+ }
102
+ return ctx.getRuntime().getNil();
103
+ }
104
+
105
+ @JRubyMethod(name = "feed_each", required = 1)
106
+ public IRubyObject feedEach(ThreadContext ctx, IRubyObject data, Block block) {
107
+ feed(ctx, data);
108
+ each(ctx, block);
109
+ return ctx.getRuntime().getNil();
110
+ }
111
+
112
+ @JRubyMethod
113
+ public IRubyObject each(ThreadContext ctx, Block block) {
114
+ if (block.isGiven()) {
115
+ if (decoder != null) {
116
+ try {
117
+ while (decoder.hasNext()) {
118
+ block.yield(ctx, decoder.next());
119
+ }
120
+ } catch (RaiseException re) {
121
+ if (re.getException().getType() != underflowErrorClass) {
122
+ throw re;
123
+ }
124
+ }
125
+ }
126
+ return this;
127
+ } else {
128
+ return callMethod(ctx, "to_enum");
129
+ }
130
+ }
131
+
132
+ @JRubyMethod
133
+ public IRubyObject fill(ThreadContext ctx) {
134
+ return ctx.getRuntime().getNil();
135
+ }
136
+
137
+ @JRubyMethod
138
+ public IRubyObject reset(ThreadContext ctx) {
139
+ if (decoder != null) {
140
+ decoder.reset();
141
+ }
142
+ return ctx.getRuntime().getNil();
143
+ }
144
+
145
+ @JRubyMethod(name = "stream")
146
+ public IRubyObject getStream(ThreadContext ctx) {
147
+ if (stream == null) {
148
+ return ctx.getRuntime().getNil();
149
+ } else {
150
+ return stream;
151
+ }
152
+ }
153
+
154
+ @JRubyMethod(name = "stream=", required = 1)
155
+ public IRubyObject setStream(ThreadContext ctx, IRubyObject stream) {
156
+ RubyString str;
157
+ if (stream instanceof StringIO) {
158
+ str = stream.callMethod(ctx, "string").asString();
159
+ } else if (stream instanceof RubyIO) {
160
+ str = stream.callMethod(ctx, "read").asString();
161
+ } else {
162
+ throw ctx.getRuntime().newTypeError(stream, "IO");
163
+ }
164
+ ByteList byteList = str.getByteList();
165
+ this.stream = stream;
166
+ this.decoder = null;
167
+ this.decoder = new Decoder(ctx.getRuntime(), byteList.unsafeBytes(), byteList.begin(), byteList.length());
168
+ return getStream(ctx);
169
+ }
170
+ }