msgpack 1.2.6-x86-mingw32 → 1.2.7-x86-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
  SHA256:
3
- metadata.gz: aece45801a94bf03064178daeb75b87f3eba6dd6caf3bb6a6202be793e09e5ec
4
- data.tar.gz: 91a4084fb36e07bae10561c6bf007ce75b98b4997837cb16f3f9127710b1259e
3
+ metadata.gz: 9980ace5d9a150b3aad2a7254cce1999f34035e232038536b7b63914b85c7196
4
+ data.tar.gz: 1ec41edb87d3c0352b020789094c78b9d6e4cb6fc6384076d755f99c9a60ca23
5
5
  SHA512:
6
- metadata.gz: 357ff615fe4ad59fc515666981a81a5e692671863b4178911ff7e6fd9e2089de113680b8b02d76b2f559abeb30ad90e7ded56d559f40b77fafcf7bd638b00fa1
7
- data.tar.gz: b5b907954f0a56825dbfe6f8e93df7d39d0b4ab3552d19b242774b6642433ebbdf58f8e6e8de348f1d931a06c28264c7087ee74861d97c79733c0c7a5060cbf1
6
+ metadata.gz: 2b577e1208d3799414c1a87c9f338bc8900eb153e122d9b744ff0670a03d4e753a5287d034c3eb6514047aabcacca0e3038e975ec1a9e59cbc839ee7b0f563bf
7
+ data.tar.gz: cc246d549e90f46c85dd7a39a6ed7128dab059fd019cc219638f53db1c3e4ce4037f732d5deda3419d86d0172da8b144812b4adbbc0aee89c2d5d7cfad74fde5
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 2019-03-01 version 1.2.7:
2
+
3
+ * Add Packer#write_bin and Packer#write_bin_header methods
4
+
1
5
  2019-01-08 verison 1.2.6:
2
6
 
3
7
  * Update Ruby version 2.6 dependency (especially for Windows environment)
@@ -91,6 +91,12 @@ module MessagePack
91
91
  def write_nil
92
92
  end
93
93
 
94
+ #
95
+ # Serializes a string object as binary data. Same as write("string".encode(Encoding::BINARY)).
96
+ #
97
+ def write_bin(obj)
98
+ end
99
+
94
100
  #
95
101
  # Write a header of an array whose size is _n_.
96
102
  # For example, write_array_header(1).write(true) is same as write([ true ]).
@@ -109,6 +115,20 @@ module MessagePack
109
115
  def write_map_header(n)
110
116
  end
111
117
 
118
+ #
119
+ # Write a header of a binary string whose size is _n_. Useful if you want to append large binary data without loading it into memory at once.
120
+ # For example,
121
+ # MessagePack::Packer.new(io).write_bin_header(12).flush
122
+ # io.write('chunk1')
123
+ # io.write('chunk2')
124
+ # is the same as
125
+ # write('chunk1chunk2'.encode(Encoding::BINARY)).
126
+ #
127
+ # @return [Packer] self
128
+ #
129
+ def write_bin_header(n)
130
+ end
131
+
112
132
  #
113
133
  # Serializes _value_ as 32-bit single precision float into internal buffer.
114
134
  # _value_ will be approximated with the nearest possible single precision float, thus
@@ -91,6 +91,11 @@ public class Encoder {
91
91
  return readRubyString();
92
92
  }
93
93
 
94
+ public IRubyObject encodeBinHeader(int size) {
95
+ appendStringHeader(size, true);
96
+ return readRubyString();
97
+ }
98
+
94
99
  public IRubyObject encodeFloat32(RubyNumeric numeric) {
95
100
  appendFloat32(numeric);
96
101
  return readRubyString();
@@ -221,14 +226,7 @@ public class Encoder {
221
226
  buffer.putFloat(value);
222
227
  }
223
228
 
224
- private void appendString(RubyString object) {
225
- Encoding encoding = object.getEncoding();
226
- boolean binary = !compatibilityMode && encoding == binaryEncoding;
227
- if (encoding != utf8Encoding && encoding != binaryEncoding) {
228
- object = (RubyString) ((RubyString) object).encode(runtime.getCurrentContext(), runtime.getEncodingService().getEncoding(utf8Encoding));
229
- }
230
- ByteList bytes = object.getByteList();
231
- int length = bytes.length();
229
+ private void appendStringHeader(int length, boolean binary) {
232
230
  if (length < 32 && !binary) {
233
231
  ensureRemainingCapacity(1 + length);
234
232
  buffer.put((byte) (length | FIXSTR));
@@ -245,6 +243,17 @@ public class Encoder {
245
243
  buffer.put(binary ? BIN32 : STR32);
246
244
  buffer.putInt((int) length);
247
245
  }
246
+ }
247
+
248
+ private void appendString(RubyString object) {
249
+ Encoding encoding = object.getEncoding();
250
+ boolean binary = !compatibilityMode && encoding == binaryEncoding;
251
+ if (encoding != utf8Encoding && encoding != binaryEncoding) {
252
+ object = (RubyString) ((RubyString) object).encode(runtime.getCurrentContext(), runtime.getEncodingService().getEncoding(utf8Encoding));
253
+ }
254
+ ByteList bytes = object.getByteList();
255
+ int length = bytes.length();
256
+ appendStringHeader(length, binary);
248
257
  buffer.put(bytes.unsafeBytes(), bytes.begin(), length);
249
258
  }
250
259
 
@@ -21,6 +21,8 @@ import org.jruby.util.ByteList;
21
21
  import org.jruby.util.TypeConverter;
22
22
  import org.msgpack.jruby.ExtensionValue;
23
23
 
24
+ import org.jcodings.Encoding;
25
+
24
26
  import static org.jruby.runtime.Visibility.PRIVATE;
25
27
 
26
28
  @JRubyClass(name="MessagePack::Packer")
@@ -29,6 +31,7 @@ public class Packer extends RubyObject {
29
31
  private Buffer buffer;
30
32
  private Encoder encoder;
31
33
  private boolean hasSymbolExtType;
34
+ private Encoding binaryEncoding;
32
35
 
33
36
  public Packer(Ruby runtime, RubyClass type, ExtensionRegistry registry, boolean hasSymbolExtType) {
34
37
  super(runtime, type);
@@ -58,6 +61,7 @@ public class Packer extends RubyObject {
58
61
  this.encoder = new Encoder(ctx.getRuntime(), compatibilityMode, registry, hasSymbolExtType);
59
62
  this.buffer = new Buffer(ctx.getRuntime(), ctx.getRuntime().getModule("MessagePack").getClass("Buffer"));
60
63
  this.buffer.initialize(ctx, args);
64
+ this.binaryEncoding = ctx.getRuntime().getEncodingService().getAscii8bitEncoding();
61
65
  return this;
62
66
  }
63
67
 
@@ -141,6 +145,13 @@ public class Packer extends RubyObject {
141
145
  return write(ctx, obj);
142
146
  }
143
147
 
148
+ @JRubyMethod(name = "write_bin")
149
+ public IRubyObject writeBin(ThreadContext ctx, IRubyObject obj) {
150
+ checkType(ctx, obj, org.jruby.RubyString.class);
151
+ obj = ((org.jruby.RubyString) obj).encode(ctx, ctx.runtime.getEncodingService().getEncoding(binaryEncoding));
152
+ return write(ctx, obj);
153
+ }
154
+
144
155
  @JRubyMethod(name = "write_hash")
145
156
  public IRubyObject writeHash(ThreadContext ctx, IRubyObject obj) {
146
157
  checkType(ctx, obj, org.jruby.RubyHash.class);
@@ -209,6 +220,13 @@ public class Packer extends RubyObject {
209
220
  return this;
210
221
  }
211
222
 
223
+ @JRubyMethod(name = "write_bin_header")
224
+ public IRubyObject writeBinHeader(ThreadContext ctx, IRubyObject size) {
225
+ int s = (int) size.convertToInteger().getLongValue();
226
+ buffer.write(ctx, encoder.encodeBinHeader(s));
227
+ return this;
228
+ }
229
+
212
230
  @JRubyMethod(name = "full_pack")
213
231
  public IRubyObject fullPack(ThreadContext ctx) {
214
232
  return toS(ctx);
@@ -165,6 +165,18 @@ static VALUE Packer_write_string(VALUE self, VALUE obj)
165
165
  return self;
166
166
  }
167
167
 
168
+ static VALUE Packer_write_bin(VALUE self, VALUE obj)
169
+ {
170
+ PACKER(self, pk);
171
+ Check_Type(obj, T_STRING);
172
+
173
+ VALUE enc = rb_enc_from_encoding(rb_ascii8bit_encoding());
174
+ obj = rb_str_encode(obj, enc, 0, Qnil);
175
+
176
+ msgpack_packer_write_string_value(pk, obj);
177
+ return self;
178
+ }
179
+
168
180
  static VALUE Packer_write_array(VALUE self, VALUE obj)
169
181
  {
170
182
  PACKER(self, pk);
@@ -232,6 +244,13 @@ static VALUE Packer_write_map_header(VALUE self, VALUE n)
232
244
  return self;
233
245
  }
234
246
 
247
+ static VALUE Packer_write_bin_header(VALUE self, VALUE n)
248
+ {
249
+ PACKER(self, pk);
250
+ msgpack_packer_write_bin_header(pk, NUM2UINT(n));
251
+ return self;
252
+ }
253
+
235
254
  static VALUE Packer_write_float32(VALUE self, VALUE numeric)
236
255
  {
237
256
  if(!rb_obj_is_kind_of(numeric, rb_cNumeric)) {
@@ -416,6 +435,7 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
416
435
  rb_define_method(cMessagePack_Packer, "write_false", Packer_write_false, 0);
417
436
  rb_define_method(cMessagePack_Packer, "write_float", Packer_write_float, 1);
418
437
  rb_define_method(cMessagePack_Packer, "write_string", Packer_write_string, 1);
438
+ rb_define_method(cMessagePack_Packer, "write_bin", Packer_write_bin, 1);
419
439
  rb_define_method(cMessagePack_Packer, "write_array", Packer_write_array, 1);
420
440
  rb_define_method(cMessagePack_Packer, "write_hash", Packer_write_hash, 1);
421
441
  rb_define_method(cMessagePack_Packer, "write_symbol", Packer_write_symbol, 1);
@@ -423,6 +443,7 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
423
443
  rb_define_method(cMessagePack_Packer, "write_extension", Packer_write_extension, 1);
424
444
  rb_define_method(cMessagePack_Packer, "write_array_header", Packer_write_array_header, 1);
425
445
  rb_define_method(cMessagePack_Packer, "write_map_header", Packer_write_map_header, 1);
446
+ rb_define_method(cMessagePack_Packer, "write_bin_header", Packer_write_bin_header, 1);
426
447
  rb_define_method(cMessagePack_Packer, "write_ext", Packer_write_ext, 2);
427
448
  rb_define_method(cMessagePack_Packer, "write_float32", Packer_write_float32, 1);
428
449
  rb_define_method(cMessagePack_Packer, "flush", Packer_flush, 0);
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.7"
3
3
 
4
4
  # NOTE for msgpack-ruby maintainer:
5
5
  # Check these things to release new binaryes for new Ruby versions (especially for Windows):
@@ -1,6 +1,11 @@
1
1
  require 'spec_helper'
2
2
  require 'random_compat'
3
3
 
4
+ require 'stringio'
5
+ if defined?(Encoding)
6
+ Encoding.default_external = 'ASCII-8BIT'
7
+ end
8
+
4
9
  describe Buffer do
5
10
  STATIC_EXAMPLES = {}
6
11
  STATIC_EXAMPLES[:empty01] = ''
@@ -45,7 +50,7 @@ describe Buffer do
45
50
  b.read(n)
46
51
  s.slice!(0, n)
47
52
  end
48
- key = :"random#{"%02d"%i}"
53
+ key = :"random#{"%02d" % i}"
49
54
  cases[key] = b
50
55
  examples[key] = s
51
56
  end
data/spec/packer_spec.rb CHANGED
@@ -134,6 +134,41 @@ describe MessagePack::Packer do
134
134
  packer.to_s.should == "\x81"
135
135
  end
136
136
 
137
+ it 'write_bin_header 0' do
138
+ packer.write_bin_header(0)
139
+ packer.to_s.should == "\xC4\x00"
140
+ end
141
+
142
+ it 'write_bin_header 255' do
143
+ packer.write_bin_header(255)
144
+ packer.to_s.should == "\xC4\xFF"
145
+ end
146
+
147
+ it 'write_bin_header 256' do
148
+ packer.write_bin_header(256)
149
+ packer.to_s.should == "\xC5\x01\x00"
150
+ end
151
+
152
+ it 'write_bin_header 65535' do
153
+ packer.write_bin_header(65535)
154
+ packer.to_s.should == "\xC5\xFF\xFF"
155
+ end
156
+
157
+ it 'write_bin_header 65536' do
158
+ packer.write_bin_header(65536)
159
+ packer.to_s.should == "\xC6\x00\x01\x00\x00"
160
+ end
161
+
162
+ it 'write_bin_header 999999' do
163
+ packer.write_bin_header(999999)
164
+ packer.to_s.should == "\xC6\x00\x0F\x42\x3F"
165
+ end
166
+
167
+ it 'write_bin' do
168
+ packer.write_bin("hello")
169
+ packer.to_s.should == "\xC4\x05hello"
170
+ end
171
+
137
172
  describe '#write_float32' do
138
173
  tests = [
139
174
  ['small floats', 3.14, "\xCA\x40\x48\xF5\xC3"],
@@ -193,6 +228,7 @@ describe MessagePack::Packer do
193
228
  packer = MessagePack::Packer.new
194
229
  expect { packer.write_float "hello" }.to raise_error(TypeError)
195
230
  expect { packer.write_string 1 }.to raise_error(TypeError)
231
+ expect { packer.write_bin 1 }.to raise_error(TypeError)
196
232
  expect { packer.write_array "hello" }.to raise_error(TypeError)
197
233
  expect { packer.write_hash "hello" }.to raise_error(TypeError)
198
234
  expect { packer.write_symbol "hello" }.to raise_error(TypeError)
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.2.6
4
+ version: 1.2.7
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: 2019-01-08 00:00:00.000000000 Z
13
+ date: 2019-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler