msgpack 1.2.6-x64-mingw32 → 1.2.7-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
  SHA256:
3
- metadata.gz: 90f3c4f7391be1e25551add382226a9ad77fee68899a2f84fb8859fa2024b9e3
4
- data.tar.gz: b5075d74616b3f3e304149f4378e8084530481e83ac1a4a86616d79392d250c9
3
+ metadata.gz: 6c6d806ca2c5dc1b5e50ad4d88dfb222c3f44b219dfa0c234f3edad76ed01ce4
4
+ data.tar.gz: e89e09879e75f38d70ff87952e46a7ff094f269bd537ebce412bdf66ae3cfc3f
5
5
  SHA512:
6
- metadata.gz: f8010356459e39eee7f947ed34ea67add237aa3a115f812578f6e7b48936653d76383cfb8b9380d9a0558189ed2bdc9c6fff41829b37f01962eeb12c9d8a9818
7
- data.tar.gz: 3385681456a4b5636ee43d623b47db029806517da712fdc8f75cb5ea96b70b7c718c9141bf624380cc621bcffd6202a090866712802fe3bf6f656dcb7c4564a5
6
+ metadata.gz: 5ec99006c7def54b671548593cac1883b60f0adf5da4fdb78f1e228abfb1a9221f1eee22d247abc0248323647fafff9a42f1b142d84b87c3b35d478efc8af2aa
7
+ data.tar.gz: 82fa4e5be6d820097a1ef79d734e4365a69ec530d4afdd55246b4d237307a330e955d67e836ac53ff865d962f242fa2d866df801158e9b4b978cf61f605c04a2
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
@@ -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: x64-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