msgpack 0.6.0-x64-mingw32 → 0.6.1-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65d6f0eb6ecb8c8036e9f6edc12c9e17feab5fef
4
- data.tar.gz: 84bedb5b93fc1c4827c5d08d50ac6f50659983ca
3
+ metadata.gz: 061bf4e223be0ec5cd073d7e40ffbfff30c42de8
4
+ data.tar.gz: c01cf237f4702dfb85951b138f64fbefaaa28381
5
5
  SHA512:
6
- metadata.gz: f9f3a7422baf56d2a17f4e9e61eae02f07b3f9e4e5caa33073ca394aa38fd3e5cdff9ddf5c8d1b92f7d4f3830c7dded14498dd786df2a1e15664aad795fa7583
7
- data.tar.gz: cbee6499c6d55796dda08dd8e072e22998ae3dc6d9c30bee68222613eca785b55c44f6a483ea9389ae7e8f9db856c94d0110f1ca4016bb71d568e820cf48293d
6
+ metadata.gz: c18c958023c23e0563d09a8c12e0c30c06dbedef61070c6d7802ba4d905dc3472cfb51a35b89ea9a2b1944bd8c0fc53a5d0b088b06c565b894a0952a5ed85dc6
7
+ data.tar.gz: 030f5ff78911c2397f7c65b54c515403c4d88e5f869c9e6bd08a6d8d978655c9c394f3c7452d140499bb9a80b4f7d666c8fa5554dd66307784478d323bb70fbc
data/Dockerfile CHANGED
@@ -59,4 +59,4 @@ ENV BUILD_BRANCH master
59
59
  ENV BUILD_POSITION HEAD
60
60
 
61
61
  ### docker run -v `pwd`/pkg:/home/ubuntu/msgpack-ruby/pkg IMAGENAME
62
- CMD ["bash", "-c", "git remote add dockerbuild $MSGPACK_REPO && git fetch dockerbuild && git checkout $BUILD_BRANCH && git reset --hard $BUILD_POSITION && bundle && rake cross native gem"]
62
+ CMD ["bash", "-c", "git remote add dockerbuild $MSGPACK_REPO && git fetch dockerbuild && git checkout $BUILD_BRANCH && git pull dockerbuild $BUILD_BRANCH && git reset --hard $BUILD_POSITION && bundle && rake clean && rake cross native gem"]
@@ -17,7 +17,11 @@ module MessagePack
17
17
  # This packer writes serialzied objects into the IO when the internal buffer is filled.
18
18
  # _io_ must respond to write(string) or append(string) method.
19
19
  #
20
- # See also Buffer#initialize for options.
20
+ # Supported options:
21
+ #
22
+ # * *:compatibility_mode* serialize in older versions way, without str8 and bin types
23
+ #
24
+ # See also Buffer#initialize for other options.
21
25
  #
22
26
  def initialize(*args)
23
27
  end
@@ -21,7 +21,6 @@ import org.jcodings.Encoding;
21
21
 
22
22
  @JRubyClass(name="MessagePack::Buffer")
23
23
  public class Buffer extends RubyObject {
24
- private RubyHash options;
25
24
  private IRubyObject io;
26
25
  private ByteBuffer buffer;
27
26
  private boolean writeMode;
@@ -46,9 +45,6 @@ public class Buffer extends RubyObject {
46
45
  if (args[0].respondsTo("read") && args[0].respondsTo("write")) {
47
46
  this.io = args[0];
48
47
  }
49
- if (args[args.length - 1] instanceof RubyHash) {
50
- this.options = (RubyHash) args[args.length - 1];
51
- }
52
48
  }
53
49
  this.buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE);
54
50
  this.writeMode = true;
@@ -34,14 +34,16 @@ public class Encoder {
34
34
  private final Ruby runtime;
35
35
  private final Encoding binaryEncoding;
36
36
  private final Encoding utf8Encoding;
37
+ private final boolean compatibilityMode;
37
38
 
38
39
  private ByteBuffer buffer;
39
40
 
40
- public Encoder(Ruby runtime) {
41
+ public Encoder(Ruby runtime, boolean compatibilityMode) {
41
42
  this.runtime = runtime;
42
43
  this.buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE);
43
44
  this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding();
44
45
  this.utf8Encoding = UTF8Encoding.INSTANCE;
46
+ this.compatibilityMode = compatibilityMode;
45
47
  }
46
48
 
47
49
  private void ensureRemainingCapacity(int c) {
@@ -190,7 +192,7 @@ public class Encoder {
190
192
 
191
193
  private void appendString(RubyString object) {
192
194
  Encoding encoding = object.getEncoding();
193
- boolean binary = encoding == binaryEncoding;
195
+ boolean binary = !compatibilityMode && encoding == binaryEncoding;
194
196
  if (encoding != utf8Encoding && encoding != binaryEncoding) {
195
197
  object = (RubyString) ((RubyString) object).encode(runtime.getCurrentContext(), runtime.getEncodingService().getEncoding(utf8Encoding));
196
198
  }
@@ -199,7 +201,7 @@ public class Encoder {
199
201
  if (length < 32 && !binary) {
200
202
  ensureRemainingCapacity(1 + length);
201
203
  buffer.put((byte) (length | FIXSTR));
202
- } else if (length <= 0xff) {
204
+ } else if (length <= 0xff && !compatibilityMode) {
203
205
  ensureRemainingCapacity(2 + length);
204
206
  buffer.put(binary ? BIN8 : STR8);
205
207
  buffer.put((byte) length);
@@ -32,7 +32,12 @@ public class Packer extends RubyObject {
32
32
 
33
33
  @JRubyMethod(name = "initialize", optional = 2)
34
34
  public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) {
35
- this.encoder = new Encoder(ctx.getRuntime());
35
+ boolean compatibilityMode = false;
36
+ if (args.length > 0 && args[args.length - 1] instanceof RubyHash) {
37
+ RubyHash options = (RubyHash) args[args.length - 1];
38
+ compatibilityMode = options.fastARef(ctx.getRuntime().newSymbol("compatibility_mode")).isTrue();
39
+ }
40
+ this.encoder = new Encoder(ctx.getRuntime(), compatibilityMode);
36
41
  this.buffer = new Buffer(ctx.getRuntime(), ctx.getRuntime().getModule("MessagePack").getClass("Buffer"));
37
42
  this.buffer.initialize(ctx, args);
38
43
  return this;
@@ -32,11 +32,15 @@ struct msgpack_packer_t {
32
32
 
33
33
  VALUE io;
34
34
  ID io_write_all_method;
35
+ bool compatibility_mode;
35
36
 
36
37
  ID to_msgpack_method;
37
38
  VALUE to_msgpack_arg;
38
39
 
39
40
  VALUE buffer_ref;
41
+
42
+ /* options */
43
+ bool comaptibility_mode;
40
44
  };
41
45
 
42
46
  #define PACKER_BUFFER_(pk) (&(pk)->buffer)
@@ -66,6 +70,11 @@ static inline void msgpack_packer_set_io(msgpack_packer_t* pk, VALUE io, ID io_w
66
70
 
67
71
  void msgpack_packer_reset(msgpack_packer_t* pk);
68
72
 
73
+ static inline void msgpack_packer_set_compat(msgpack_packer_t* pk, bool enable)
74
+ {
75
+ pk->compatibility_mode = enable;
76
+ }
77
+
69
78
  static inline void msgpack_packer_write_nil(msgpack_packer_t* pk)
70
79
  {
71
80
  msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
@@ -270,7 +279,7 @@ static inline void msgpack_packer_write_raw_header(msgpack_packer_t* pk, unsigne
270
279
  msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
271
280
  unsigned char h = 0xa0 | (uint8_t) n;
272
281
  msgpack_buffer_write_1(PACKER_BUFFER_(pk), h);
273
- } else if(n < 256) {
282
+ } else if(n < 256 && !pk->compatibility_mode) {
274
283
  msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2);
275
284
  unsigned char be = (uint8_t) n;
276
285
  msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd9, (const void*)&be, 1);
@@ -358,7 +367,6 @@ static inline bool msgpack_packer_is_utf8_compat_string(VALUE v, int encindex)
358
367
 
359
368
  static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE v)
360
369
  {
361
- /* TODO encoding conversion? */
362
370
  /* actual return type of RSTRING_LEN is long */
363
371
  unsigned long len = RSTRING_LEN(v);
364
372
  if(len > 0xffffffffUL) {
@@ -368,13 +376,14 @@ static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE
368
376
 
369
377
  #ifdef COMPAT_HAVE_ENCODING
370
378
  int encindex = ENCODING_GET(v);
371
- if(msgpack_packer_is_binary(v, encindex)) {
379
+ if(msgpack_packer_is_binary(v, encindex) && !pk->compatibility_mode) {
372
380
  /* write ASCII-8BIT string using Binary type */
373
381
  msgpack_packer_write_bin_header(pk, (unsigned int)len);
374
382
  msgpack_buffer_append_string(PACKER_BUFFER_(pk), v);
375
383
  } else {
376
384
  /* write UTF-8, US-ASCII, or 7bit-safe ascii-compatible string using String type directly */
377
- if(!msgpack_packer_is_utf8_compat_string(v, encindex)) {
385
+ /* in compatibility mode, packer packs String values as is */
386
+ if(!pk->compatibility_mode && !msgpack_packer_is_utf8_compat_string(v, encindex)) {
378
387
  /* transcode other strings to UTF-8 and write using String type */
379
388
  VALUE enc = rb_enc_from_encoding(rb_utf8_encoding()); /* rb_enc_from_encoding_index is not extern */
380
389
  v = rb_str_encode(v, enc, 0, Qnil);
@@ -87,13 +87,24 @@ static VALUE Packer_initialize(int argc, VALUE* argv, VALUE self)
87
87
  }
88
88
 
89
89
  PACKER(self, pk);
90
- MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
91
90
 
92
- // TODO MessagePack_Unpacker_initialize and options
91
+ MessagePack_Packer_initialize(pk, io, options);
93
92
 
94
93
  return self;
95
94
  }
96
95
 
96
+ void MessagePack_Packer_initialize(msgpack_packer_t* pk, VALUE io, VALUE options)
97
+ {
98
+ MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
99
+
100
+ if(options != Qnil) {
101
+ VALUE v;
102
+
103
+ v = rb_hash_aref(options, ID2SYM(rb_intern("compatibility_mode")));
104
+ msgpack_packer_set_compat(pk, RTEST(v));
105
+ }
106
+ }
107
+
97
108
  static VALUE Packer_buffer(VALUE self)
98
109
  {
99
110
  PACKER(self, pk);
@@ -221,11 +232,15 @@ VALUE MessagePack_pack(int argc, VALUE* argv)
221
232
 
222
233
  VALUE self = Packer_alloc(cMessagePack_Packer);
223
234
  PACKER(self, pk);
235
+
236
+ if (options != Qnil) {
237
+ pk->compatibility_mode = RTEST(rb_hash_aref(options, ID2SYM(rb_intern("compatibility_mode"))));
238
+ }
239
+
224
240
  //msgpack_packer_reset(s_packer);
225
241
  //msgpack_buffer_reset_io(PACKER_BUFFER_(s_packer));
226
242
 
227
- MessagePack_Buffer_initialize(PACKER_BUFFER_(pk), io, options);
228
- // TODO MessagePack_Unpacker_initialize and options
243
+ MessagePack_Packer_initialize(pk, io, options);
229
244
 
230
245
  msgpack_packer_write_value(pk, v);
231
246
 
@@ -26,5 +26,7 @@ void MessagePack_Packer_module_init(VALUE mMessagePack);
26
26
 
27
27
  VALUE MessagePack_pack(int argc, VALUE* argv);
28
28
 
29
+ void MessagePack_Packer_initialize(msgpack_packer_t* pk, VALUE io, VALUE options);
30
+
29
31
  #endif
30
32
 
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -116,5 +116,23 @@ describe Packer do
116
116
  CustomPack02.new.to_msgpack(s04)
117
117
  s04.string.should == [1,2].to_msgpack
118
118
  end
119
+
120
+ context 'in compatibility mode' do
121
+ it 'does not use the bin types' do
122
+ packed = MessagePack.pack('hello'.force_encoding(Encoding::BINARY), compatibility_mode: true)
123
+ packed.should eq("\xA5hello")
124
+ packed = MessagePack.pack(('hello' * 100).force_encoding(Encoding::BINARY), compatibility_mode: true)
125
+ packed.should start_with("\xDA\x01\xF4")
126
+
127
+ packer = MessagePack::Packer.new(compatibility_mode: 1)
128
+ packed = packer.pack(('hello' * 100).force_encoding(Encoding::BINARY))
129
+ packed.to_str.should start_with("\xDA\x01\xF4")
130
+ end
131
+
132
+ it 'does not use the str8 type' do
133
+ packed = MessagePack.pack('x' * 32, compatibility_mode: true)
134
+ packed.should start_with("\xDA\x00\x20")
135
+ end
136
+ end
119
137
  end
120
138
 
@@ -36,9 +36,15 @@ describe MessagePack do
36
36
  ['negative floats', -2.1, "\xCB\xC0\x00\xCC\xCC\xCC\xCC\xCC\xCD"]
37
37
  ],
38
38
  'strings' => [
39
- ['strings', utf8enc('hello world'), "\xABhello world"],
39
+ ['tiny strings', utf8enc('hello world'), "\xABhello world"],
40
+ ['short strings', utf8enc('hello' * 5), "\xB9hellohellohellohellohello"],
40
41
  ['empty strings', utf8enc(''), "\xA0"]
41
42
  ],
43
+ 'binary strings' => [
44
+ ['tiny strings', asciienc('hello world'), "\xC4\vhello world"],
45
+ ['short strings', asciienc('hello' * 5), "\xC4\x19hellohellohellohellohello"],
46
+ ['empty strings', asciienc(''), "\xC4\x00"]
47
+ ],
42
48
  'arrays' => [
43
49
  ['empty arrays', [], "\x90"],
44
50
  ['arrays with strings', [utf8enc("hello"), utf8enc("world")], "\x92\xA5hello\xA5world"],
@@ -139,4 +145,18 @@ describe MessagePack do
139
145
  packed.index("w\xC3\xA5rld").should_not be_nil
140
146
  end
141
147
  end
148
+
149
+ context 'in compatibility mode' do
150
+ it 'does not use the bin types' do
151
+ packed = MessagePack.pack('hello'.force_encoding(Encoding::BINARY), compatibility_mode: true)
152
+ packed.should eq("\xA5hello")
153
+ packed = MessagePack.pack(('hello' * 100).force_encoding(Encoding::BINARY), compatibility_mode: true)
154
+ packed.should start_with("\xDA\x01\xF4")
155
+ end
156
+
157
+ it 'does not use the str8 type' do
158
+ packed = MessagePack.pack('x' * 32, compatibility_mode: true)
159
+ packed.should start_with("\xDA\x00\x20")
160
+ end
161
+ end
142
162
  end
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: 0.6.0
4
+ version: 0.6.1
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-26 00:00:00.000000000 Z
12
+ date: 2015-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler